I'm trying to use selectable datatable of primefaces 4.0, but the selected object is always null.
I have tired add rowKey
like here and here said, but still get null...
here's my page:
<p:dataTable id="appDetailTable" var="appDetail" value="#{newAppraiseBean.appDetailDataModel}"
paginator="true" rows="5" paginatorPosition="bottom" selection="#{newAppraiseBean.selectedAppDetail}"
rowKey="#{appDetail.appraiseDetailID}" selectionMode="single">
<p:ajax event="rowSelect" listener="#{newAppraiseBean.modifyAppDetail()}" oncomplete="newAppDlg.show();" update=":newAppraiseForm:newAppDetail"/>
</p:dataTable>
In my backing bean:
newAppraiseBean.modifyAppDetail(): (Just print the selected item)
public void modifyAppDetail(){
System.out.println("modify, selectedAppDetail:"+selectedAppDetail);
}
DataModel:
private class AppraiseDetailDataModel extends ListDataModel<Appraisedetail> implements SelectableDataModel<Appraisedetail> {
public AppraiseDetailDataModel(List<Appraisedetail> list) {
super(list);
}
@Override
public Object getRowKey(Appraisedetail t) {
return t.getAppraiseDetailID();
}
@Override
public Appraisedetail getRowData(String string) {
List<Appraisedetail> appList=(List<Appraisedetail>) getWrappedData();
for(Appraisedetail app:appList){
System.out.println(app.getAppraiseDetailID());
if(app.getAppraiseDetailID()==Integer.parseInt(string)){
return app;
}
}
return null;
}
}
It always print null and I don't know what am I missing.
Update
I have simplified my code and put it on google drive.
This is an zipped file of netbean project, you may open it directly with netbean after unzip it.
And of course the problem remains after I simplify my code.