Hello dear,
I think you can do that by using a Map. e.g
Map<Object[], Boolean> selections = new HashMap<Object[], Boolean>();
public String deleteSelection(){
try{
for (Object[] item: List) {
Boolean selected = selections.get(item);
if (selected!=null && selected) {
selections.put(item, false);
System.out.println("The deleted is: "+ item[0].toString());
// u can call any method u want
}
}
}catch(Exception e){
e.printStackTrace();
}
and on the JSF side use:
<h:dataTable id="list" value="#{userList}" var="User" >
<h:column>
<f:facet name="header">
<h:outputText value="Select" />
</f:facet>
<h:selectBooleanCheckbox value="#{selections[User]}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{User.name}" />
</h:column>
</h:dataTable>
<h:commandButton ction="#{Action.deleteSelection}" value="Delete />
I hope it will do the trick;">
Implement valuechangelisteners.
public void listen(ValueChangeEvent event) {
if (!event.getOldValue().equals(event.getNewValue()) {
// the attached field has changed
}
}
I thought of implementing the valueChangeListener but that results in two problems
Firstly, the valueChagneListener is invoked before the update model phase, hence I don't have the datamodel(h:dataTable) at that stage.
Secondly, even if I get the dataModel somehow, how do I know the row that resulted in the valueChangeListener event being fired.
> Firstly, the valueChagneListener is invoked before
> the update model phase, hence I don't have the
> datamodel(h:dataTable) at that stage.
Reload the data and/or, preferably, put the data in session.
> Secondly, even if I get the dataModel somehow, how do
> I know the row that resulted in the
> valueChangeListener event being fired.
HtmlDataTable.getRowData() tells you.