Reputation: 73
Event listener for SelectManyCheckbox is not invoked when a checkbox is clicked.
My SelectManyCheckbox code:
SelectManyCheckbox smcb = new SelectManyCheckbox();
UISelectItem item = new UISelectItem();
item.setItemValue("ItemValue");
item.setItemLabel("ItemLabel");
smcb.getChildren().add(item);
I have tried AjaxBehavior:
AjaxBehavior ajaxBeh = (AjaxBehavior) fc.getApplication().createBehavior(AjaxBehavior.BEHAVIOR_ID);
ajaxBeh.setRender(Collections.singletonList("@this"));
ajaxBeh.setExecute(Collections.singletonList("@this"));
ajaxBeh.setImmediate(true);
ajaxBeh.setTransient(true);
ajaxBeh.addAjaxBehaviorListener(new AjaxBehaviorListener() {
@Override
public void processAjaxBehavior(AjaxBehaviorEvent e)
throws AbortProcessingException {
System.out.println("Event Triggered");
}
});
smcb.addClientBehavior("change",ajaxBeh);
and also ValueChangeListener:
public class CustomValueChangeListener implements ValueChangeListener {
@Override
public void processValueChange(ValueChangeEvent arg0)
throws AbortProcessingException {
System.out.println("processValueChange");
}
}
smcb.addValueChangeListener(new CustomValueChangeListener ());
Both of the above methods do not work.
How can I setup an event listener so that it gets called when a checkbox is selected or unselected?
Upvotes: 0
Views: 1364
Reputation: 76
I think you could very well try to run an ajax event from the jsf code by calling a valueChangeListener and work on your selection at the Bean end.
JSF Code:
<p:selectManyCheckbox id="custom" columns="1" layout="pageDirection" value="#{dapBean.selection}" disabled="#{!dapBean.status}"
valueChangeListener="#{dapBean.checkListener}">
<f:selectItems value="#{dapBean.toolOptions}" var="tool" itemLabel="#{tool.toolLabel}" itemValue="#{tool.toolLabel}" />
<f:ajax event="valueChange" update = "@form"></f:ajax>
</p:selectManyCheckbox>
This can be backed up with a valueChangeListener at the back end.
Java Code:
public void checkListener(ValueChangeEvent e) {
System.out.println(e.getNewValue().toString());
System.out.println(e.getOldValue().toString());
}
Everytime you check or uncheck a checkBox you can get your selected as well as unchecked entries.
Hope it helps!!
Upvotes: 1