0

I have a simple input text element in my form.

The user has 2 possible actions to take on that form: 1) approve the form and 2) reject the form. So there are 2 buttons at the bottom of the form for the user to click on.

If the user clicks on approve the comment inputField should be optional. If the user clicks on reject the comment inputField should be required.

Here is a simple representation of the form:

<h:form>
    <p:inputText id="comment" required="???" .../>

    <p:commandButton id="approve" ... />
    <p:commandButton id="reject" ... />
</h:form>
felipe_gdr
  • 1,088
  • 2
  • 11
  • 27

2 Answers2

3

Try this.

<h:form id="forma">
    <p:inputText id="comment" 
                 value="#{userView.firstname}" 
                 title="comment" 
                 required="#{not empty param[reject.clientId]}"/>
    <p:message for="comment"/>

    <p:commandButton id="approve" 
                     binding="#{approve}" 
                     value="approve" 
                     process="@form" 
                     update="@form"/>
    <p:commandButton id="reject" 
                     binding="#{reject}" 
                     value="reject" 
                     process="@form" 
                     update="@form"/>
</h:form>
wittakarn
  • 3,124
  • 1
  • 18
  • 31
1

Your question looks similar to Dynamic required validation for different buttons?.

Modify the required attribute as follows:

<h:form id="form">
    <p:inputText id="comment" required="#{not empty param['form:reject']}" ... />
    <p:commandButton id="approve" ... />
    <p:commandButton id="reject" ... />
</h:form> 
Community
  • 1
  • 1
Seitaridis
  • 4,459
  • 9
  • 53
  • 85