Search code examples
jsfrichfacesseam

selectOneMenu sets field to null after being changed


I try to do something that is very similar to this richfaces example. I have a form that describes custom ID validation in case that you have not selected one of the predefined ones, else the form will be disabled. So disabled expression for the form members would go to the next method:

public boolean isPredefinedValidator() {
    return !currentProjectRegField.getIdValidation().getIdType().equals(IdValidatorType.NONE);
}

that is invoked like this:

disabled="#{accountHome.isPredefinedValidator()}"

and here is the selector for the predefined validator:

<h:selectOneMenu value="#{accountHome.currentProjectRegField.idValidation.idType}"
    rendered="#{!(empty accountHome.currentProjectRegField or empty accountHome.currentProjectRegField.idValidation)}">
    <a4j:support event="onchange" reRender="customIdValidator"/>
        <s:convertEnum />
            <s:enumItem enumValue="NONE" label="#{messages['IdValidatorType_enum.NONE']}"/>
            <s:enumItem enumValue="USA_ID" label="#{messages['IdValidatorType_enum.USA_ID']}"/>
            <s:enumItem enumValue="MEXICO_ID" label="#{messages['IdValidatorType_enum.MEXICO_ID']}"/>
</h:selectOneMenu>

The issue is, when the method isPredefinedValidator() is invoked on a4j rerender (on disabled EL), I receive NPE.

Caused by: java.lang.NullPointerException
at com.whatever.something.action.AccountHome.isPredefinedValidator(AccountHome.java)

And when I try to debug - turns out that the value that has been set from the selectOneMenu is null.

Does it mean that reRender and setting value to the variable happens async, and there is a race condition? And what is the correct solution for this case?


Solution

  • Some black-magic configuration in the rich:modalPanel that contains the h:selectOneMenu resolved this issue. It goes like this <rich:modalPanel ... domElementAttachment="form">