0
votes

I am starting to get to know JSF and I have been able to add some standard validators that show up in messages that I have defined, but they only validate when I click the button to submit the form where the components that need to be validated are in. I would like those components to be validated already on the moment that I click outside them (for example with onblur), but I don't know which method I have to call in the onblur-property to execute the validator of that element? The code I have at this moment is:

<h:form>
  <h:outputText value="#{msgs.name}"/><br/>
  <h:inputText id="name" value="#{user.name}" label="#{msgs.name}" required="true" requiredMessage="#{msgs.name_required}"/>
 <h:message for="name" styleClass="error_single_message"/>
  <br/><br/>

  <h:outputText value="#{msgs.password}"/><br/>
  <h:inputText id="password" value="#{user.password}" label="#{msgs.password}" required="true" requiredMessage="#{msgs.password_required}"/>
  <h:message for="password" styleClass="error_single_message"/>
  <br/><br/>

  <div class="error_overview_messages">Overview errors
  <h:messages showDetail="#{true}" showSummary="#{false}"/>
  </div><br/>

  <h:commandButton value="Log_on" action="logged_in"/>
</h:form>

2

2 Answers

0
votes

JSF validations happens server side, so you will essentially need to have a submit triggered to have server side code activated.

If you are not interested in that, you need to activate some specific Java script.

0
votes

If you are using JSF2, you can accomplish what you are looking for by adding Richfaces to your build and using Richfaces client side validation:

Richfaces Client Side Validation

It is a great new feature in their v4 release that compiles standard jsf validators and JSR-303 bean validation to javascript that can be executed client side. You can trigger the validations on any standard javascript event (blur, click, keyup).