Primefaces dependent selectOneMenu and required=“true”

后端 未结 1 1684
后悔当初
后悔当初 2021-01-02 16:14

In my application I have three dropdown menu (p:selectOneMenu), say A, B, C. Among them two are dependent, say B and C. By changing the value of B I am dynamica

相关标签:
1条回答
  • 2021-01-02 16:30

    You can use EL in the required attribute. You can let the desired expression evaluate true only when a particular submit button is pressed, or when a particular component value is submitted (and thus by its client ID present in the request parameter map #{param}).

    The following kickoff example should do what you need.

    <p:selectOneMenu binding="#{menu1}" ... required="#{not empty param[submit.clientId]}">
        ...                       
    </p:selectOneMenu>
    <p:selectOneMenu ... required="#{not empty param[menu1.clientId]}">
        ...                       
    </p:selectOneMenu>
    <p:commandButton binding="#{submit}" ... />
    

    This way, the 1st menu is only required when the form's main submit button is pressed (and thus not when event listeners are fired) and the 2nd menu is only required when the 1st menu has a value.

    0 讨论(0)
提交回复
热议问题