@Test public void should_match_method_name_in_EL() throws Exception { assertArrayEquals("Simplest" , arr("#{bean}", "myMethod"), splitAtLastProperty("#{bean.myMethod}")); assertArrayEquals("methodFollowedBySpaces" , arr("#{bean}", "methodFollowedBySpaces"), splitAtLastProperty("#{bean.methodFollowedBySpaces }")); assertArrayEquals("_ and digits" , arr("#{bean}", "_myMethod123"), splitAtLastProperty("#{bean._myMethod123}")); assertArrayEquals("$ in name" , arr("#{bean}", "$my34Method"), splitAtLastProperty("#{bean.$my34Method}")); assertArrayEquals("After property" , arr("#{bean.property}", "myMethod"), splitAtLastProperty("#{bean.property.myMethod}")); assertArrayEquals("After mapped property" , arr("#{bean['property']}", "myMethod"), splitAtLastProperty("#{bean['property'].myMethod}")); try { splitAtLastProperty("#{bean.000notAMethod}"); fail("Should have failed - Name can't start with a digit"); } catch (IllegalArgumentException e) {} }
protected static String[] splitAtLastProperty(String elExpression) { final Matcher matcher = RE_LAST_EL_PROPERTY.matcher(elExpression); if (matcher.find()) { final int matchGroup = 1; final int propertyNameWithDotStart = matcher.start(matchGroup) - 1; String lastProperty = matcher.group(matchGroup); String elWithoutLastProperty = elExpression.substring(0, propertyNameWithDotStart) + "}"; return new String[] {elWithoutLastProperty, lastProperty}; } else { throw new IllegalArgumentException("Couldn't find a trailing property name in the EL '" + elExpression + "' using " + matcher); } }
Jsf12ValidatingElResolver implements ValidatingElResolver { protected static String[] splitAtLastProperty(String elExpression) { final Matcher matcher = RE_LAST_EL_PROPERTY.matcher(elExpression); if (matcher.find()) { final int matchGroup = 1; final int propertyNameWithDotStart = matcher.start(matchGroup) - 1; String lastProperty = matcher.group(matchGroup); String elWithoutLastProperty = elExpression.substring(0, propertyNameWithDotStart) + "}"; return new String[] {elWithoutLastProperty, lastProperty}; } else { throw new IllegalArgumentException("Couldn't find a trailing property name in the EL '" + elExpression + "' using " + matcher); } } }
Jsf12ValidatingElResolver implements ValidatingElResolver { protected static String[] splitAtLastProperty(String elExpression) { final Matcher matcher = RE_LAST_EL_PROPERTY.matcher(elExpression); if (matcher.find()) { final int matchGroup = 1; final int propertyNameWithDotStart = matcher.start(matchGroup) - 1; String lastProperty = matcher.group(matchGroup); String elWithoutLastProperty = elExpression.substring(0, propertyNameWithDotStart) + "}"; return new String[] {elWithoutLastProperty, lastProperty}; } else { throw new IllegalArgumentException("Couldn't find a trailing property name in the EL '" + elExpression + "' using " + matcher); } } Jsf12ValidatingElResolver(); }
Jsf12ValidatingElResolver implements ValidatingElResolver { protected static String[] splitAtLastProperty(String elExpression) { final Matcher matcher = RE_LAST_EL_PROPERTY.matcher(elExpression); if (matcher.find()) { final int matchGroup = 1; final int propertyNameWithDotStart = matcher.start(matchGroup) - 1; String lastProperty = matcher.group(matchGroup); String elWithoutLastProperty = elExpression.substring(0, propertyNameWithDotStart) + "}"; return new String[] {elWithoutLastProperty, lastProperty}; } else { throw new IllegalArgumentException("Couldn't find a trailing property name in the EL '" + elExpression + "' using " + matcher); } } Jsf12ValidatingElResolver(); @Override /** {@inheritDoc} */ ValidationResult validateElExpression(String elExpression, AttributeInfo attributeInfo); JsfElValidator declareVariable(String name, Object value); JsfElValidator definePropertyTypeOverride(String mapJsfExpression,
            Class<?> newType); void setUnknownVariableResolver(
            ElVariableResolver unknownVariableResolver); void setIncludeKnownVariablesInException(
            boolean includeKnownVariablesInException); void addElExpressionFilter(ElExpressionFilter elExpressionFilter); }
Jsf12ValidatingElResolver implements ValidatingElResolver { protected static String[] splitAtLastProperty(String elExpression) { final Matcher matcher = RE_LAST_EL_PROPERTY.matcher(elExpression); if (matcher.find()) { final int matchGroup = 1; final int propertyNameWithDotStart = matcher.start(matchGroup) - 1; String lastProperty = matcher.group(matchGroup); String elWithoutLastProperty = elExpression.substring(0, propertyNameWithDotStart) + "}"; return new String[] {elWithoutLastProperty, lastProperty}; } else { throw new IllegalArgumentException("Couldn't find a trailing property name in the EL '" + elExpression + "' using " + matcher); } } Jsf12ValidatingElResolver(); @Override /** {@inheritDoc} */ ValidationResult validateElExpression(String elExpression, AttributeInfo attributeInfo); JsfElValidator declareVariable(String name, Object value); JsfElValidator definePropertyTypeOverride(String mapJsfExpression,
            Class<?> newType); void setUnknownVariableResolver(
            ElVariableResolver unknownVariableResolver); void setIncludeKnownVariablesInException(
            boolean includeKnownVariablesInException); void addElExpressionFilter(ElExpressionFilter elExpressionFilter); static final Pattern RE_LAST_EL_PROPERTY; }