[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Gavin King gavin.king at jboss.com
Tue Jun 12 14:46:43 EDT 2007


  User: gavin   
  Date: 07/06/12 14:46:43

  Modified:    src/main/org/jboss/seam/core  Expressions.java
  Log:
  do model-based validation for page parameters
  
  Revision  Changes    Path
  1.34      +30 -2     jboss-seam/src/main/org/jboss/seam/core/Expressions.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Expressions.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Expressions.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -b -r1.33 -r1.34
  --- Expressions.java	1 Jun 2007 19:47:12 -0000	1.33
  +++ Expressions.java	12 Jun 2007 18:46:43 -0000	1.34
  @@ -1,4 +1,4 @@
  -//$Id: Expressions.java,v 1.33 2007/06/01 19:47:12 gavin Exp $
  +//$Id: Expressions.java,v 1.34 2007/06/12 18:46:43 gavin Exp $
   package org.jboss.seam.core;
   
   import static org.jboss.seam.InterceptionType.NEVER;
  @@ -9,7 +9,9 @@
   
   import javax.el.ELContext;
   import javax.el.ExpressionFactory;
  +import javax.faces.application.FacesMessage;
   import javax.faces.context.FacesContext;
  +import javax.faces.validator.ValidatorException;
   
   import org.hibernate.validator.ClassValidator;
   import org.hibernate.validator.InvalidValue;
  @@ -187,7 +189,7 @@
       * 
       * @return the validation failures, as InvalidValues
       */
  -   public InvalidValue[] validate(String propertyExpression, Object value)
  +   public InvalidValue[] getInvalidValues(String propertyExpression, Object value)
      {
         if (propertyExpression == null)
         {
  @@ -230,6 +232,32 @@
      }
      
      /**
  +    * Validate that a value can be assigned to the property
  +    * identified by a value expression.
  +    * 
  +    * @param propertyExpression a value expression
  +    * @param value the value that is to be assigned
  +    * 
  +    * @throws ValidatorException is validation fails
  +    */
  +   public void validate(String propertyExpression, Object value)
  +   {
  +      InvalidValue[] ivs;
  +      try
  +      {
  +         ivs = getInvalidValues(propertyExpression, value );
  +      }
  +      catch (Exception e)
  +      {
  +         throw new ValidatorException( new FacesMessage(FacesMessage.SEVERITY_ERROR, "model validation failed:" + e.getMessage(), null), e );
  +      }
  +      if ( ivs.length>0 )
  +      {
  +         throw new ValidatorException( FacesMessages.createFacesMessage( FacesMessage.SEVERITY_ERROR, ivs[0].getMessage() ) );
  +      }
  +   }
  +
  +   /**
       * Gets the validator from the Component object (if this is a Seam
       * component, we need to use the validator for the bean class, not
       * the proxy class) or from a Model object (if it is not a Seam
  
  
  



More information about the jboss-cvs-commits mailing list