문제

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