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

Gavin King gavin.king at jboss.com
Tue Jul 17 11:27:08 EDT 2007


  User: gavin   
  Date: 07/07/17 11:27:08

  Modified:    src/main/org/jboss/seam/navigation   Pages.java Param.java
  Log:
  JBSEAM-1041 do validation of page parameters after checking redirects and permissions
  this was needed because model-based validation requires evaluating the value bindings 
  
  Revision  Changes    Path
  1.8       +45 -22    jboss-seam/src/main/org/jboss/seam/navigation/Pages.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Pages.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/navigation/Pages.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- Pages.java	12 Jul 2007 11:18:31 -0000	1.7
  +++ Pages.java	17 Jul 2007 15:27:08 -0000	1.8
  @@ -349,11 +349,11 @@
      {
         //first store the page parameters into the viewroot, so 
         //that if a login redirect occurs, or if a failure
  -      //occurs while applying to the model, we can still make
  -      //Redirect.captureCurrentView() work.
  -      boolean validationFailed = storeRequestParameterValuesInViewRoot(facesContext);
  -      if (validationFailed) Validation.instance().fail();
  +      //occurs while validating of applying to the model, we can 
  +      //still make Redirect.captureCurrentView() work.
  +      storeRequestParameterValuesInViewRoot(facesContext);
         
  +      //check if we need to redirect
         String viewId = getViewId(facesContext);      
         for ( Page page: getPageStack(viewId) )
         {         
  @@ -378,10 +378,20 @@
            }
         }
   
  -      //now apply page parameters to the model
  +      //now validate the values we just stored in
  +      //the view root, after the redirect checking
  +      if ( validateViewRootValues(facesContext) ) 
  +      {
  +         Validation.instance().fail();
  +         //and don't apply them to the model
  +      }
  +      else
  +      {   
  +         //finally apply page parameters to the model
         //(after checking permissions)
         applyViewRootValues(facesContext);
      }
  +   }
      
      private boolean isNoConversationRedirectRequired(Page page)
      {
  @@ -714,32 +724,45 @@
         }
      }
      
  -   private boolean storeRequestParameterValuesInViewRoot(FacesContext facesContext)
  +   private void storeRequestParameterValuesInViewRoot(FacesContext facesContext)
      {
  -      String viewId = getViewId(facesContext);
         Map<String, String[]> requestParameters = Parameters.instance().getRequestParameters();
  -      boolean validationFailed = false;
  -      for ( Page page: getPageStack(viewId) )
  +      for ( Page page: getPageStack( getViewId(facesContext) ) )
         {
            for ( Param pageParameter: page.getParameters() )
            {  
  -            try
  -            {
                  Object value = pageParameter.getValueFromRequest(facesContext, requestParameters);
                  if (value==null)
                  {
  +               //this should not be necessary, were it not for a MyFaces bug
                     if ( facesContext.getRenderResponse() ) //ie. for a non-faces request
                     {
  -                     //this should not be necessary, were it not for a MyFaces bug
                        Contexts.getPageContext().remove( pageParameter.getName() );
                     }
  -                  //TODO: add some support for required=true
                  }
                  else
                  {
                     Contexts.getPageContext().set( pageParameter.getName(), value );
                  }
               }
  +      }
  +   }
  +   
  +   private boolean validateViewRootValues(FacesContext facesContext)
  +   {
  +      boolean validationFailed = false;
  +      for ( Page page: getPageStack( getViewId(facesContext) ) )
  +      {
  +         for ( Param pageParameter: page.getParameters() )
  +         {  
  +            try
  +            {
  +               Object value = Contexts.getPageContext().get( pageParameter.getName() );
  +               if (value!=null)
  +               {
  +                  pageParameter.validateConvertedValue(facesContext, value);
  +               }
  +            }
               catch (ValidatorException ve)
               {
                  facesContext.addMessage( null, ve.getFacesMessage() );
  
  
  
  1.8       +10 -4     jboss-seam/src/main/org/jboss/seam/navigation/Param.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Param.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/navigation/Param.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- Param.java	10 Jul 2007 16:46:58 -0000	1.7
  +++ Param.java	17 Jul 2007 15:27:08 -0000	1.8
  @@ -200,10 +200,18 @@
            return null;
         }
         
  -      Object value = converter==null ? 
  +      return converter==null ? 
               stringValue :
               converter.getAsObject( facesContext, facesContext.getViewRoot(), stringValue );
  +   }
         
  +   /**
  +    * Validate the pre-converted value of the parameter using the JSF
  +    * validator specified in pages.xml, and using Hibernate Validator
  +    * annotations specified on the model.
  +    */
  +   public void validateConvertedValue(FacesContext facesContext, Object value)
  +   {
         Validator validator = getValidator();
         if (validator!=null)
         {
  @@ -231,8 +239,6 @@
               throw new ValidatorException( createMessage(invalidValues) );
            }
         }
  -      
  -      return value;
      }
   
      private FacesMessage createMessage(InvalidValue[] invalidValues)
  
  
  



More information about the jboss-cvs-commits mailing list