views:

313

answers:

1

Hi,

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.

+1  A: 

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.

BalusC