Java Code Examples for javax.faces.context.FacesContext#getELContext()
The following examples show how to use
javax.faces.context.FacesContext#getELContext() .
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: MessagesBean.java From sailfish-core with Apache License 2.0 | 5 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:name".equals(sortField)) { elRaw = "#{message.name}"; } else if("table:from".equals(sortField)) { elRaw = "#{message.from}"; } else if("table:to".equals(sortField)) { elRaw = "#{message.to}"; } else if("table:content".equals(sortField)) { elRaw = "#{message.content}"; } else if("table:timestamp".equals(sortField)) { elRaw = "#{message.timestamp}"; } 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 3
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 4
Source File: ElExpressionSample.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 5 votes |
public void safeEL() { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); ValueExpression vex = expressionFactory.createValueExpression(elContext, "1+1", String.class); String result = (String) vex.getValue(elContext); System.out.println(result); }
Example 5
Source File: ResourceHandlerWrapper.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void handleResourceRequest(FacesContext context) throws IOException { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String library = params.get("ln"); String dynamicContentId = params.get(Constants.DYNAMIC_CONTENT_PARAM); if (dynamicContentId != null && library != null && library.equals("primefaces")) { Map<String, Object> session = context.getExternalContext().getSessionMap(); try { String dynamicContentEL = (String) session.get(dynamicContentId); if (!ALLOWED_EXPRESSIONS.contains(dynamicContentEL)) { throw new Exception("prevented EL " + dynamicContentEL); } System.out.println(dynamicContentEL); ELContext elContext = context.getELContext(); ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), dynamicContentEL, StreamedContent.class); StreamedContent content = (StreamedContent) ve.getValue(elContext); HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); response.setContentType(content.getContentType()); byte[] buffer = new byte[2048]; int length; InputStream inputStream = content.getStream(); while ((length = (inputStream.read(buffer))) >= 0) { response.getOutputStream().write(buffer, 0, length); } response.setStatus(200); response.getOutputStream().flush(); context.responseComplete(); } catch (Exception e) { logger.log(Level.SEVERE, "Error in streaming dynamic resource" + e.getMessage()); } finally { session.remove(dynamicContentId); } } else { super.handleResourceRequest(context); } }
Example 6
Source File: ApplicationScopeBean.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
public static String evalLabelEl(String labelEl) { if (ALLOWED_LABEL_EXPRESSIONS_PATTERN_REGEXP.matcher(labelEl).find()) { FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), "#{" + labelEl + "}", String.class); return (String) ve.getValue(elContext); } return labelEl; }
Example 7
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Utility method to create a JSF Value expression from the p_expression string * * @param p_expression * @return */ public static ValueExpression createValueExpression(String p_expression) { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, Object.class); return vex; }
Example 8
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Utility method to create a JSF Value expression from p_expression with * exprectedType class as return * * @param p_expression * @param expectedType * @return */ public static ValueExpression createValueExpression(String p_expression, Class<?> expectedType) { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); if (null == expectedType) { LOGGER.severe("The expected type of " + p_expression + " is null. Defaulting to String."); expectedType = String.class; } ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, expectedType); return vex; }
Example 9
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Utility method to create a JSF Method expression * * @param p_expression * @param returnType * @param parameterTypes * @return */ public static MethodExpression createMethodExpression(String p_expression, Class<?> returnType, Class<?>... parameterTypes) { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); MethodExpression mex = expressionFactory.createMethodExpression(elContext, p_expression, returnType, parameterTypes); return mex; }
Example 10
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Evaluates an EL expression into an object. * * @param p_expression * the expression * @throws PropertyNotFoundException * if the attribute doesn't exist at all (as opposed to being null) * @return the object */ public static Object evalAsObject(String p_expression) throws PropertyNotFoundException { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, Object.class); Object result = vex.getValue(elContext); return result; }
Example 11
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Evaluates an EL expression into a string. * * @param p_expression * the el expression * @return the value */ public static String evalAsString(String p_expression) { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, String.class); String result = (String) vex.getValue(elContext); return result; }
Example 12
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Yields the type of the variable displayed by a component. * * @param p_component * the UIComponent * @return the type (as class) */ public static Class<?> getType(UIComponent p_component) { ValueExpression valueExpression = p_component.getValueExpression("value"); if (valueExpression != null) { FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); return valueExpression.getType(elContext); } return null; }
Example 13
Source File: ELTools.java From BootsFaces-OSP with Apache License 2.0 | 5 votes |
/** * Which annotations are given to an object described by an EL expression? * * @param p_expression * EL expression of the JSF bean attribute * @return null if there are no annotations, or if they cannot be accessed */ public static Annotation[] readAnnotations(ValueExpression p_expression, UIComponent p_component) { FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); try { ValueReference valueReference = p_expression.getValueReference(elContext); Object base; if (null == valueReference) { base = evaluteBaseForMojarra(elContext, p_expression); } else { base = valueReference.getBase(); } if (null == base) { return null; } Field declaredField = getField(base, p_expression.getExpressionString()); if (null != declaredField) { return declaredField.getAnnotations(); } Method getter = getGetter(base, p_expression.getExpressionString()); if (null != getter) { return getter.getAnnotations(); } } catch (PropertyNotFoundException ex) { // this happens if a bean is null. That's a legal state, so suffice it to return no annotation. } return null; }
Example 14
Source File: SpecialtyConverter.java From javaee7-petclinic with GNU General Public License v2.0 | 5 votes |
private VetController getCapitalsParser(FacesContext facesContext) { if (vetController == null) { ELContext elContext = facesContext.getELContext(); vetController = (VetController) elContext.getELResolver().getValue(elContext, null, "vetController"); } return vetController; }
Example 15
Source File: AJAXBroadcastComponent.java From BootsFaces-OSP with Apache License 2.0 | 3 votes |
/** * Evaluates an EL expression into an object. * * @param p_expression * the expression * @throws PropertyNotFoundException * if the attribute doesn't exist at all (as opposed to being * null) * @return the object */ public static ValueExpression evalAsValueExpression(String p_expression) throws PropertyNotFoundException { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); ValueExpression vex = expressionFactory.createValueExpression(elContext, p_expression, Object.class); return vex; }
Example 16
Source File: AJAXBroadcastComponent.java From BootsFaces-OSP with Apache License 2.0 | 3 votes |
/** * Evaluates an EL expression into an object. * * @param p_expression * the expression * @throws PropertyNotFoundException * if the attribute doesn't exist at all (as opposed to being * null) * @return the object */ public static MethodExpression evalAsMethodExpression(String p_expression) throws PropertyNotFoundException { FacesContext context = FacesContext.getCurrentInstance(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ELContext elContext = context.getELContext(); MethodExpression mex = expressionFactory.createMethodExpression(elContext, p_expression, Object.class, new Class[0]); return mex; }