jsf 2 - jsf datatable row selection problem -
i have problem selecting rows in primefaces datatable. use dynamic columns, standard row selection mechanism not usable here, implement checkbox selection myself.
to help, here's s simplified version of have in xhtml:
<h:form> <p:datatable id="table" var="result" value="#{tablebean.results}"> <p:columns value="#{tablebean.columnnames}" var="column" columnindexvar="colindex"> <f:facet name="header"> #{column} </f:facet> <h:panelgroup rendered="#{colindex==0}"> <h:outputlabel>#{rowindex}</h:outputlabel> <h:selectbooleancheckbox value="#{tablebean.selectedrows[result[0]]}"/> </h:panelgroup> </p:columns> </p:datatable> <h:commandbutton value="submit"></h:commandbutton> </h:form>
and here's have in managed bean select checkboxes:
package testpackage; import java.util.*; import javax.faces.bean.*; @managedbean @sessionscoped public class tablebean { private map<string, boolean> selectedrows = new hashmap<string, boolean>(); list<list<string>> results = new linkedlist<list<string>>(); public tablebean() { list<string> row1 = new linkedlist<string>(); list<string> row2 = new linkedlist<string>(); row1.add("row1.ref"); row1.add("row1.id"); row1.add("row1.status"); row2.add("row2.ref"); row2.add("row2.id"); row2.add("row2.status"); results.add(row1); results.add(row2); //selectedrows.put("row2.ref", true); } public map<string, boolean> getselectedrows() { return selectedrows; } public string submit() { list<list<string>> selectedresults = new arraylist<list<string>>(); (list<string> result : results) { if (selectedrows.get(result.get(0)) != null) { selectedresults.add(result); selectedrows.remove(result.get(0)); } } return null; } public list<list<string>> getresults() { return results; } public list<string> getcolumnnames() { list<string> columnnames = new linkedlist<string>(); columnnames.add(""); columnnames.add("ref"); columnnames.add("id"); columnnames.add("status"); return columnnames; } }
the getselectedrows method works great, problem setselectedrows method never called, don't know checkboxes user has selected. maybe overlook trivial, cannot find solution.
any ideas on this? glad if helped, or give other row selection solution dynamic columns.
thx in advance, levi
to me looks rendering wrong field in selectbooleancheckbox
.
should using variable or field result
variable.
my solution:
in situation rendering object list form of table row if want make changes , retrieve status of row should using variable object only.
i understand submitting whole form , want pickup updated rows, in case have loop through whole list , find rows have been updated checking status in request handler(action) bean.
hope helps.
Comments
Post a Comment