0 Replies Latest reply on Sep 28, 2011 7:27 AM by Raj Raj

    Highlighting the form field if the validation fails in JSF

    Raj Raj Newbie

      I am working on JSF2.0 and Richfaces. I am having an requirement where I need to change the style of the form field(entire row) if the validation fails. I am using the following code to display field label and text box.

       

      <h:panelGrid columns="2">

           <h:outputLabel value="#{uit.firstname}:">

                        <span class="required"><strong>*</strong> </span>

           </h:outputLabel>                 

           <h:inputText value="#{editUserProfileBean.firstName}" type="text"                           id="firstname" styleClass="basicFormTextBox" size="30"                           required="true" requiredMessage="#{uitkem.valueRequired}"

             validatorMessage="#{prod.firstNameValidator}">

             <f:validateLength maximum="#{prodConf.MaxLengthForFirstName}"

             minimum="#{prodConf.MinLengthForFirstName}" />

           </h:inputText>

      </h:panelGrid>

       

      Suppose if the validation fails, I need to hightlight the row(both label and textbox) as shown in the attached image.

      I can use the following code to hightlight the textbox if the validation fails. But I want to hightlight the entire row, that is not possible using the following code.

       

      <h:inputText value="#{editUserProfileBean.firstName}" required="true" styleClass="#{not component.valid ? 'newStyleClass' : ''}" /> 

       

      Can anyone help me on this?

      Thanks in advance.