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

前端 未结 2 1434
一生所求
一生所求 2021-01-24 09:19

I\'ve the below form:


    
        
            

        
相关标签:
2条回答
  • 2021-01-24 09:43

    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 !

    0 讨论(0)
  • 2021-01-24 10:06

    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:

    • When to use valueChangeListener or f:ajax listener?
    • What values can I pass to the event attribute of the f:ajax tag?
    • How can I pass selected row to commandLink inside dataTable?
    • Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
    0 讨论(0)
提交回复
热议问题