[jboss-cvs] jboss-seam/seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/validator ...

Peter Muir peter at bleepbleep.org.uk
Tue Mar 20 13:58:59 EDT 2007


  User: pmuir   
  Date: 07/03/20 13:58:59

  Added:       seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/validator 
                        ModelValidator.java
  Log:
  Port more tags to CDK
  
  Revision  Changes    Path
  1.1      date: 2007/03/20 17:58:59;  author: pmuir;  state: Exp;jboss-seam/seam-ui-cdk/jboss-seam-ui/src/main/java/org/jboss/seam/ui/validator/ModelValidator.java
  
  Index: ModelValidator.java
  ===================================================================
  package org.jboss.seam.ui.validator;
  
  import javax.faces.application.FacesMessage;
  import javax.faces.component.UIComponent;
  import javax.faces.context.FacesContext;
  import javax.faces.el.ValueBinding;
  import javax.faces.validator.Validator;
  import javax.faces.validator.ValidatorException;
  
  import org.hibernate.validator.InvalidValue;
  import org.jboss.seam.core.Expressions;
  import org.jboss.seam.core.FacesMessages;
  
  public class ModelValidator implements Validator
  {
  
     public void validate(FacesContext context, UIComponent component, Object value)
           throws ValidatorException
     {
        ValueBinding valueBinding = component.getValueBinding("value");
        if (valueBinding==null)
        {
           throw new RuntimeException("component has no value attribute: " + component.getId());
        }
        InvalidValue[] ivs;
        try
        {
           ivs = Expressions.instance().validate( valueBinding.getExpressionString(), value );
        }
        catch (Exception e)
        {
           throw new ValidatorException( new FacesMessage(FacesMessage.SEVERITY_ERROR, "model validation failed:" + e.getMessage(), null) );
        }
        if ( ivs.length>0 )
        {
           throw new ValidatorException( FacesMessages.createFacesMessage( FacesMessage.SEVERITY_WARN, ivs[0].getMessage() ) );
        }
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list