比如,在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";
}