javax.el.ExpressionFactory Java Examples
The following examples show how to use
javax.el.ExpressionFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnvironmentBean.java From sailfish-core with Apache License 2.0 | 6 votes |
public void loadSort() { DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:table"); if(sortField == null || "".equals(sortField)) { dataTable.setValueExpression("sortBy", null); return; } String elRaw = null; if("table:nameColumn".equals(sortField)) { elRaw = "#{service.name}"; } else if("table:typeColumn".equals(sortField)) { elRaw = "#{service.type}"; } else if("table:statusColumn".equals(sortField)) { elRaw = "#{service.status}"; } FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); ExpressionFactory elFactory = facesContext.getApplication().getExpressionFactory(); ValueExpression valueExpresion = elFactory.createValueExpression(elContext, elRaw, Date.class); dataTable.setSortOrder(sortOrder); dataTable.setValueExpression("sortBy", valueExpresion); }
Example #2
Source File: TestValueExpressionImpl.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void testBug51177ObjectList() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); Object o1 = "String value"; Object o2 = Integer.valueOf(32); List<Object> list = new ArrayList<Object>(); list.add(0, o1); list.add(1, o2); ValueExpression var = factory.createValueExpression(list, List.class); context.getVariableMapper().setVariable("list", var); ValueExpression ve1 = factory.createValueExpression( context, "${list[0]}", Object.class); ve1.setValue(context, o2); assertEquals(o2, ve1.getValue(context)); ValueExpression ve2 = factory.createValueExpression( context, "${list[1]}", Object.class); ve2.setValue(context, o1); assertEquals(o1, ve2.getValue(context)); }
Example #3
Source File: TestELParser.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void bug56185() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanC beanC = new TesterBeanC(); ValueExpression var = factory.createValueExpression(beanC, TesterBeanC.class); context.getVariableMapper().setVariable("myBean", var); ValueExpression ve = factory.createValueExpression(context, "${(myBean.int1 > 1 and myBean.myBool) or "+ "((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}", Boolean.class); assertEquals(Boolean.FALSE, ve.getValue(context)); beanC.setInt1(2); beanC.setMyBool1(true); assertEquals(Boolean.TRUE, ve.getValue(context)); }
Example #4
Source File: TestValueExpressionImpl.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void testGetValueReference() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanB beanB = new TesterBeanB(); beanB.setName("Tomcat"); ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class); context.getVariableMapper().setVariable("beanB", var); ValueExpression ve = factory.createValueExpression( context, "${beanB.name}", String.class); // First check the basics work String result = (String) ve.getValue(context); assertEquals("Tomcat", result); // Now check the value reference ValueReference vr = ve.getValueReference(context); assertNotNull(vr); assertEquals(beanB, vr.getBase()); assertEquals("name", vr.getProperty()); }
Example #5
Source File: MockedJsf2TestContainer.java From deltaspike with Apache License 2.0 | 6 votes |
protected void applyContainerConfig() { //add the default values servletContext.addInitParameter("javax.faces.PROJECT_STAGE", "UnitTest"); servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", "true"); servletContext.addInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "-1"); servletContext.addInitParameter("org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE", "true"); servletContext.addInitParameter("org.apache.myfaces.spi.InjectionProvider", "org.apache.myfaces.spi.impl.NoInjectionAnnotationInjectionProvider"); servletContext.addInitParameter("org.apache.myfaces.config.annotation.LifecycleProvider", "org.apache.myfaces.config.annotation.NoInjectionAnnotationLifecycleProvider"); servletConfig.addInitParameter("org.apache.myfaces.CHECKED_VIEWID_CACHE_ENABLED", "false"); servletContext.addInitParameter(ExpressionFactory.class.getName(), "org.apache.el.ExpressionFactoryImpl"); //add custom values (might replace the default values) for (Map.Entry<String, String> entry : containerConfig.entrySet()) { servletContext.addInitParameter(entry.getKey(), entry.getValue()); } }
Example #6
Source File: ExpressionEvaluatorImpl.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
public Expression parseExpression(String expression, Class expectedType, FunctionMapper fMapper ) throws ELException { ExpressionFactory fac = ExpressionFactory.newInstance(); javax.el.ValueExpression expr; ELContextImpl elContext = new ELContextImpl(null); javax.el.FunctionMapper fm = new FunctionMapperWrapper(fMapper); elContext.setFunctionMapper(fm); try { expr = fac.createValueExpression( elContext, expression, expectedType); } catch (javax.el.ELException ex) { throw new ELException(ex); } return new ExpressionImpl(expr, pageContext); }
Example #7
Source File: TestValueExpressionImpl.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void testBug51177ObjectMap() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); Object o1 = "String value"; Object o2 = Integer.valueOf(32); Map<Object,Object> map = new HashMap<Object,Object>(); map.put("key1", o1); map.put("key2", o2); ValueExpression var = factory.createValueExpression(map, Map.class); context.getVariableMapper().setVariable("map", var); ValueExpression ve1 = factory.createValueExpression( context, "${map.key1}", Object.class); ve1.setValue(context, o2); assertEquals(o2, ve1.getValue(context)); ValueExpression ve2 = factory.createValueExpression( context, "${map.key2}", Object.class); ve2.setValue(context, o1); assertEquals(o1, ve2.getValue(context)); }
Example #8
Source File: TestELParser.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testJavaKeyWordSuffix() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); TesterBeanA beanA = new TesterBeanA(); beanA.setInt("five"); ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class); context.getVariableMapper().setVariable("beanA", var); // Should fail Exception e = null; try { factory.createValueExpression(context, "${beanA.int}", String.class); } catch (ELException ele) { e = ele; } Assert.assertNotNull(e); }
Example #9
Source File: TestELParser.java From Tomcat8-Source-Read with MIT License | 6 votes |
private void doTestBug56179(int parenthesesCount, String innerExpr) { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); ValueExpression var = factory.createValueExpression(Boolean.TRUE, Boolean.class); context.getVariableMapper().setVariable("test", var); StringBuilder expr = new StringBuilder(); expr.append("${"); for (int i = 0; i < parenthesesCount; i++) { expr.append("("); } expr.append(innerExpr); for (int i = 0; i < parenthesesCount; i++) { expr.append(")"); } expr.append("}"); ValueExpression ve = factory.createValueExpression( context, expr.toString(), String.class); String result = (String) ve.getValue(context); Assert.assertEquals("true", result); }
Example #10
Source File: TestELParser.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void bug56185() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); TesterBeanC beanC = new TesterBeanC(); ValueExpression var = factory.createValueExpression(beanC, TesterBeanC.class); context.getVariableMapper().setVariable("myBean", var); ValueExpression ve = factory.createValueExpression(context, "${(myBean.int1 > 1 and myBean.myBool) or "+ "((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}", Boolean.class); Assert.assertEquals(Boolean.FALSE, ve.getValue(context)); beanC.setInt1(2); beanC.setMyBool1(true); Assert.assertEquals(Boolean.TRUE, ve.getValue(context)); }
Example #11
Source File: TestELParser.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void bug56185() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanC beanC = new TesterBeanC(); ValueExpression var = factory.createValueExpression(beanC, TesterBeanC.class); context.getVariableMapper().setVariable("myBean", var); ValueExpression ve = factory.createValueExpression(context, "${(myBean.int1 > 1 and myBean.myBool) or "+ "((myBean.myBool or myBean.myBool1) and myBean.int1 > 1)}", Boolean.class); assertEquals(Boolean.FALSE, ve.getValue(context)); beanC.setInt1(2); beanC.setMyBool1(true); assertEquals(Boolean.TRUE, ve.getValue(context)); }
Example #12
Source File: TestValueExpressionImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testGetValueReference() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); TesterBeanB beanB = new TesterBeanB(); beanB.setName("Tomcat"); ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class); context.getVariableMapper().setVariable("beanB", var); ValueExpression ve = factory.createValueExpression( context, "${beanB.name}", String.class); // First check the basics work String result = (String) ve.getValue(context); Assert.assertEquals("Tomcat", result); // Now check the value reference ValueReference vr = ve.getValueReference(context); Assert.assertNotNull(vr); Assert.assertEquals(beanB, vr.getBase()); Assert.assertEquals("name", vr.getProperty()); }
Example #13
Source File: TestELParser.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Test public void testJavaKeyWordIdentifier() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanA beanA = new TesterBeanA(); beanA.setInt("five"); ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class); context.getVariableMapper().setVariable("this", var); // Should fail Exception e = null; try { factory.createValueExpression(context, "${this}", String.class); } catch (ELException ele) { e = ele; } assertNotNull(e); }
Example #14
Source File: TestValueExpressionImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testBug50105() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); TesterEnum testEnum = TesterEnum.APPLE; ValueExpression var = factory.createValueExpression(testEnum, TesterEnum.class); context.getVariableMapper().setVariable("testEnum", var); // When coercing an Enum to a String, name() should always be used. ValueExpression ve1 = factory.createValueExpression( context, "${testEnum}", String.class); String result1 = (String) ve1.getValue(context); Assert.assertEquals("APPLE", result1); ValueExpression ve2 = factory.createValueExpression( context, "foo${testEnum}bar", String.class); String result2 = (String) ve2.getValue(context); Assert.assertEquals("fooAPPLEbar", result2); }
Example #15
Source File: TestValueExpressionImpl.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void testBug50105() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterEnum testEnum = TesterEnum.APPLE; ValueExpression var = factory.createValueExpression(testEnum, TesterEnum.class); context.getVariableMapper().setVariable("testEnum", var); // When coercing an Enum to a String, name() should always be used. ValueExpression ve1 = factory.createValueExpression( context, "${testEnum}", String.class); String result1 = (String) ve1.getValue(context); assertEquals("APPLE", result1); ValueExpression ve2 = factory.createValueExpression( context, "foo${testEnum}bar", String.class); String result2 = (String) ve2.getValue(context); assertEquals("fooAPPLEbar", result2); }
Example #16
Source File: TestValueExpressionImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testBug51177ObjectList() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); Object o1 = "String value"; Object o2 = Integer.valueOf(32); List<Object> list = new ArrayList<>(); list.add(0, o1); list.add(1, o2); ValueExpression var = factory.createValueExpression(list, List.class); context.getVariableMapper().setVariable("list", var); ValueExpression ve1 = factory.createValueExpression( context, "${list[0]}", Object.class); ve1.setValue(context, o2); Assert.assertEquals(o2, ve1.getValue(context)); ValueExpression ve2 = factory.createValueExpression( context, "${list[1]}", Object.class); ve2.setValue(context, o1); Assert.assertEquals(o1, ve2.getValue(context)); }
Example #17
Source File: TestELParser.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
private void doTestBug56179(int parenthesesCount, String innerExpr) { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); ValueExpression var = factory.createValueExpression(Boolean.TRUE, Boolean.class); context.getVariableMapper().setVariable("test", var); StringBuilder expr = new StringBuilder(); expr.append("${"); for (int i = 0; i < parenthesesCount; i++) { expr.append("("); } expr.append(innerExpr); for (int i = 0; i < parenthesesCount; i++) { expr.append(")"); } expr.append("}"); ValueExpression ve = factory.createValueExpression( context, expr.toString(), String.class); String result = (String) ve.getValue(context); assertEquals("true", result); }
Example #18
Source File: TestValueExpressionImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testBug51544Bean() throws Exception { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); TesterBeanA beanA = new TesterBeanA(); beanA.setValList(Collections.emptyList()); ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class); context.getVariableMapper().setVariable("beanA", var); ValueExpression ve = factory.createValueExpression( context, "${beanA.valList.size()}", Integer.class); Integer result = (Integer) ve.getValue(context); Assert.assertEquals(Integer.valueOf(0), result); }
Example #19
Source File: TestValueExpressionImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testBug51544Direct() throws Exception { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); List<?> list = Collections.emptyList(); ValueExpression var = factory.createValueExpression(list, List.class); context.getVariableMapper().setVariable("list", var); ValueExpression ve = factory.createValueExpression( context, "${list.size()}", Integer.class); Integer result = (Integer) ve.getValue(context); Assert.assertEquals(Integer.valueOf(0), result); }
Example #20
Source File: TestValueExpressionImpl.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Test public void testBug56522SetNullValue() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(factory); TesterBeanB beanB = new TesterBeanB(); beanB.setName("Tomcat"); ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class); context.getVariableMapper().setVariable("beanB", var); ValueExpression ve = factory.createValueExpression( context, "${beanB.name}", String.class); // First check the basics work String result = (String) ve.getValue(context); Assert.assertEquals("Tomcat", result); // Now set the value to null ve.setValue(context, null); Assert.assertEquals("", beanB.getName()); }
Example #21
Source File: ELPlugin.java From seed with Mozilla Public License 2.0 | 6 votes |
private static Object buildExpressionFactory() { try { // EL will use the TCCL to find the implementation return ExpressionFactory.newInstance(); } catch (Throwable t1) { // If TCCL failed, we use the ClassLoader that loaded the ELPlugin final ClassLoader originalTCCL = run(Thread.currentThread()::getContextClassLoader); try { run((PrivilegedAction<Void>) () -> { Thread.currentThread().setContextClassLoader(ELPlugin.class.getClassLoader()); return null; }); return ExpressionFactory.newInstance(); } catch (Throwable t2) { throw SeedException.wrap(t2, ELErrorCode.UNABLE_TO_INSTANTIATE_EXPRESSION_FACTORY); } finally { // restore original TCCL run((PrivilegedAction<Void>) () -> { Thread.currentThread().setContextClassLoader(originalTCCL); return null; }); } } }
Example #22
Source File: TestValueExpressionImpl.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void testBug51177ObjectList() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); Object o1 = "String value"; Object o2 = Integer.valueOf(32); List<Object> list = new ArrayList<Object>(); list.add(0, o1); list.add(1, o2); ValueExpression var = factory.createValueExpression(list, List.class); context.getVariableMapper().setVariable("list", var); ValueExpression ve1 = factory.createValueExpression( context, "${list[0]}", Object.class); ve1.setValue(context, o2); assertEquals(o2, ve1.getValue(context)); ValueExpression ve2 = factory.createValueExpression( context, "${list[1]}", Object.class); ve2.setValue(context, o1); assertEquals(o1, ve2.getValue(context)); }
Example #23
Source File: TestELParser.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Test public void testJavaKeyWordSuffix() { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); TesterBeanA beanA = new TesterBeanA(); beanA.setInt("five"); ValueExpression var = factory.createValueExpression(beanA, TesterBeanA.class); context.getVariableMapper().setVariable("beanA", var); // Should fail Exception e = null; try { factory.createValueExpression(context, "${beanA.int}", String.class); } catch (ELException ele) { e = ele; } assertNotNull(e); }
Example #24
Source File: FeelEngineImpl.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public FeelEngineImpl(FeelToJuelTransform transform, ExpressionFactory expressionFactory, ElContextFactory elContextFactory, Cache<TransformExpressionCacheKey, String> transformExpressionCache) { this.transform = transform; this.expressionFactory = expressionFactory; this.elContextFactory = elContextFactory; this.transformExpressionCache = transformExpressionCache; }
Example #25
Source File: ElExpressionSample.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 5 votes |
public void unsafeEL(String expression) { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); ValueExpression vex = expressionFactory.createValueExpression(elContext, expression, String.class); String result = (String) vex.getValue(elContext); System.out.println(result); }
Example #26
Source File: TestELParser.java From tomcatsrc with Apache License 2.0 | 5 votes |
private void testExpression(String expression, String expected) { ExpressionFactory factory = ExpressionFactory.newInstance(); ELContext context = new ELContextImpl(); ValueExpression ve = factory.createValueExpression( context, expression, String.class); String result = (String) ve.getValue(context); assertEquals(expected, result); }
Example #27
Source File: FeelEngineImpl.java From camunda-engine-dmn with Apache License 2.0 | 5 votes |
public FeelEngineImpl(FeelToJuelTransform transform, ExpressionFactory expressionFactory, ElContextFactory elContextFactory, Cache<TransformExpressionCacheKey, String> transformExpressionCache) { this.transform = transform; this.expressionFactory = expressionFactory; this.elContextFactory = elContextFactory; this.transformExpressionCache = transformExpressionCache; }
Example #28
Source File: ELModule.java From seed with Mozilla Public License 2.0 | 5 votes |
@Override protected void configure() { bind(ExpressionFactory.class).toInstance(expressionFactory); bind(ELService.class).to(ELServiceInternal.class); bind(ELContextBuilder.class).to(ELContextBuilderImpl.class); for (Class<ELHandler<?>> elHandlerClass : elMap.values()) { bind(elHandlerClass); } // bind the map of annotation -> ELHandler bind(new AnnotationHandlersTypeLiteral()).toInstance(ImmutableMap.copyOf(elMap)); }
Example #29
Source File: RuleEvaluator.java From proctor with Apache License 2.0 | 5 votes |
RuleEvaluator( @Nonnull final ExpressionFactory expressionFactory, @Nonnull final FunctionMapper functionMapper, @Nonnull final Map<String, Object> testConstantsMap ) { this.expressionFactory = expressionFactory; this.functionMapper = functionMapper; elResolver = constructStandardElResolver(); testConstants = ProctorUtils.convertToValueExpressionMap(expressionFactory, testConstantsMap); }
Example #30
Source File: RandomTestChooser.java From proctor with Apache License 2.0 | 5 votes |
public RandomTestChooser( final ExpressionFactory expressionFactory, final FunctionMapper functionMapper, final String testName, @Nonnull final ConsumableTestDefinition testDefinition ) { this(System.nanoTime(), expressionFactory, functionMapper, testName, testDefinition); }