比如,在Goods類中有一個goodsList存放了當前的所有商品,頁面的代碼為:
js 代碼
復制代碼 代碼如下:
<f:view>
<h:form>
...
<h:dataTablevalue="#{Goods.goodsList}"var="goods">
<h:column>
<f:facetname="header">
<h:outputTextvalue="Name"/>
<h:commandLintaction="#{Goods.select}"immediate="true">
<h:outputTextvalue="#{goods.name}"/>
</h:commandLink>
</h:column>
...
</h:form>
</f:view>
Goods類如下:
java 代碼
復制代碼 代碼如下:
publicclassGoods{
....
privateDateModelgoodsList;
...
publicDataModelgetGoodsList(){
if(goodsList==null){
goodsList=newDataModel();
}
goodsList.setWrappedData(getRealGoodsList());//這裡通過Service層或者Dao層訪問到數據庫
retrungoodsList;
}
publicStringselect(){
GoodsselectedGoods=(Goods)goodsList.getRowData();
setSelectedGoods(selectedGoods);
return"success";
}