private String getMessage(String format) { FacesContext facesContext = FacesContext.getCurrentInstance(); String viewId = facesContext.getViewRoot().getViewId(); UIComponent component = UIComponent.getCurrentComponent(facesContext); String clientId = component == null ? "<unknown>" : component.getClientId(facesContext); return String.format(format, getClass().getName(), clientId, viewId); }
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; } }
protected void encodeCaption(FacesContext context, UIComponent caption) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("div", null); writer.writeAttribute("class", PickList.CAPTION_CLASS, null); caption.encodeAll(context); writer.endElement("div"); }
@Override public ExternalContext getObject() { return FacesContext.getCurrentInstance().getExternalContext(); } @Override
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; }
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context); ProjectStage projectStage = context.getApplication().getProjectStage(); boolean csvEnabled = applicationContext.getConfig().isClientSideValidationEnabled(); writer.startElement("head", component); writer.writeAttribute("id", component.getClientId(context), "id"); UIComponent first = component.getFacet("first"); if (first != null) { first.encodeAll(context); ELContext elContext = context.getELContext(); ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory(); ValueExpression ve = expressionFactory.createValueExpression(elContext, themeParamValue, String.class); theme = (String) ve.getValue(elContext); UIViewRoot viewRoot = context.getViewRoot(); List<UIComponent> resources = viewRoot.getComponentResources(context, "head"); for (int i = 0; i < resources.size(); i++) { UIComponent resource = resources.get(i); writer.write("PrimeFaces.settings.locale='" + context.getViewRoot().getLocale() + "';");
@Override public Object resolveReference(String key) { if (REFERENCE_REQUEST.equals(key)) { return getExternalContext().getRequest(); return getExternalContext().getSession(true); return getExternalContext().getContext(); return getFacesContext().getViewRoot(); return getFacesContext().getViewRoot().getViewMap(); return getFacesContext().getApplication().getResourceHandler();
public int compare(Object obj1, Object obj2) { try { FacesContext context = FacesContext.getCurrentInstance(); context.getExternalContext().getRequestMap().put(var, ((TreeNode) obj1).getData()); Object value1 = sortBy.getValue(context.getELContext()); context.getExternalContext().getRequestMap().put(var, ((TreeNode) obj2).getData()); Object value2 = sortBy.getValue(context.getELContext()); result = (Integer) sortFunction.invoke(context.getELContext(), new Object[]{value1, value2}); throw new FacesException(e);
@Override public void processAction(ActionEvent actionEvent) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); StreamedContent content = (StreamedContent) value.getValue(elContext); ExternalContext externalContext = context.getExternalContext(); String contentDispositionValue = contentDisposition != null ? (String) contentDisposition.getValue(elContext) : "attachment"; String monitorKeyValue = monitorKey != null ? "_" + (String) monitorKey.getValue(elContext) : ""; externalContext.setResponseContentType(content.getContentType()); externalContext.setResponseHeader("Content-Disposition", ComponentUtils.createContentDisposition(contentDispositionValue, content.getName())); externalContext.addResponseCookie(Constants.DOWNLOAD_COOKIE + monitorKeyValue, "true", Collections.<String, Object>emptyMap()); externalContext.responseFlushBuffer(); context.responseComplete(); throw new FacesException(e);
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) { context.getELContext(), component.getValueExpression("value")); String expressionString = expression.getExpressionString(); String resourceKey = md5(expressionString); .append("&").append(Constants.DYNAMIC_CONTENT_TYPE_PARAM).append("=").append(type.toString()); for (int i = 0; i < component.getChildCount(); i++) { UIComponent child = component.getChildren().get(i); if (child instanceof UIParameter) { UIParameter param = (UIParameter) child; return context.getExternalContext().encodeResourceURL(src);
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 event) { FacesContext context = FacesContext.getCurrentInstance(); ELContext elContext = context.getELContext(); String tables = (String) target.getValue(elContext); String exportAs = (String) type.getValue(elContext); String outputFileName = (String) fileName.getValue(elContext); if (repeat != null) { repeating = repeat.isLiteralText() ? Boolean.parseBoolean(repeat.getValue(context.getELContext()).toString()) : (Boolean) repeat.getValue(context.getELContext()); if (pageOnly != null) { isPageOnly = pageOnly.isLiteralText() ? Boolean.parseBoolean(pageOnly.getValue(context.getELContext()).toString()) : (Boolean) pageOnly.getValue(context.getELContext()); if (selectionOnly != null) { isSelectionOnly = selectionOnly.isLiteralText() ? Boolean.parseBoolean(selectionOnly.getValue(context.getELContext()).toString()) : (Boolean) selectionOnly.getValue(context.getELContext()); context.responseComplete(); throw new FacesException(e);
protected void encodeCSS(FacesContext context, String library, String resource) throws IOException { ResponseWriter writer = context.getResponseWriter(); Resource cssResource = context.getApplication().getResourceHandler().createResource(resource, library); if (cssResource == null) { throw new FacesException("Error loading css, cannot find \"" + resource + "\" resource of \"" + library + "\" library"); } else { writer.startElement("link", null); writer.writeAttribute("type", "text/css", null); writer.writeAttribute("rel", "stylesheet", null); writer.writeAttribute("href", cssResource.getRequestPath(), null); writer.endElement("link"); } }
public static void includeCompositeComponent(UIComponent parent, String taglibURI, String tagName, String id) { FacesContext context = FacesContext.getCurrentInstance(); UIComponent composite = context.getApplication().getViewHandler() .getViewDeclarationLanguage(context, context.getViewRoot().getViewId()) .createComponent(context, taglibURI, tagName, null); composite.setId(id); parent.getChildren().add(composite); }
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); }
@Override public void handle(FacesContext context) throws IOException { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); ExternalContext externalContext = context.getExternalContext(); String sessionKey = params.get(Constants.DYNAMIC_CONTENT_PARAM); Map<String, Object> session = externalContext.getSessionMap(); Map<String, String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING); String value = barcodeMapping.get(sessionKey); if (value != null) { boolean cache = Boolean.parseBoolean(params.get(Constants.DYNAMIC_CONTENT_CACHE_PARAM)); externalContext.setResponseStatus(200); externalContext.setResponseContentType("image/png"); handleCache(externalContext, cache); ErrorCorrectionLevel ecl = ErrorCorrectionLevel.L; String errorCorrection = params.get("qrec"); if (!LangUtils.isValueBlank(errorCorrection)) { ecl = ErrorCorrectionLevel.valueOf(errorCorrection); } QRCode.from(value).to(ImageType.PNG).withErrorCorrection(ecl).withCharset("UTF-8") .writeTo(externalContext.getResponseOutputStream()); externalContext.responseFlushBuffer(); context.responseComplete(); } }
public static NavigationCase findNavigationCase(FacesContext context, String outcome) { ConfigurableNavigationHandler navHandler = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler(); String outcomeValue = (outcome == null) ? context.getViewRoot().getViewId() : outcome; return navHandler.getNavigationCase(context, null, outcomeValue); }
public static boolean isRequestSource(UIComponent component, FacesContext context) { return component.getClientId(context).equals(context.getExternalContext().getRequestParameterMap().get(Constants.RequestParams.PARTIAL_SOURCE_PARAM)); }
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; } }
protected void handleRedirect(FacesContext context, Throwable rootCause, ExceptionInfo info, boolean responseResetted) throws IOException { ExternalContext externalContext = context.getExternalContext(); externalContext.getSessionMap().put(ExceptionInfo.ATTRIBUTE_NAME, info); String url = externalContext.getRequestContextPath() + errorPage; if (responseResetted && context.getPartialViewContext().isAjaxRequest()) { PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter(); externalContext.addResponseHeader("Content-Type", "text/xml; charset=" + externalContext.getResponseCharacterEncoding()); externalContext.addResponseHeader("Cache-Control", "no-cache"); externalContext.setResponseContentType("text/xml"); if (externalContext.isResponseCommitted() && !context.getPartialViewContext().isAjaxRequest()) { PartialResponseWriter writer = context.getPartialViewContext().getPartialResponseWriter(); writer.startElement("script", null); writer.write("window.location.href = '" + url + "';"); writer.endElement("script"); writer.getWrapped().endDocument(); context.responseComplete();