public static final String getValue(FacesContext context, UICalendar calendar, Object value, String pattern) { //first ask the converter if (calendar.getConverter() != null) { return calendar.getConverter().getAsString(context, calendar, value); } else if (value instanceof String) { return (String) value; } //Use built-in converter else if (value instanceof Date) { SimpleDateFormat format = new SimpleDateFormat(pattern, calendar.calculateLocale(context)); format.setTimeZone(calculateTimeZone(calendar.getTimeZone())); return format.format((Date) value); } else { //Delegate to global defined converter (e.g. joda or java8) ValueExpression ve = calendar.getValueExpression("value"); if (ve != null) { Class type = ve.getType(context.getELContext()); if (type != null && type != Object.class && type != Date.class) { Converter converter = context.getApplication().createConverter(type); if (converter != null) { return converter.getAsString(context, calendar, value); } } } throw new FacesException("Value could be either String or java.util.Date"); } }
Application app = context.getApplication(); ViewDeclarationLanguage vdl = app.getViewHandler().getViewDeclarationLanguage(context, context.getViewRoot().getViewId()); BeanInfo componentMetadata = vdl.getComponentMetadata(context, componentResource); String componentType = (String) valueExpression.getValue(context.getELContext()); if (!isEmpty(componentType)) { result = app.createComponent(componentType); throw new FacesException(ie); result = app.createComponent("javax.faces.NamingContainer"); result.setRendererType("javax.faces.Composite"); Map<String, Object> attrs = result.getAttributes(); attrs.put(COMPONENT_RESOURCE_KEY, componentResource); attrs.put(BEANINFO_KEY, componentMetadata);
@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()); throw new FacesException(e);
public int compare(Object obj1, Object obj2) { try { FacesContext context = FacesContext.getCurrentInstance(); context.getExternalContext().getRequestMap().put(var, obj1); Object value1 = sortBy.getValue(context.getELContext()); context.getExternalContext().getRequestMap().put(var, obj2); Object value2 = sortBy.getValue(context.getELContext()); throw new FacesException(e);
event.getComponent().getId())); FacesContext context = FacesContext.getCurrentInstance(); Application application = context.getApplication(); LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new FacesException (binding.getExpressionString() + ": " + e.getMessage(), e); LOGGER.log(Level.SEVERE, e.getMessage(), e); throw new FacesException (binding.getExpressionString() + ": " + e.getMessage(), e); NavigationHandler navHandler = application.getNavigationHandler(); context.renderResponse();
/** * If page >= 1 then it's a page number to show */ @Attribute public int getPage() { UIComponent dataTable = getDataTable(); Map<String, Object> attributes = dataTable.getAttributes(); FacesContext facesContext = getFacesContext(); Integer state = (Integer) attributes.get(dataTable.getClientId(facesContext) + SCROLLER_STATE_ATTRIBUTE); if (state != null) { return state; } if (this.page != null) { return page; } ValueExpression ve = getValueExpression("page"); if (ve != null) { try { Integer pageObject = (Integer) ve.getValue(getFacesContext().getELContext()); if (pageObject != null) { return pageObject; } } catch (ELException e) { throw new FacesException(e); } } return 1; }
@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()); UIComponent component = (UIComponent) components.get(0); if (!(component instanceof DataTable)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable."); throw new FacesException(e);
if (renderKitId.isLiteralText()) { viewRoot.setRenderKitId(renderKitId.getValue(elContext).toString()); } else { context.getApplication().getDefaultRenderKitId(); if (null == renderKitIdString) { renderKitIdString = RenderKitFactory.HTML_BASIC_RENDER_KIT; if (locale.isLiteralText()) { component.setValueExpression("locale", locale); Object result = locale.getValue(context.getELContext()); if (result instanceof Locale) { if (beforePhase.isLiteralText()) { Object params [] = {beforePhase}; throw new javax.faces.FacesException(MessageUtils.getExceptionMessageString(MessageUtils.INVALID_EXPRESSION_ID, params)); if (afterPhase.isLiteralText()) { Object params [] = {afterPhase}; throw new javax.faces.FacesException(MessageUtils.getExceptionMessageString(MessageUtils.INVALID_EXPRESSION_ID, params)); throw new FacesException(ele);
protected void updateAttribute(FacesContext context, UIComponent component, String attribute, Object value) { Object oldValue = component.getAttributes().get(attribute); if ((oldValue != null && !oldValue.equals(value)) || (oldValue == null && value != null)) { ELContext elContext = context.getELContext(); ValueExpression ve = component.getValueExpression(attribute); if (ve != null && !ve.isReadOnly(elContext)) { component.getAttributes().put(attribute, null); try { ve.setValue(elContext, value); } catch (ELException e) { throw new FacesException(e); } } else { component.getAttributes().put(attribute, value); } } }
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; } }
/** * Lazy init cacheProvider. Not required if no cache component is used in the application. */ protected synchronized void initCacheProvider() { if (cacheProvider == null) { String cacheProviderConfigValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(Constants.ContextParams.CACHE_PROVIDER); if (cacheProviderConfigValue == null) { cacheProvider = new DefaultCacheProvider(); } else { try { cacheProvider = (CacheProvider) LangUtils.loadClassForName(cacheProviderConfigValue).newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) { throw new FacesException(ex); } } } }
String submittedValue = context.getExternalContext().getRequestParameterMap().get(inputId); ValueExpression valueExpression = inputNumber.getValueExpression("value"); if (valueExpression != null) { Class<?> type = valueExpression.getType(context.getELContext()); if (type != null && type.isPrimitive() && !LangUtils.isValueBlank(inputNumber.getMinValue())) { throw new FacesException("Invalid number", ex);
protected Class<? extends SystemEvent> getEventClass(FaceletContext ctx) { String eventType = (String) this.type.getValueExpression(ctx, String.class).getValue(ctx); if (eventType == null) { throw new FacesException("Attribute 'type' can not be null"); } return ApplicationAssociate.getInstance(ctx.getFacesContext().getExternalContext()) .getNamedEventManager().getNamedEvent(eventType); }
public static void includeCompositeComponent(UIComponent parent, String libraryName, String resourceName, String id) { // Prepare. FacesContext context = FacesContext.getCurrentInstance(); Application application = context.getApplication(); FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); // This basically creates <ui:component> based on <composite:interface>. Resource resource = application.getResourceHandler().createResource(resourceName, libraryName); UIComponent composite = application.createComponent(context, resource); composite.setId(id); // Mandatory for the case composite is part of UIForm! Otherwise JSF can't find inputs. // This basically creates <composite:implementation>. UIComponent implementation = application.createComponent(UIPanel.COMPONENT_TYPE); implementation.setRendererType("javax.faces.Group"); composite.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, implementation); // Now include the composite component file in the given parent. parent.getChildren().add(composite); parent.pushComponentToEL(context, composite); // This makes #{cc} available. try { faceletContext.includeFacelet(implementation, resource.getURL()); } catch (IOException e) { throw new FacesException(e); } finally { parent.popComponentFromEL(context); } }
public void processAction(ActionEvent actionEvent) throws AbortProcessingException FacesContext facesContext = FacesContext.getCurrentInstance(); Application application = facesContext.getApplication(); throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); throw new FacesException("Error calling action method of component with id " + actionEvent.getComponent().getClientId(facesContext), e); NavigationHandler navigationHandler = application.getNavigationHandler(); navigationHandler.handleNavigation(facesContext, fromAction, outcome); facesContext.renderResponse();
url = "#".equals(href) ? "#" : context.getExternalContext().encodeRedirectURL(href, outcomeTarget.getParams()); throw new FacesException("Could not resolve NavigationCase for outcome: " + outcomeTarget.getOutcome()); && outcomeTarget.isDisableClientWindow()) { clientWindow = context.getExternalContext().getClientWindow(); url = context.getApplication().getViewHandler().getBookmarkableURL(context, toViewId, params, isIncludeViewParams);
public void setLiteralValue(String name, ValueExpression expression) { assert (expression.isLiteralText()); ELContext context = getFacesContext().getELContext(); try { setLiteralAttribute(name, expression.getValue(context)); } catch (ELException elem) { throw new FacesException(elem); } }
if (converter == null) { Class valueType = value.getClass(); converter = context.getApplication().createConverter(valueType); throw new FacesException("Value of " + component.getClientId(context) + " must be a List or an Array."); return (String) component.getAttributes().get("alt");
if(component!=null) { out.print("<component id=\"" + component.getClientId(context) + "\"><![CDATA["); boolean oldValue = HtmlRendererUtils.isAllowedCdataSection(context); throw new FacesException(e); FacesContext facesContext = FacesContext.getCurrentInstance(); StateManager stateManager = facesContext.getApplication().getStateManager(); StateManager.SerializedView serializedView = stateManager.saveSerializedView(facesContext); throw new FacesException(e);
public static void decode(FacesContext context, FileUpload fileUpload, String inputToDecodeId) { HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); try { if (fileUpload.getMode().equals("simple")) { decodeSimple(context, fileUpload, request, inputToDecodeId); } else { decodeAdvanced(context, fileUpload, request); } } catch (IOException ioe) { throw new FacesException(ioe); } catch (ServletException se) { throw new FacesException(se); } }