Rashmi
Rashmi

Reputation: 31

JSF required field validation-need help

I am Rashmi.I have two forms in a single JSP page which are developed using JSF.Each form has one required field input and a submit button.On click of any of the button from any form,both forms should get validated and display required message.Please need help..........

sample code:

  <body>
<f:view>
  <h:form id="form1">
     <h:outputText value="UserName:"/>
     <h:inputText id="userName1" value="#{userBean.userName}" required="true" requiredMessage="UserName1 required"/><br/><br/>
      <h:message for="userName1" style="color:red"></h:message>
     <a4j:commandButton action="login1" value="SUBMIT" type="submit" reRender="form1,form2" />
  </h:form>
  <br/>
  <br/>
  <br/>
  <h:form id="form2">
      <h:outputText value="UserName:"/>
     <h:inputText id="userName2" value="#{userBean.userName}" required="true" requiredMessage="UserName2 required"/><br/><br/>
     <h:message for="userName2" style="color:red"></h:message>
     <a4j:commandButton action="login" value="SUBMIT" type="submit" reRender="form1,form2" >
     </a4j:commandButton>
     <h:commandLink ></h:commandLink>
  </h:form>  
  </f:view>
</body>

in advance Thanks.

Upvotes: 0

Views: 2270

Answers (1)

BalusC
BalusC

Reputation: 1109735

Put the input fields which you'd like to send to the server (and thus implicitly also let to validate by JSF) in the same <h:form>. Right now you have two independent forms.

Upvotes: 2

Related Questions