<ice:dataTable value="#{myView.serviceList}"
var="service"
id="ServicesTable"
rows="5">
<ice:column id="column1">
<f:facet name="header">
<ice:outputText value="#{msg.name}"></ice:outputText>
</f:facet>
<ice:outputText effect="#{service.effect}" value="#{service.name}" />
</ice:column>
<ice:column id="c_selector">
<f:facet name="header">
<ice:outputText value="#{msg.selected}"/>
</f:facet>
<ice:selectBooleanCheckbox partialSubmit="true" valueChangeListener="#{myView.changeListener}" />
</ice:column>
</ice:dataTable>
In the valueChangeListener you can consult the source, which is the UIComponent that triggered it - but in such a loop the UIComponent is always the same for every iteration.
This means that you can't even make a different binding for each element in the loop - something like:
<ice:selectBooleanCheckbox binding="#{service.checkboxBinding}" partialSubmit="true" valueChangeListener="#{myView.changeListener}" />
... because there's only one component and faces won't let you do a binding to a changing element.
But there is one option to retrieve the current value of your iterator variable from the listener, through the ExternalContext's requestMap:
public class MyView{
public String changeListener(ValueChangeEvent event){
//event.getSource(); will always be the same UIComponent
FacesContext ctx = FacesContext.getCurrentInstance();
//"service" is the name of the "var" attribute of the datatable
ServiceViewObject service=(ServiceViewObject) ctx.getExternalContext().getRequestMap().get("service");
System.out.prinln("You changed the value for: "+service);
return null;
}
}
The only drawback of this is that you have to have to force the name of the variable in your loop in the JSP file to the name defined in the valueChangeListener.
No comments:
Post a Comment