Search code examples
jsfrichfacesajax4jsf

h:selectOneListbox + a4j:ajax not calling setter


I'm facing a strange issue, I have a form with a h:selectOneListbox :

<h:selectOneListbox value="#{webHostingServicesActions.customPackage.storage}" size="1">
    <f:selectItem itemLabel="None" itemValue="#{null}" />
    <f:selectItems value="#{webHostingServicesActions.storagesChoices}" var="item" itemLabel="#{item.name}" />
    <f:converter converterId="productConverter" />
    <a4j:ajax event="valueChange" render="lblTotal" />
</h:selectOneListbox>

When I select one item from f:selectItems, the setter webHostingServicesActions.customPackage.storage is not called. But when I select the item from f:selectItem, the setter is called properly.

Of course I'm using a custom converter, but it was tested and respond correctly.

Every other ajax actions in the form seems blocked when an item from f:selectItems is selected. There is no error on server side, also no error when using a4j:log in debug.

EDIT 1 : When I'm selecting an item from f:selectItems, the server-side code to apply request values is executed, but it blocks somewhere before the setter. I wasn't able to trace far enough to see what is happening.

EDIT 2 : I've added the BalusC LifeCycleListener...

When I select the item from f:selectItem

START PHASE RESTORE_VIEW 1
END PHASE RESTORE_VIEW 1
START PHASE APPLY_REQUEST_VALUES 2
END PHASE APPLY_REQUEST_VALUES 2
START PHASE PROCESS_VALIDATIONS 3
END PHASE PROCESS_VALIDATIONS 3
START PHASE UPDATE_MODEL_VALUES 4
END PHASE UPDATE_MODEL_VALUES 4
START PHASE INVOKE_APPLICATION 5
END PHASE INVOKE_APPLICATION 5
START PHASE RENDER_RESPONSE 6
END PHASE RENDER_RESPONSE 6

When I select an item from the f:selectItems

START PHASE RESTORE_VIEW 1
END PHASE RESTORE_VIEW 1
START PHASE APPLY_REQUEST_VALUES 2
END PHASE APPLY_REQUEST_VALUES 2
START PHASE PROCESS_VALIDATIONS 3
END PHASE PROCESS_VALIDATIONS 3
START PHASE RENDER_RESPONSE 6
END PHASE RENDER_RESPONSE 6

I've also tested the change instead of valueChange and nothing was different.

Any help appreciated thank you!

Alexandre.


Solution

  • Now I found the solution, I had a misconception about using converter with h:selectOneListbox. I was thinking that the converter could be used to convert the Object from the f:selectItems and vice-versa.

    I've changed back my code a bit :

    <h:selectOneListbox value="#{webHostingServicesActions.selectedStorage}" size="1">
        <f:selectItem itemLabel="Aucun" itemValue="#{null}" />
        <f:selectItems value="#{webHostingServicesActions.storagesChoices}" var="item" itemLabel="#{item.name}" itemValue="#{item.keyProduct}" />
        <f:converter converterId="integerConverter" />
        <a4j:ajax event="valueChange" render="lblTotal" />
    </h:selectOneListbox>
    

    Now the setter selectedStorage will receive an Integer instead of an object Product. Everything works as espected.

    Thanks to kolossus putting me on the right way and this post : Object as itemValue in <f:selectItems>