public ViewFactory createViewFactory(Expression viewId, ExpressionParser expressionParser, ConversionService conversionService, BinderConfiguration binderConfiguration, Validator validator, ValidationHintResolver validationHintResolver) { if (useSpringBeanBinding) { expressionParser = new BeanWrapperExpressionParser(conversionService); } AbstractMvcViewFactory viewFactory = createMvcViewFactory(viewId, expressionParser, conversionService, binderConfiguration); if (StringUtils.hasText(eventIdParameterName)) { viewFactory.setEventIdParameterName(eventIdParameterName); } if (StringUtils.hasText(fieldMarkerPrefix)) { viewFactory.setFieldMarkerPrefix(fieldMarkerPrefix); } viewFactory.setValidator(validator); viewFactory.setValidationHintResolver(validationHintResolver); return viewFactory; }
protected Expression doParseExpression(String expressionString, ParserContext context) throws ParserException { BeanWrapperExpression expression = new BeanWrapperExpression(expressionString, conversionService); expression.setAutoGrowNestedPaths(autoGrowNestedPaths); expression.setAutoGrowCollectionLimit(autoGrowCollectionLimit); return expression; } }
protected Expression doParseExpression(String expressionString, ParserContext context) throws ParserException { return new BeanWrapperExpression(expressionString, conversionService); } }
public void testParseTemplateComposite() { String exp = "hello ${flag} ${flag} ${flag}"; Expression e = parser.parseExpression(exp, new FluentParserContext().template()); assertNotNull(e); String str = (String) e.getValue(bean); assertEquals("hello false false false", str); }
public void testParseSimpleAllowDelimited() { parser.setAllowDelimitedEvalExpressions(true); String exp = "${flag}"; Expression e = parser.parseExpression(exp, null); assertNotNull(e); Boolean b = (Boolean) e.getValue(bean); assertFalse(b); }
public Class<?> getValueType(Object context) { try { BeanWrapperImpl beanWrapper = new BeanWrapperImpl(context); return beanWrapper.getPropertyType(expression); } catch (NotReadablePropertyException e) { throw new PropertyNotFoundException(context.getClass(), expression, e); } catch (BeansException e) { throw new EvaluationException(context.getClass(), getExpressionString(), "An BeansException occurred getting the value type for expression '" + getExpressionString() + "' on context [" + context.getClass() + "]", e); } }
public void testParseSimple() { String exp = "flag"; Expression e = parser.parseExpression(exp, null); assertNotNull(e); Boolean b = (Boolean) e.getValue(bean); assertFalse(b); }
public void testSetBogusValueWithCoersion() { Expression e = parser.parseExpression("date", null); try { e.setValue(bean, "bogus"); fail("Should have failed tme"); } catch (ValueCoercionException ex) { assertTrue(ex.getCause() instanceof TypeMismatchException); } }
public void testParseSimpleDelimitedNotAllowed() { String exp = "${flag}"; try { parser.parseExpression(exp, null); fail("should have failed"); } catch (ParserException e) { } }
public void testGetValueType() { String exp = "flag"; Expression e = parser.parseExpression(exp, null); assertEquals(boolean.class, e.getValueType(bean)); }
public void testSetValueWithCoersion() { GenericConversionService cs = (GenericConversionService) parser.getConversionService(); StringToDate converter = new StringToDate(); converter.setPattern("yyyy-MM-dd"); cs.addConverter(converter); Expression e = parser.parseExpression("date", null); e.setValue(bean, "2008-9-15"); }
public void setAsText(String text) throws IllegalArgumentException { try { Object convertedValue = converter.execute(text); setValue(convertedValue); } catch (ConversionException e) { IllegalArgumentException iae = new IllegalArgumentException("Unable to convert text '" + text + "'"); iae.initCause(e); throw iae; } } }
protected Expression doParseExpression(String expressionString, ParserContext context) throws ParserException { BeanWrapperExpression expression = new BeanWrapperExpression(expressionString, conversionService); expression.setAutoGrowNestedPaths(autoGrowNestedPaths); expression.setAutoGrowCollectionLimit(autoGrowCollectionLimit); return expression; } }
protected ExpressionParser getExpressionParser() { return new BeanWrapperExpressionParser(); }
public void testParseTemplateEmpty() { Expression e = parser.parseExpression("", new FluentParserContext().template()); assertNotNull(e); assertEquals("", e.getValue(bean)); }
public Class<?> getValueType(Object context) { try { BeanWrapperImpl beanWrapper = new BeanWrapperImpl(context); return beanWrapper.getPropertyType(expression); } catch (NotReadablePropertyException e) { throw new PropertyNotFoundException(context.getClass(), expression, e); } catch (BeansException e) { throw new EvaluationException(context.getClass(), getExpressionString(), "An BeansException occurred getting the value type for expression '" + getExpressionString() + "' on context [" + context.getClass() + "]", e); } }
public void testTemplateEnclosedCompositeNotSupported() { String exp = "${hello ${flag} ${flag} ${flag}}"; try { parser.parseExpression(exp, new FluentParserContext().template()); fail("Should've failed - not intended use"); } catch (ParserException e) { } }
public void testGetValueTypeNullCollectionValue() { String exp = "list[0]"; Expression e = parser.parseExpression(exp, null); assertEquals(null, e.getValueType(bean)); }
public ViewFactory createViewFactory(Expression viewId, ExpressionParser expressionParser, ConversionService conversionService, BinderConfiguration binderConfiguration) { if (useSpringBeanBinding) { expressionParser = new BeanWrapperExpressionParser(conversionService); } AbstractMvcViewFactory viewFactory = createMvcViewFactory(viewId, expressionParser, conversionService, binderConfiguration); if (StringUtils.hasText(eventIdParameterName)) { viewFactory.setEventIdParameterName(eventIdParameterName); } if (StringUtils.hasText(fieldMarkerPrefix)) { viewFactory.setFieldMarkerPrefix(fieldMarkerPrefix); } return viewFactory; }
public void testParseTemplateSimpleLiteral() { String exp = "flag"; Expression e = parser.parseExpression(exp, new FluentParserContext().template()); assertNotNull(e); assertEquals("flag", e.getValue(bean)); }