@Test public void testInvoke() { TesterBeanB beanB = new TesterBeanB(); beanB.setName("B"); context .getVariableMapper() .setVariable("beanB", factory.createValueExpression(beanB, TesterBeanB.class)); MethodExpression me1 = factory.createMethodExpression( context, "${beanB.getName}", String.class, new Class<?>[] {}); MethodExpression me2 = factory.createMethodExpression( context, "${beanB.sayHello('JUnit')}", String.class, new Class<?>[] {String.class}); MethodExpression me3 = factory.createMethodExpression( context, "${beanB.sayHello}", String.class, new Class<?>[] {String.class}); assertEquals("B", me1.invoke(context, null)); assertEquals("Hello JUnit from B", me2.invoke(context, null)); assertEquals("Hello JUnit from B", me2.invoke(context, new Object[] {"JUnit2"})); assertEquals("Hello JUnit2 from B", me3.invoke(context, new Object[] {"JUnit2"})); assertEquals("Hello JUnit from B", me2.invoke(context, new Object[] {null})); assertEquals("Hello from B", me3.invoke(context, new Object[] {null})); }
public static MethodExpression createMethodExpression( String el, Class returnType, Class[] paramTypes) { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory factory = ExpressionFactory.newInstance(); return factory.createMethodExpression( context.getELContext(), el, null, new Class[] {String.class}); }
@Override public Object getValue(ELContext context) { ELContext nxcontext = getLocalContext(context); Object res = null; if (originalValueExpression != null) { res = originalValueExpression.getValue(nxcontext); if (res instanceof String) { String expression = (String) res; if (ComponentTagUtils.isValueReference(expression)) { FacesContext faces = FacesContext.getCurrentInstance(); Application app = faces.getApplication(); ExpressionFactory factory = app.getExpressionFactory(); ValueExpression newExpr = factory.createValueExpression(nxcontext, expression, expectedType); try { res = newExpr.getValue(nxcontext); } catch (ELException err) { log.error("Error processing expression " + expression + ": " + err); res = null; } } else { res = expression; } } } return res; }
public Object invokeMethodExpression( String expr, Class returnType, Class[] argTypes, Object[] args) { FacesContext fc = FacesContext.getCurrentInstance(); ELContext elctx = fc.getELContext(); ExpressionFactory elFactory = fc.getApplication().getExpressionFactory(); MethodExpression methodExpr = elFactory.createMethodExpression(elctx, expr, returnType, argTypes); return methodExpr.invoke(elctx, args); }
@Test public void testBugPrimitives() throws Exception { MethodExpression me = factory.createMethodExpression(context, "${beanA.setValLong(5)}", null, null); me.invoke(context, null); ValueExpression ve = factory.createValueExpression(context, "#{beanA.valLong}", java.lang.String.class); assertEquals("5", ve.getValue(context)); }
@Test public void testInvokeWithSuper() { MethodExpression me = factory.createMethodExpression( context, "${beanA.setBean(beanBB)}", null, new Class<?>[] {TesterBeanB.class}); me.invoke(context, null); ValueExpression ve = factory.createValueExpression(context, "${beanA.bean.name}", String.class); Object r = ve.getValue(context); assertEquals("BB", r); }
static ValueExpression restore(Object value, Class type, FacesContext context) { if (value == null) return null; String expr = (String) value; Application app = context.getApplication(); ExpressionFactory factory = app.getExpressionFactory(); return factory.createValueExpression(context.getELContext(), expr, type); }
/** * @param expressao * @param obj * @param clazz */ public void setAtributo(String expressao, Object obj, Class clazz) { FacesContext current = FacesContext.getCurrentInstance(); Application app = current.getApplication(); ExpressionFactory fac = app.getExpressionFactory(); ValueExpression ve = fac.createValueExpression(current.getELContext(), expressao, clazz); ve.setValue(current.getELContext(), obj); }
/* * This is also tested implicitly in numerous places elsewhere in this class. */ @Test public void testBug49655() throws Exception { // This is the call the failed MethodExpression me = factory.createMethodExpression(context, "#{beanA.setName('New value')}", null, null); // The rest is to check it worked correctly me.invoke(context, null); ValueExpression ve = factory.createValueExpression(context, "#{beanA.name}", java.lang.String.class); assertEquals("New value", ve.getValue(context)); }
@Override public Object evaluateMethodExpression(String expression, Object... values) throws UnsupportedEvaluationException { String el = toELExpression(expression); FacesContext facesContext = getFacesContext(); ELContext elContext = facesContext.getELContext(); ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory(); MethodExpression methodExpression = expressionFactory.createMethodExpression( elContext, el, Object.class, new Class[values.length]); return methodExpression.invoke(elContext, values); }
protected MethodExpression getExpresionAccionEscogerNodo() { if (expresionAccionZum == null) { ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory(); ELContext context = FacesContext.getCurrentInstance().getELContext(); String expression = "#{" + getPaginaBasica().getManagedBeanName() + ".accionEscogerNodo}"; expresionAccionZum = factory.createMethodExpression(context, expression, String.class, new Class[] {}); track("getExpresionAccionEscogerNodo", expression); } return expresionAccionZum; }
/** * @param hierarchy * @return */ protected UIComponent createFilterItem(Hierarchy hierarchy) { String id = "filter-item-" + hierarchy.getUniqueName().hashCode(); HtmlPanelGroup panel = new HtmlPanelGroup(); panel.setId(id); panel.setLayout("block"); panel.setStyleClass("ui-widget-header filter-item"); CommandLink link = new CommandLink(); link.setId(id + "-link"); link.setValue(hierarchy.getCaption()); link.setTitle(hierarchy.getUniqueName()); FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory factory = context.getApplication().getExpressionFactory(); link.setActionExpression( factory.createMethodExpression( context.getELContext(), "#{filterHandler.show}", Void.class, new Class<?>[0])); link.setUpdate(":filter-form"); link.setOncomplete("PF('filterDialog').show();"); UIParameter parameter = new UIParameter(); parameter.setName("hierarchy"); parameter.setValue(hierarchy.getName()); link.getChildren().add(parameter); panel.getChildren().add(link); CommandButton closeButton = new CommandButton(); closeButton.setId(id + "-button"); closeButton.setIcon("ui-icon-close"); closeButton.setActionExpression( factory.createMethodExpression( context.getELContext(), "#{filterHandler.removeHierarchy}", Void.class, new Class<?>[0])); closeButton.setUpdate( ":filter-items-form,:source-tree-form,:grid-form,:editor-form:mdx-editor,:editor-form:editor-toolbar"); closeButton.setOncomplete("onViewChanged()"); UIParameter parameter2 = new UIParameter(); parameter2.setName("hierarchy"); parameter2.setValue(hierarchy.getName()); closeButton.getChildren().add(parameter2); panel.getChildren().add(closeButton); return panel; }
@Test public void testBug52445a() { MethodExpression me = factory.createMethodExpression( context, "${beanA.setBean(beanBB)}", null, new Class<?>[] {TesterBeanB.class}); me.invoke(context, null); MethodExpression me1 = factory.createMethodExpression(context, "${beanA.bean.sayHello()}", null, null); String actual = (String) me1.invoke(context, null); assertEquals("Hello from BB", actual); }
@Test public void testBug52970() { MethodExpression me = factory.createMethodExpression( context, "${beanEnum.submit('APPLE')}", null, new Class<?>[] {TesterBeanEnum.class}); me.invoke(context, null); ValueExpression ve = factory.createValueExpression(context, "#{beanEnum.lastSubmitted}", TesterEnum.class); TesterEnum actual = (TesterEnum) ve.getValue(context); assertEquals(TesterEnum.APPLE, actual); }
/** * @param exp * @param clazz * @return */ public Object getAtributo(String exp, Class clazz) { FacesContext current = FacesContext.getCurrentInstance(); Application app = current.getApplication(); ExpressionFactory fac = app.getExpressionFactory(); ValueExpression ve = fac.createValueExpression(current.getELContext(), exp, clazz); Object resultado = ve.getValue(current.getELContext()); return resultado; }
public String getValueFrmExpression(String data) { FacesContext fc = FacesContext.getCurrentInstance(); Application app = fc.getApplication(); ExpressionFactory elFactory = app.getExpressionFactory(); ELContext elContext = fc.getELContext(); ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class); String Message = null; Object obj = valueExp.getValue(elContext); if (obj != null) { Message = obj.toString(); } return Message; }
protected Object coerceToModelType(FacesContext ctx, Object value, Class itemValueType) { Object newValue; try { ExpressionFactory ef = ctx.getApplication().getExpressionFactory(); newValue = ef.coerceToType(value, itemValueType); } catch (ELException ele) { newValue = value; } catch (IllegalArgumentException iae) { newValue = value; } return newValue; }
static ValueExpression restoreWithType(Object value, FacesContext context) { if (value == null) return null; Object[] state = (Object[]) value; String expr = (String) state[0]; Class type = (Class) state[1]; Application app = context.getApplication(); ExpressionFactory factory = app.getExpressionFactory(); return factory.createValueExpression(context.getELContext(), expr, type); }
public String getValue(String key) { final SufdAttribute attr = getSufdDescriptor().get(key); ELContext elContext = FacesContext.getCurrentInstance().getELContext(); ExpressionFactory f = FacesContext.getCurrentInstance().getApplication().getExpressionFactory(); ValueExpression ex = f.createValueExpression(elContext, attr.getValue(), Object.class); final Object value = ex.getValue(elContext); if (value instanceof LocalDate) { return ((LocalDate) value).format(dateTimeFormatter); } else if (value instanceof BigDecimal) { return decimalFormatter.format(value); } else { return value.toString(); } }
/** * @param writer * @param component * @param context * @param scripts * @param styles * @throws java.io.IOException */ public static void writeRequiredIncludes( ResponseWriter writer, UIComponent component, FacesContext context, String[] scripts, String[] styles) throws IOException { /* * Prepare access to the managed bean NitobiIncludes */ ELContext elContext = context.getELContext(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); MethodExpression methodExpression = expressionFactory.createMethodExpression( elContext, "#{NitobiIncludes.registerInclude}", Boolean.TYPE, new Class[] {String.class}); /* * Include the toolkit if needed */ if ((Boolean) methodExpression.invoke(elContext, new Object[] {NitobiIncludes.TOOLKIT})) { writeScriptInclude(writer, component, NitobiIncludes.TOOLKIT); } /* * Include the scripts */ if (scripts != null) { for (String include : scripts) { if ((Boolean) methodExpression.invoke(elContext, new Object[] {include})) { writeScriptInclude(writer, component, include); } } } /* * Include the styles */ if (styles != null) { for (String style : styles) { if ((Boolean) methodExpression.invoke(elContext, new Object[] {style})) { writeCSSInclude(writer, component, style); } } } }
@Test public void testMethExpr() { MethodExpression meth = null; ELContext ctxt = elm.getELContext(); try { meth = factory.createMethodExpression(ctxt, "#{str.length}", Object.class, null); } catch (NullPointerException ex) { // Do nothing } assertTrue(meth == null); meth = factory.createMethodExpression(ctxt, "#{'abc'.length()}", Object.class, null); Object result = meth.invoke(ctxt, new Object[] {"abcde"}); System.out.println("'abc'.length() called, equals " + result); assertEquals(result, new Integer(3)); }
protected String resolveTheme(FacesContext context) { String theme = null; String themeConfigValue = RequestContext.getCurrentInstance().getApplicationContext().getConfig().getMobileTheme(); if (themeConfigValue != null) { ELContext elContext = context.getELContext(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ValueExpression ve = expressionFactory.createValueExpression(elContext, themeConfigValue, String.class); theme = ve.isLiteralText() ? themeConfigValue : (String) ve.getValue(elContext); } return theme; }
private boolean _jspx_meth_c_005fset_005f0(PageContext _jspx_page_context) throws Throwable { PageContext pageContext = _jspx_page_context; JspWriter out = _jspx_page_context.getOut(); // c:set org.apache.taglibs.standard.tag.rt.core.SetTag _jspx_th_c_005fset_005f0 = (org.apache.taglibs.standard.tag.rt.core.SetTag) _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.get( org.apache.taglibs.standard.tag.rt.core.SetTag.class); _jspx_th_c_005fset_005f0.setPageContext(_jspx_page_context); _jspx_th_c_005fset_005f0.setParent(null); // /common/jspHead.jsp(4,0) name = var type = java.lang.String reqTime = false required = false // fragment = false deferredValue = false expectedTypeName = null deferredMethod = false // methodSignature = null _jspx_th_c_005fset_005f0.setVar("ctx"); // /common/jspHead.jsp(4,0) name = value type = javax.el.ValueExpression reqTime = true required // = false fragment = false deferredValue = true expectedTypeName = java.lang.Object // deferredMethod = false methodSignature = null _jspx_th_c_005fset_005f0.setValue( new org.apache.jasper.el.JspValueExpression( "/common/jspHead.jsp(4,0) '${pageContext.request.contextPath}'", _el_expressionfactory.createValueExpression( _jspx_page_context.getELContext(), "${pageContext.request.contextPath}", java.lang.Object.class)) .getValue(_jspx_page_context.getELContext())); int _jspx_eval_c_005fset_005f0 = _jspx_th_c_005fset_005f0.doStartTag(); if (_jspx_th_c_005fset_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.reuse( _jspx_th_c_005fset_005f0); return true; } _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.reuse( _jspx_th_c_005fset_005f0); return false; }
@Test public void testInvokeWithSuperAAAB() { MethodExpression me11 = factory.createMethodExpression(context, "${beanC.sayHello(beanAAA,beanB)}", null, null); Object r11 = me11.invoke(context, null); assertEquals("AAB: Hello AAA from B", r11.toString()); }
@Test public void testBug50449b() throws Exception { MethodExpression me1 = factory.createMethodExpression(context, "${beanB.sayHello('Tomcat')}", null, null); String actual = (String) me1.invoke(context, null); assertEquals("Hello Tomcat from B", actual); }
public void processAction(ActionEvent e) throws AbortProcessingException { FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); try { Object value = source.getValue(elContext); if (value != null) { ExpressionFactory factory = facesContext.getApplication().getExpressionFactory(); value = factory.coerceToType(value, target.getType(elContext)); } target.setValue(elContext, value); } catch (ELException ele) { throw new AbortProcessingException(ele); } }
@Test public void testInvokeWithSuperABNoReturnTypeNoParamTypes() { MethodExpression me2 = factory.createMethodExpression(context, "${beanC.sayHello(beanA,beanB)}", null, null); Object r2 = me2.invoke(context, null); assertEquals("AB: Hello A from B", r2.toString()); }
private boolean _jspx_meth_c_005fset_005f0( javax.servlet.jsp.tagext.JspTag _jspx_th_c_005fif_005f2, PageContext _jspx_page_context) throws Throwable { JspWriter out = _jspx_page_context.getOut(); // c:set org.apache.taglibs.standard.tag.rt.core.SetTag _jspx_th_c_005fset_005f0 = (org.apache.taglibs.standard.tag.rt.core.SetTag) _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.get( org.apache.taglibs.standard.tag.rt.core.SetTag.class); _jspx_th_c_005fset_005f0.setPageContext(_jspx_page_context); _jspx_th_c_005fset_005f0.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_c_005fif_005f2); // /WEB-INF/tags/form/fields/display.tagx(20,57) name = var type = java.lang.String reqTime = // false required = false fragment = false deferredValue = false expectedTypeName = null // deferredMethod = false methodSignature = null _jspx_th_c_005fset_005f0.setVar("dateTimePattern"); // /WEB-INF/tags/form/fields/display.tagx(20,57) name = value type = javax.el.ValueExpression // reqTime = true required = false fragment = false deferredValue = true expectedTypeName = // java.lang.Object deferredMethod = false methodSignature = null _jspx_th_c_005fset_005f0.setValue( new org.apache.jasper.el.JspValueExpression( "/WEB-INF/tags/form/fields/display.tagx(20,57) 'MM/dd/yyyy'", _el_expressionfactory.createValueExpression("MM/dd/yyyy", java.lang.Object.class)) .getValue(this.getJspContext().getELContext())); int _jspx_eval_c_005fset_005f0 = _jspx_th_c_005fset_005f0.doStartTag(); if (_jspx_th_c_005fset_005f0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) { _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.reuse( _jspx_th_c_005fset_005f0); throw new SkipPageException(); } _005fjspx_005ftagPool_005fc_005fset_0026_005fvar_005fvalue_005fnobody.reuse( _jspx_th_c_005fset_005f0); return false; }
@Test public void testInvokeWithSuperABBB() { MethodExpression me7 = factory.createMethodExpression(context, "${beanC.sayHello(beanA,beanBBB)}", null, null); Object r7 = me7.invoke(context, null); assertEquals("ABB: Hello A from BBB", r7.toString()); }
@Test public void testIsParametersProvided() { TesterBeanB beanB = new TesterBeanB(); beanB.setName("Tomcat"); ValueExpression var = factory.createValueExpression(beanB, TesterBeanB.class); context.getVariableMapper().setVariable("beanB", var); MethodExpression me1 = factory.createMethodExpression( context, "${beanB.getName}", String.class, new Class<?>[] {}); MethodExpression me2 = factory.createMethodExpression( context, "${beanB.sayHello('JUnit')}", String.class, new Class<?>[] {String.class}); assertFalse(me1.isParmetersProvided()); assertTrue(me2.isParmetersProvided()); }