how to settle JSF combobox with values depending on another combobox if both are set to required

Posted by mykola on Stack Overflow See other posts from Stack Overflow or by mykola
Published on 2010-06-03T15:14:43Z Indexed on 2010/06/03 15:24 UTC
Read the original article Hit count: 352

Filed under:
|
|
|

Hi, everybody! Can anyone tell me how to automatically set <h:selectOneMenu> (or any other component) with values depending on another <h:selectOneMenu> if there empty elements with 'required' set to 'true' on the form? If to set <a4j:support event="onchange" reRender="anotherElement" immediate="true"/> then nothing is changed because changed value isn't set. But without immediate i always have message that this or that element cannot be empty. Here's code example that doesn't work :)

        <h:outputLabel value="* #{msg.someField}: "/>
        <h:panelGrid cellpadding="0" cellspacing="0">
            <h:selectOneMenu id="someSelect"
                    value="#{MyBean.someObj.someId}"
                    required="true" label="#{msg.someField}"
                    >
                <a4j:support event="onchange" reRender="anotherSelect" limitToList="true" immediate="true"/>
                <f:selectItem itemValue=""/>
                <f:selectItems value="#{MyBean.someList}"/>
            </h:selectOneMenu>
            <rich:message for="someSelect" styleClass="redOne"/>
        </h:panelGrid>

        <h:outputLabel value="* #{msg.anotherField}: "/>
        <h:panelGrid cellpadding="0" cellspacing="0">
            <h:selectOneMenu id="anotherSelect"
                    value="#{MyBean.someObj.anotherId}"
                    required="true" label="#{msg.anotherField}"
                    >
                <f:selectItem itemValue=""/>
                <f:selectItems value="#{MyBean.anotherList}"/>
            </h:selectOneMenu>
            <rich:message for="anotherSelect" styleClass="redOne"/>
        </h:panelGrid>

        <h:outputLabel value="* #{msg.name}: "/>
        <h:panelGrid cellpadding="0" cellspacing="0">
            <h:inputText id="myName" value="#{MyBean.someObj.myName}" 
                    required="true" label="#{msg.name}"/>
            <rich:message for="myName" styleClass="redOne"/>
        </h:panelGrid>

So, here (i repeat), if i try to change 'someSelect' then 'anotherSelect' should update its values but it doesn't because either when it tries to get value of 'someSelect' it gets null (if immediate set to 'true') or form validation fails on empty elements. How can i skip validation but get this changed value from 'someSelect'?

© Stack Overflow or respective owner

Related posts about java

Related posts about jsf