I have a case where s:validateAll was not firing hibernate validators for all
fields on a page. We found a workaround, but believe we have found code used
by the Seam s:validateAll tag that could be enhanced to properly validating all
of the fields without the workaround. Here's the scenario:
I have an Institution class, with a @Role specified for name
"currentInstitution".
However, institution could be one of many subclasses, for example, I have a
school class that extends Institution.
For the page in question, I was updating a school. However, whether a school
or any other kind of institution, I use currentInstitution as the backing bean
(keeps the code really simple and non-redundant). s:validateAll was firing the
validators for the fields that reside in the Institution class, but not those
in the School subclass.
We found that the following code hit during the processing of s:validateAll
was causing the school-specific fields to not be validated:
private static ClassValidator getValidator(Object instance, String
componentName)
| {
| Component component = Component.forName(componentName);
| return ( component==null ? Model.forClass( instance.getClass() ) :
component ).getValidator();
| }
The code first looks to see if currentInstitution is a defined Seam component.
It is, by virtue of the @Role annotation, so it calls getValidator() for the
Institution class, not the School class.
We resolved this issue by removing the @Role annotation and manually setting
currentInstitution into the the Conversation context, as such:
Contexts.getConversationContext().set("currentInstitution", currentInstitution);
Now, since the code in question does not recognize currentInstitution as a Seam
component, it uses the Model for the School class, which returns the desired
validators.
Long-winded way of getting here, but our question is if the s, instead of
looking to see if the s:validateAll code can be made more sophisticated, such
that it properly handles validators on the subclass? Is it necessary to look
for the Seam component, or can the code just always use the model of the class
of which the backing bean is an instance?
If the Seam developers agree with this proposed change, I'll add to the JIRA.
Thanks!
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4044440#4044440
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4044440
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user