-
1. Re: Problems with Validator and Seam when submit form
ask4saif Dec 27, 2006 3:16 AM (in response to fabio.ita04)I had the same kind of problem with the hibernate validation annotations, but i was not using a4j in it.
Is there any kind of exception raised when you submit the form?
Try to Remove the @NotNull annotaion and then try to run you example, As its alternate use the required="true" in your jsf tags.
can you mail me your code on ask4saif@gmail.com, i will see what i can do.
Thank you -
2. Re: Problems with Validator and Seam when submit form
fabio.ita04 Dec 27, 2006 1:17 PM (in response to fabio.ita04)Thanks for the tip! required=true in JSF worked (forms being validated on submission).
I noted that when *NOT* using required=true, the fields are *ONLY* validated if they *AREN'T EMPTY*.
So, it's frustrating: when I say @Length(min=5), implicitly I say that property is required, don't?
Thanx,
Fábio. -
3. Re: Problems with Validator and Seam when submit form
norman.richards Dec 27, 2006 3:01 PM (in response to fabio.ita04)JSF only validates fields that are submitted. If the field is empty, it isn't submitted and isn't validated. It's just the way that JSF works. (and really the way HTTP works)
-
4. Re: Problems with Validator and Seam when submit form
cayo Dec 27, 2006 4:41 PM (in response to fabio.ita04)I have a problem which goes in the same direction. I'm interested if anyone had this problem too.
After validating the form and e.g. have validation messages because of required=true violation on the form, the ajax4jsf actions cannot rerender fields which are currently in validation error.
It's a problem if the user cannot use the ajax4jsf controls after he tried to validate the form. -
5. Re: Problems with Validator and Seam when submit form
fabio.ita04 Dec 27, 2006 7:19 PM (in response to fabio.ita04)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. -
6. Re: Problems with Validator and Seam when submit form
cayo Dec 28, 2006 7:10 AM (in response to fabio.ita04)Thanks Fábio!
I will try this.