protected Object coerceToModelType(FacesContext ctx, Object value, Class itemValueType) { Object newValue; try { ExpressionFactory ef = ctx.getApplication().getExpressionFactory(); newValue = ef.coerceToType(value, itemValueType); } catch (ELException | IllegalArgumentException ele) { newValue = value; } return newValue; }
public boolean isRTL() { if (rtl == null) { String param = context.getExternalContext().getInitParameter(Constants.ContextParams.DIRECTION); if (param == null) { rtl = false; } else { ELContext elContext = context.getELContext(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ValueExpression expression = expressionFactory.createValueExpression(elContext, param, String.class); String expressionValue = (String) expression.getValue(elContext); rtl = (expressionValue == null) ? false : expressionValue.equalsIgnoreCase("rtl"); } } return rtl; } }
private String createPostParameters(FacesContext context, Object value) throws UnsupportedEncodingException { String privateKey = context.getApplication().evaluateExpressionGet(context, context.getExternalContext().getInitParameter(Captcha.PRIVATE_KEY), String.class); if (privateKey == null) { throw new FacesException("Cannot find private key for catpcha, use primefaces.PRIVATE_CAPTCHA_KEY context-param to define one"); } StringBuilder postParams = new StringBuilder(); postParams.append("secret=").append(URLEncoder.encode(privateKey, "UTF-8")); postParams.append("&response=").append(value == null ? "" : URLEncoder.encode((String) value, "UTF-8")); String params = postParams.toString(); postParams.setLength(0); return params; } }
public static void addComponentResource(FacesContext context, String name, String library, String target) { Application application = context.getApplication(); UIComponent componentResource = application.createComponent(UIOutput.COMPONENT_TYPE); componentResource.setRendererType(application.getResourceHandler().getRendererTypeForResourceName(name)); componentResource.getAttributes().put("name", name); componentResource.getAttributes().put("library", library); componentResource.getAttributes().put("target", target); context.getViewRoot().addComponentResource(context, componentResource, target); }
protected ResourceBundle getFacesResourceBundle(Locale locale) { ResourceBundle facesResourceBundle = facesResourceBundleMap.get(locale); if (facesResourceBundle == null) { String messageBundle = FacesContext.getCurrentInstance().getApplication().getMessageBundle(); if (messageBundle == null) { messageBundle = FacesMessage.FACES_MESSAGES; } facesResourceBundle = ResourceBundle.getBundle(messageBundle, locale); facesResourceBundleMap.put(locale, facesResourceBundle); } return facesResourceBundle; }
Resource resource = context.getApplication().getResourceHandler().createResource("dynamiccontent.properties", "primefaces", "image/png"); String resourcePath = resource.getRequestPath(); Map<String, Object> session = context.getExternalContext().getSessionMap(); Map<String, String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING); if (barcodeMapping == null) { barcodeMapping = new HashMap<>(); session.put(Constants.BARCODE_MAPPING, barcodeMapping); barcodeMapping.put(sessionKey, (String) value); StringBuilder builder = SharedStringBuilder.get(context, SB_BUILD); writer.writeAttribute("src", context.getExternalContext().encodeResourceURL(src), null);
Resource resource = context.getApplication().getResourceHandler().createResource( "dynamiccontent.properties", "primefaces", streamedContent.getContentType()); String resourcePath = resource.getRequestPath(); Map<String, Object> session = context.getExternalContext().getSessionMap(); Map<String, String> dynamicResourcesMapping = (Map) session.get(Constants.DYNAMIC_RESOURCES_MAPPING); if (dynamicResourcesMapping == null) { dynamicResourcesMapping = new LimitedSizeHashMap<>(200); session.put(Constants.DYNAMIC_RESOURCES_MAPPING, dynamicResourcesMapping); context.getELContext(), component.getValueExpression("value")); dynamicResourcesMapping.put(resourceKey, expressionString); return context.getExternalContext().encodeResourceURL(src);
public void processAction(ActionEvent evt) throws AbortProcessingException { FacesContext faces = FacesContext.getCurrentInstance(); ELContext el = faces.getELContext(); Object valueObj = this.value.getValue(el); if (valueObj != null) { ExpressionFactory factory = faces.getApplication().getExpressionFactory(); valueObj = factory.coerceToType(valueObj, target.getType(el)); } this.target.setValue(el, valueObj); }
public static Object coerce(Object value, Class<?> toType) { FacesContext context = FacesContext.getCurrentInstance(); return context.getApplication().getExpressionFactory().coerceToType(value, toType); }
public static void addSearchKeywordResolvers() { FacesContext.getCurrentInstance() .getApplication() .addSearchKeywordResolver(new Jsf23WidgetVarSearchKeywordResolver()); } }
protected Converter findImplicitConverter(FacesContext context, UIComponent component) { ValueExpression ve = component.getValueExpression("value"); if (ve != null) { Class<?> valueType = ve.getType(context.getELContext()); if (valueType != null) { if (valueType.isArray()) { valueType = valueType.getComponentType(); } return context.getApplication().createConverter(valueType); } } return null; }
protected String baseUrlForContent(String baseName, String extension) { if (useExtensions) { return baseName + "." + extension; } else { FacesContext context = FacesContext.getCurrentInstance(); ViewHandler handler = context.getApplication().getViewHandler(); String url = handler.getActionURL(context, DOCSTORE_BASE_URL + Faces.getDefaultSuffix(context)); return context.getExternalContext().encodeActionURL(url); } }
if (event instanceof MenuActionEvent) { FacesContext facesContext = getFacesContext(); ELContext eLContext = facesContext.getELContext(); MenuActionEvent menuActionEvent = (MenuActionEvent) event; MenuItem menuItem = menuActionEvent.getMenuItem(); MethodExpression noArgExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[0]); MethodExpression argExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[]{ActionEvent.class}); MethodExpression argExpr = facesContext.getApplication().getExpressionFactory(). createMethodExpression(eLContext, actionExpressionString, String.class, new Class[]{MenuActionEvent.class}); String outcome = (invokeResult != null) ? invokeResult.toString() : null; facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, actionExpressionString, outcome);
private void processCustomArgListener(FacesContext context, ELContext elContext, AjaxBehaviorEvent event) throws AbortProcessingException { if (listenerWithCustomArg == null) { MethodExpression argListener = context.getApplication().getExpressionFactory(). createMethodExpression(elContext, listener.getExpressionString(), Void.class, new Class[]{event.getClass()}); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke customListener: " + argListener.getExpressionString()); } argListener.invoke(elContext, new Object[]{event}); } else { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Try to invoke customListener: " + listenerWithCustomArg.getExpressionString()); } listenerWithCustomArg.invoke(elContext, new Object[]{event}); } } }
public ResourceComponent(FacesContext facesContext, String resourceName, String resourceLibrary, String target) { ResourceHandler resourceHandler = facesContext.getApplication().getResourceHandler(); setRendererType(resourceHandler.getRendererTypeForResourceName(resourceName)); Map<String, Object> attributes = this.getAttributes(); attributes.put("name", resourceName); attributes.put("library", resourceLibrary); attributes.put("target", target); } }
protected ResourceBundle getFacesResourceBundle(Locale locale) { ResourceBundle facesResourceBundle = facesResourceBundleMap.get(locale); if (facesResourceBundle == null) { String messageBundle = FacesContext.getCurrentInstance().getApplication().getMessageBundle(); if (messageBundle == null) { messageBundle = FacesMessage.FACES_MESSAGES; } facesResourceBundle = ResourceBundle.getBundle(messageBundle, locale); facesResourceBundleMap.put(locale, facesResourceBundle); } return facesResourceBundle; }
protected void setupConversationSystem(FacesContext context) { if (Boolean.TRUE.equals(context.getExternalContext().getApplicationMap().get(CONVERSATION_SYSTEM_SETUP))) { return; } VariableResolver originalVR = context.getApplication().getVariableResolver(); context.getApplication().setVariableResolver(new ConversationVariableResolver(originalVR)); context.getExternalContext().getApplicationMap().put(CONVERSATION_SYSTEM_SETUP, Boolean.TRUE); }
public String resolveDynamicField(ValueExpression expression) { if (expression == null) { return null; } FacesContext context = getFacesContext(); ELContext elContext = context.getELContext(); String expressionString = expression.getExpressionString(); // old syntax compatibility // #{car[column.property]} // new syntax is: // #{column.property} or even a method call if (expressionString.startsWith("#{" + getVar() + "[")) { expressionString = expressionString.substring(expressionString.indexOf("[") + 1, expressionString.indexOf("]")); expressionString = "#{" + expressionString + "}"; ValueExpression dynaVE = context.getApplication() .getExpressionFactory().createValueExpression(elContext, expressionString, String.class); return (String) dynaVE.getValue(elContext); } return (String) expression.getValue(elContext); }
@Override public void processAction(ActionEvent evt) throws AbortProcessingException { FacesContext faces = FacesContext.getCurrentInstance(); ELContext el = faces.getELContext(); Object valueObj = this.value.getValue(el); if (valueObj != null) { ExpressionFactory factory = faces.getApplication().getExpressionFactory(); valueObj = factory.coerceToType(valueObj, target.getType(el)); } this.target.setValue(el, valueObj); }
protected String getPublicKey(FacesContext context, Captcha captcha) { return context.getApplication().evaluateExpressionGet(context, context.getExternalContext().getInitParameter(Captcha.PUBLIC_KEY), String.class); } }