Package com.ocpsoft.pretty.faces.config.mapping

Examples of com.ocpsoft.pretty.faces.config.mapping.PathValidator


                     "Please set the index of the path parameter you want to validate with the @URLValidator specified on mapping: "
                              + mapping.getId());
         }

         // prepare PathValidator
         PathValidator pathValidator = new PathValidator();
         pathValidator.setIndex(validationAnnotation.index());
         pathValidator.setOnError(validationAnnotation.onError());
         pathValidator.setValidatorIds(join(validationAnnotation.validatorIds(), " "));

         // optional validator method
         if (!isBlank(validationAnnotation.validator()))
         {
            pathValidator.setValidatorExpression(new ConstantExpression(validationAnnotation.validator()));
         }

         // add PathValidator to the mapping
         mapping.getPathValidators().add(pathValidator);
View Full Code Here


      validators.addAll(child.getPathValidators());

      int i = 0;
      for (PathValidator pv : validators)
      {
         PathValidator temp = copy(pv);
         temp.setIndex(i++);
         result.add(temp);
      }

      child.setPathValidators(result);
   }
View Full Code Here

      return result;
   }

   private PathValidator copy(PathValidator pathValidator)
   {
      PathValidator result = new PathValidator();
      result.setIndex(pathValidator.getIndex());
      result.setOnError(pathValidator.getOnError());
      result.setValidatorIds(pathValidator.getValidatorIds());
      result.setValidatorExpression(pathValidator.getValidatorExpression());
      return result;
   }
View Full Code Here

   private void validatePathParams(final FacesContext context, final URL url, final UrlMapping mapping)
   {
      List<PathParameter> params = mapping.getPatternParser().parse(url);

      PathParameter currentParameter = new PathParameter();
      PathValidator currentPathValidator = new PathValidator();
      String currentValidatorId = "";
      try
      {
         for (PathParameter param : params)
         {
            currentParameter = param;

            List<PathValidator> validators = mapping.getValidatorsForPathParam(param);

            if (validators != null && validators.size() > 0)
            {
               String value = param.getValue();
               Object coerced = elUtils.coerceToType(context, param.getExpression().getELExpression(), value);
               for (PathValidator pv : validators)
               {
                  currentPathValidator = pv;
                  for (String id : pv.getValidatorIdList())
                  {
                     currentValidatorId = id;
                     Validator validator = context.getApplication().createValidator(id);
                     validator.validate(context, new NullComponent(), coerced);
                  }
                  if (pv.getValidatorExpression() != null)
                  {
                     elUtils.invokeMethod(context, pv.getValidatorExpression().getELExpression(),
                              new Class<?>[] { FacesContext.class, UIComponent.class, Object.class },
                              new Object[] { context, new NullComponent(), coerced });
                  }
               }
            }
         }
      }
      catch (ELException e)
      {
         FacesMessage message = new FacesMessage("Could not coerce value [" + currentParameter.getValue()
                  + "] on mappingId [" + mapping.getId() + "] to type in location [" + currentParameter.getExpression()
                  + "]");
         handleValidationFailure(context, message, currentPathValidator.getOnError());
      }
      catch (ValidatorException e)
      {
         handleValidationFailure(context, e.getFacesMessage(), currentPathValidator.getOnError());
      }
      catch (FacesException e)
      {
         FacesMessage message = new FacesMessage("Error occurred invoking validator with id [" + currentValidatorId
                  + "] on mappingId [" + mapping.getId() + "] parameter [" + currentParameter.getExpression()
                  + "] at position [" + currentParameter.getPosition() + "]");
         handleValidationFailure(context, message, currentPathValidator.getOnError());
      }
   }
View Full Code Here

   public PrettyUrlMappingTest()
   {
      m.setId("foo");
      m.setPattern("/project/#{pb.name}");
      m.addPathValidator(new PathValidator(0, "val1 val2 val3", "#{handler.handle}"));
      m.addPathValidator(new PathValidator(2, "val4 val5", "#{handler.handle}"));
   }
View Full Code Here

      assertEquals(0, mapping.getActions().size());
      assertEquals(0, mapping.getQueryParams().size());
      assertEquals(1, mapping.getPathValidators().size());

      // check path validation
      PathValidator validator = mapping.getPathValidators().get(0);
      assertEquals(0, validator.getIndex());
      assertEquals("#{bean.action}", validator.getOnError());
      assertEquals("myValidator myOtherValidator", validator.getValidatorIds());

   }
View Full Code Here

            throw new IllegalArgumentException(
                  "Please set the index of the path parameter you want to validate with the @URLValidator specified on mapping: " + mapping.getId());
         }

         // prepare PathValidator
         PathValidator pathValidator = new PathValidator();
         pathValidator.setIndex(validationAnnotation.index());
         pathValidator.setOnError(validationAnnotation.onError());
         pathValidator.setValidatorIds(join(validationAnnotation.validatorIds(), " "));

         // optional validator method
         if (!isBlank(validationAnnotation.validator()))
         {
            pathValidator.setValidatorExpression(new ConstantExpression(validationAnnotation.validator()));
         }

         // add PathValidator to the mapping
         mapping.getPathValidators().add(pathValidator);
View Full Code Here

      validators.addAll(child.getPathValidators());

      int i = 0;
      for (PathValidator pv : validators)
      {
         PathValidator temp = copy(pv);
         temp.setIndex(i++);
         result.add(temp);
      }

      child.setPathValidators(result);
   }
View Full Code Here

      child.setPathValidators(result);
   }

   private PathValidator copy(PathValidator pathValidator)
   {
      PathValidator result = new PathValidator();
      result.setIndex(pathValidator.getIndex());
      result.setOnError(pathValidator.getOnError());
      result.setValidatorIds(pathValidator.getValidatorIds());
      result.setValidatorExpression(pathValidator.getValidatorExpression());
      return result;
   }
View Full Code Here

   private void validatePathParams(final FacesContext context, final URL url, final UrlMapping mapping)
   {
      List<PathParameter> params = mapping.getPatternParser().parse(url);

      PathParameter currentParameter = new PathParameter();
      PathValidator currentPathValidator = new PathValidator();
      String currentValidatorId = "";
      try
      {
         for (PathParameter param : params)
         {
            currentParameter = param;

            List<PathValidator> validators = mapping.getValidatorsForPathParam(param);

            if (validators != null && validators.size() > 0)
            {
               String value = param.getValue();
               Object coerced = elUtils.coerceToType(context, param.getExpression().getELExpression(), value);
               for (PathValidator pv : validators)
               {
                  currentPathValidator = pv;
                  for (String id : pv.getValidatorIdList())
                  {
                     currentValidatorId = id;
                     Validator validator = context.getApplication().createValidator(id);
                     validator.validate(context, new NullComponent(), coerced);
                  }
                  if (pv.getValidatorExpression() != null)
                  {
                     elUtils.invokeMethod(context, pv.getValidatorExpression().getELExpression(),
                              new Class<?>[] { FacesContext.class, UIComponent.class, Object.class },
                              new Object[] { context, new NullComponent(), coerced });
                  }
               }
            }
         }
      }
      catch (ELException e)
      {
         FacesMessage message = new FacesMessage("Could not coerce value [" + currentParameter.getValue()
                  + "] on mappingId [" + mapping.getId() + "] to type in location [" + currentParameter.getExpression()
                  + "]");
         handleValidationFailure(context, message, currentPathValidator.getOnError());
      }
      catch (ValidatorException e)
      {
         handleValidationFailure(context, e.getFacesMessage(), currentPathValidator.getOnError());
      }
      catch (FacesException e)
      {
         FacesMessage message = new FacesMessage("Error occurred invoking validator with id [" + currentValidatorId
                  + "] on mappingId [" + mapping.getId() + "] parameter [" + currentParameter.getExpression()
                  + "] at position [" + currentParameter.getPosition() + "]");
         handleValidationFailure(context, message, currentPathValidator.getOnError());
      }
   }
View Full Code Here

TOP

Related Classes of com.ocpsoft.pretty.faces.config.mapping.PathValidator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.