0

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>

skaffman
  • 398,947
  • 96
  • 818
  • 769
Dimitri
  • 345
  • 1
  • 3
  • 9
  • 1
    see http://stackoverflow.com/questions/4013410/jsf2-validation-clientside-or-serverside – Adam Apr 21 '11 at 09:28

2 Answers2

0

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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
0

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).

Dave Maple
  • 8,102
  • 4
  • 45
  • 64