ADFfaces Ignores Immediate if the required input has partialTrigger the submiting component

Cosmin Cosmin picture Cosmin Cosmin · Jun 17, 2011 · Viewed 7.2k times · Source

I have a selectOneChoice with autoSubmit=true and immediate=true to skip validation, if the selectOneChoice is set to some value I want to remove the required attribute from an inputText, so the inputText will have partialTrigger the id of the selectOneChoice, but when I change the value from the selectOneChoice (and the change is submitted) the required validation is still triggered just for the component which needs to be updated (because of the presence of the partialTriggers) the other required components doesn't trigger its validation.
Any workarounds ?

Answer

Billy Bob Bain picture Billy Bob Bain · Aug 26, 2011

You need to change the required indicator in a valueChangeListener. This will happen before the model is updated.

For example, given this JSF fragment.

<af:panelFormLayout id="pfl1">
  <af:inputText label="Label 1" id="it1" value="#{pageFlowScope.RemoveRequiredBean.myValue}" required="true" partialTriggers="soc1"/>
  <af:selectOneChoice label="Selection" value="#{pageFlowScope.RemoveRequiredBean.selection}" id="soc1" autoSubmit="true" immediate="true"
                      valueChangeListener="#{pageFlowScope.RemoveRequiredBean.selectionChange}">
    <af:selectItem label="one" value="one" id="si3"/>
    <af:selectItem label="two" value="two" id="si1"/>
    <af:selectItem label="three" value="three" id="si2"/>
  </af:selectOneChoice>
  <af:commandButton text="commandButton 1" id="cb1"/>
  <f:facet name="footer"/>
</af:panelFormLayout>

And this listener, you get the behavior you describe.

public void selectionChange(ValueChangeEvent valueChangeEvent) {
    String newValue = valueChangeEvent.getNewValue().toString();
    RichInputText it = (RichInputText)valueChangeEvent.getComponent().findComponent("it1");
    it.setRequired(!"two".equals(newValue));
}