How to send the currently iterated item to h:selectBooleanCheckbox with f:ajax event=change

余生颓废 提交于 2019-12-02 04:43:22
BalusC

First of all, the valueChangeListener is the wrong tool for the job. Use <f:ajax listener>. Second, event="change" is the wrong choice in case of checkboxes/radiobuttons because their physical value actually never changes. You should use event="click", but this is the default already, so you can just omit it.

All in all, the proper initial code should look like this:

<h:selectBooleanCheckbox value="#{item.enabled}">
    <f:ajax listener="#{bean.onchangeEnabled}" />
</h:selectBooleanCheckbox>

with

public void onchangeEnabled(AjaxBehaviorEvent event) { // Note: event argument is optional.
    // ...
}

Once fixed it like that, then you can easily make use of EL 2.2 capability to pass method arguments:

<h:selectBooleanCheckbox value="#{item.enabled}">
    <f:ajax listener="#{bean.onchangeEnabled(item)}" />
</h:selectBooleanCheckbox>

with

public void onchangeEnabled(Item item) {
    // ...
}

See also:

For selectBooleanCheckbox it only reacts on the event click and the form should be posted.

so add this to the checkbox

valueChangeListener="#{mybean.myfunction}" onchange="submit();"

it should get fired !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!