[jboss-user] [JBoss Seam] - Re: Recovering from a Constraint violation exception

supernovasoftware.com do-not-reply at jboss.com
Tue Sep 18 11:27:25 EDT 2007

I do this validation manually and add a message to that control if the value already exists.

I am not using Hibernate Validator at all.  In every action that requires validation, I do this.  This handles all complex cases that I have come across.

Does anyone know if it is possible to bind a method of a seam component directly to the view for validation?

Something like the following

 <h:inputText id="#{myId}" value="#{myValue}" converter="#{myValue.validateMyValue}"/>

Currently I am using 

	  public static int addMessages(Map<String, String> m)
  | 	  {
  | 	    for(String key : m.keySet()) 
  | 	    { 
  | 	      if(key.startsWith("globalMessage")) 
  | 	      {
  | 	        FacesMessages.instance().add(m.get(key));
  | 	      } 
  | 	      else
  | 	      {
  | 	        FacesMessages.instance().addToControl(key, m.get(key));
  | 	      }      
  | 	    }
  | 	    return m.size();
  | 	  }

And use this as follows

  private boolean isValid()
  |   {
  | 	HashMap<String, String> errorMessages = new HashMap<String, String>();
  |     ValidatonUtil.checkNull("condition", 
  |                             poPipe.getCondition(),
  |                             "Condition required!",
  |                             errorMessages);
  |     ValidatonUtil.checkUniquePONuml("poNum", 
  |                                                      poPipe.getPoNum(),
  |                                                     "You PO # must be unique!",                            
  |                                                     errorMessages);
  |     ValidatonUtil.checkPositiveDouble("amountOrdered",
  |                                       poPipe.getAmountOrdered(), 
  |                                       "Postive amount required!",
  |                                       errorMessages); 
  |     ValidatonUtil.checkDateRealistic("date",
  |                                       poPipe.getDate(), 
  |                                       "Date required!",
  |                                       errorMessages);  
  |     ValidatonUtil.checkDateRealistic("dateAvailable",
  |                                      poPipe.getDatePromised(), 
  |                                      "Date Available required!",
  |                                      errorMessages);  
  |     return (ValidatonUtil.addMessages(errorMessages)==0) ? true : false;
  |   }

I call a method like this every time I need to validate.  These messages are added after jsf validations.  If for example "0www8" is entered into a numeric field JSF messages appear and mine do not.  I would like for all of these validations to occur at the same time.  I would also like to not have to know the id of the component I want to attach the messages.  If I could specify the method to use to validate and put it on the input field, I would like this to be tied together automatically.

Is this possible and could someone point me to an example?

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

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

More information about the jboss-user mailing list