[jboss-user] [JBoss Seam] - Re: Object level validation

norman.richards@jboss.com do-not-reply at jboss.com
Thu Dec 28 21:06:05 EST 2006


You can easily add extra conditions:


  |     @AssertTrue(message="second number must be larger than the first")
  |     public boolean checkNumbers() {
  |         System.out.println("number1=" + number1 + " number2=" + number2);
  |         return number2 > number1;
  |     }
  | 

   Hibernate will check the condition at persist() time.  Unfortunately, it doesn't handle it a way that is very friendly to your application. (from the perspective of being transparent)  You'll have to add a bit of code to the application for that.  Here's an overridden persist on EntityHome:


  |     @Transactional
  |     @Override
  |     public String persist()
  |     {
  |         ClassValidator validator = Validators.instance().getValidator(YourEntity.class, "yourEntity");
  |         InvalidValue[] ivs = validator.getInvalidValues(getInstance());
  |         if (ivs.length>0) {
  |             facesMessages.add(ivs);
  |             return null;
  |         }
  | 
  |         return super.persist();
  |     }
  | 



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3996766#3996766

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996766



More information about the jboss-user mailing list