Cayo,
I spent some time with an error like yours. Simple validation (like that in
Hibernate Validator) worked fine even after first submission (failed due to
required constraints), but complex validation (using some business logic, like
verify if a login field is unique) don't. The JSF code:
| <div class="entry">
| <s:decorate>
| <label>#{messages['user.login']}</label>
| <h:inputText id="login" value="#{user.login}">
| <a:support event="onblur" reRender="loginError" />
| </h:inputText>
| <a:outputPanel id="loginError">
| <s:message />
| <c:if test="#{userManager.loginInUse}">
| #{messages['user.login.in.use']}
| </c:if>
| </a:outputPanel>
| </s:decorate>
| </div>
|
where #{userManager.loginInUse} is a Session Bean method that was supposed to
perform validation (verify if login is unique) at ajax rerendering.
The reason of the fails: the backing bean wasn't properly populated, probably
because "required" constraints returned page before that. So, a method like
user.getLogin (invoked at #{userManager.loginInUse}) returned null, even when
the field was typed in the form.
So, I decided to move this validation to not be executed at ajax events.
Instead, placed it in the action method that is invoked on form submission. If
validation fails, add a message in FacesMessages with Fatal Severity, and
return.
| FacesMessages.instance().addFromResourceBundle(
| FacesMessage.SEVERITY_FATAL, "login.already.in.use");
|
All Fatal errors are displayed as Global Errors at the top of the form:
| <span>
| <h:messages infoClass="success" fatalClass="globalErrors"
errorStyle="display: none" />
| </span>
|
This way, business logic validation is executed at the very begining of action
method (grant simple validation and proper population of backing bean).
Hope it helps.
Fábio.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996549#3996549
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996549
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user