-
1. Re: Complex validation assign message to specific component.
max522over Apr 11, 2006 11:58 AM (in response to supernovasoftware.com)The following is from chapter 3 of the validation chapter of the hibernate docs. I see the @MyBeanConstraint and I wonder what that is. Is that a validation created for by the developer for that class to ensure not more than 45 instances of dog?
Can we attach validations for the entire class similiar to the @MyBeanConstraint or do we use MyBeanConstraint? Would this be what you are looking for. I know I have complex validations that span multiple fields and multiple classes. Where should I put that, in controlling logic, and only field level constraints in validations.
While the example only shows public property validation, you can also annotate fields of any kind of visibility.@MyBeanConstraint(max=45) public class Dog { @AssertTrue private boolean isMale; @NotNull protected String getName() { ... }; ... }
You can also annotate interfaces. Hibernate Validator will check all superclasses and interfaces extended or implemented by a given bean to read the appropriate validator annotations.public interface Named { @NotNull String getName(); ... } public class Dog implements Named { @AssertTrue private boolean isMale; public String getName() { ... }; }
The name property will be checked for nullity when the Dog bean is validated. -
2. Re: Complex validation assign message to specific component.
supernovasoftware.com Apr 11, 2006 12:12 PM (in response to supernovasoftware.com)Not sure if that is what I am looking for.
What I would like to do is code my own logic in the method I use to persist the object and then add them to be displayed next to a particular field.
Use@In(create = true) FacesMessages facesMessages;
and then something like the following:if(checkEmailInExternalResource(email) { facesMessages.add(new FacesMessage("duplidate email); }
,but I see no way in the FacesMessages interface to specify a field the message applies to.
I also triedfc.addMessage("email",new FacesMessage("duplicate email"));
, but this does now work either.
Any assistance woudl be greatly appreciated. -
3. Re: Complex validation assign message to specific component.
gavin.king Apr 11, 2006 1:01 PM (in response to supernovasoftware.com)Unfortunately, JSF does not make it easy to do this. Look at ValidationInterceptor.addMessageToFacesContext() to see how to do it.
What I will do for you is expose this functionality on FacesMessages. -
5. Re: Complex validation assign message to specific component.
supernovasoftware.com Apr 11, 2006 1:09 PM (in response to supernovasoftware.com)Thank you for the prompt reply and proposed solution.
I spent all day yesterday trying to get this to work. I figured this would be obvious and trivial like most of the other seam features.
I guess it will be when you add this to FacesMessages.
Thx again. :) -
6. Re: Complex validation assign message to specific component.
gavin.king Apr 11, 2006 4:03 PM (in response to supernovasoftware.com)Fixed in CVS, please try it out for me. Thanks
-
7. Re: Complex validation assign message to specific component.
supernovasoftware.com Apr 11, 2006 9:00 PM (in response to supernovasoftware.com)I checked out the CVS head and saw your modifications. Then I complied my project against the new seam jar and included it with my project I cannot get any messages to appear from either the annotations or using your modification as shown below. Going back to the old jar solves the problem.
Not even with <h:messages/>@In(create=true) FacesMessages facesMessages; ... facesMessages.add("nameFirst", new FacesMessage("Test Gavin's new component messages"));
I have
<h:inputText value="#{member.nameFirst}" id="nameFirst" /> <h:message for="nameFirst"/>
in my page.
1. Am I using the method properly?
2. If I do multiple validations and add a message for each one, how can I check the size of FacesMessages in order to decide if I should proceed or redirect back to form?
-
8. Re: Complex validation assign message to specific component.
gavin.king Apr 12, 2006 12:14 AM (in response to supernovasoftware.com)Try updating again. Perhaps you got a broken checkout.
-
9. Re: Complex validation assign message to specific component.
supernovasoftware.com Apr 12, 2006 3:03 AM (in response to supernovasoftware.com)That was it. That rocks. It seems to do exactly what I wanted.
-
10. Re: Complex validation assign message to specific component.
supernovasoftware.com Apr 18, 2006 1:18 PM (in response to supernovasoftware.com)I have been using the component assigned messages in the following manner:
@IfInvalid(outcome = REDISPLAY) public String create() { if(poCoupling.getSize().getId()==null) { facesMessages.add("size", new FacesMessage("Size required")); } if(poCoupling.getGrade().getId()==null) { facesMessages.add("grade", new FacesMessage("Grade required")); } if(!facesMessages.isEmpty()) return null; poCouplingDAO.makePersistent(poCoupling); return "nothing"; }
I added the following method to FacesMessages in order to check to see if I should redisplay the form.public boolean isEmpty() { if(facesMessages.size()==0 && keyedFacesMessages.size()==0) { return true; } else { return false; } }
I need to check for the presence of an id in my objects because they are connected to a dropdown and if the id is null I get an org.hibernate.TransientObjectException.
Is there an existing way to do this? If not, how do you feel about adding this funtionality? -
11. Re: Complex validation assign message to specific component.
supernovasoftware.com Apr 18, 2006 1:20 PM (in response to supernovasoftware.com)I have been using the component assigned messages in the following manner:
@IfInvalid(outcome = REDISPLAY) public String create() { if(poCoupling.getSize().getId()==null) { facesMessages.add("size", new FacesMessage("Size required")); } if(poCoupling.getGrade().getId()==null) { facesMessages.add("grade", new FacesMessage("Grade required")); } if(!facesMessages.isEmpty()) return null; poCouplingDAO.makePersistent(poCoupling); return "nothing"; }
I added the following method to FacesMessages in order to check to see if I should redisplay the form.public boolean isEmpty() { if(facesMessages.size()==0 && keyedFacesMessages.size()==0) { return true; } else { return false; } }
I need to check for the presence of an id in my objects because they are connected to a dropdown and if the id is null I get an org.hibernate.TransientObjectException.
Is there an existing way to do this? If not, how do you feel about adding this funtionality?