[jboss-user] [JBoss Seam] - Re: Gotchas (so far)

tony.herstell@gmail.com do-not-reply at jboss.com
Tue Nov 14 18:33:28 EST 2006

Another Gotcha....

if you have a 

  | @Length(min = 12, max = 30, message = "sim must between 12 and 30 characters long")
on a Database Object that is NOT mandatory (like a post code) that is mapped to a view component of type string.

If you leave the string empty in the view you get a "" back as apposed to a null (which seems helpful as it reduces a lot of null pointer exceptions).

However, I had to write code to convert the "" back to null just before persisting it to stop the validator failing...

  | 		// Need to set "" to null for validator to allow a blank field through.
  | 		subscriber.setCreationDate(new Date());
  | 		if (subscriber.getXxx().equals("")) {
  | 			ZZZZZZZ.setXxx(null);
  | 		}
  | 		if (subscriber.getYyy().equals("")) {
  | 			ZZZZZZZ.setYyy(null);
  | 		}
  | 		em.persist(ZZZZZZ);

I could have extended the validator, but this seemed wrong as a string of "" should fail !!!
The better solution was to pass null to the validator.


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

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

More information about the jboss-user mailing list