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 ?

有帮助吗?

解决方案

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));
}

其他提示

Can you post the EL expression for the required attribute of your inputText?

<af:inputText label="ResId" id="it1" required="#{someValueExpression}"
                    partialTriggers="soc1">            
      </af:inputText>
      <af:selectOneChoice label="Label 1" id="soc1" autoSubmit="true">
        <af:selectItem label="test" value="test" id="si1"/>
        <af:selectItem label="test2" value="test2" id="si12"/>
      </af:selectOneChoice>

If you want to skip the validation then make the Skip Validation to True on pagedef.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top