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());
}
}