how to settle JSF combobox with values depending on another combobox if both are set to required
- by mykola
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'?