protected static Locale getLocale() { Locale locale = null; FacesContext facesContext = FacesContext.getCurrentInstance(); if (facesContext != null && facesContext.getViewRoot() != null) { locale = facesContext.getViewRoot().getLocale(); if (locale == null) { locale = Locale.getDefault(); } } else { locale = Locale.getDefault(); } return locale; }
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); }
@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();
@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.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); 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("if(window.PrimeFaces){"); writer.write("PrimeFaces.settings.locale='" + context.getViewRoot().getLocale() + "';");
public static Locale getCurrentLocale(FacesContext context) { UIViewRoot viewRoot = context.getViewRoot(); Locale locale; if (null == viewRoot) { locale = Locale.getDefault(); } else { locale = viewRoot.getLocale(); } return locale; }
/** * This template method called from the {@link #setupFacesRequest()} to create components view tree in the virtual request. * The default implementation is only creates {@link UIViewRoot} instance for view ID "/test.xhtml". * @return */ protected UIViewRoot setupView() { UIViewRoot viewRoot = (UIViewRoot) application.createComponent(UIViewRoot.COMPONENT_TYPE); viewRoot.setViewId("/test.xhtml"); viewRoot.setLocale(Locale.getDefault()); viewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT); return viewRoot; }
@Override public UIViewRoot getViewRoot() { if (viewRoot == null) { viewRoot = new UIViewRoot(); viewRoot.setLocale(Locale.getDefault()); viewRoot.setViewId(FACES_PREFIX + "xhtml"); } return viewRoot; }
public void setLocaleCode(String localeCode) { Iterator<Locale> locales = FacesContext.getCurrentInstance().getApplication().getSupportedLocales(); while (locales.hasNext()) { Locale locale = locales.next(); if (!Strings.isEmpty(locale.getLanguage()) && locale.getLanguage().equals(localeCode)) { this.localeCode = localeCode; FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(localeCode)); setCookieValue(localeCode); break; } } }
private static String getAction(FacesContext facesContext) { String viewId = facesContext.getViewRoot().getViewId(); String actionURL = facesContext.getApplication().getViewHandler(). getActionURL(facesContext, viewId); return (facesContext.getExternalContext().encodeActionURL(actionURL)); } }
protected void encodeScript(FacesContext context, Clock clock) throws IOException { String clientId = clock.getClientId(context); String mode = clock.getMode(); WidgetBuilder wb = getWidgetBuilder(context); wb.init("Clock", clock.resolveWidgetVar(), clientId); wb.attr("mode", mode) .attr("pattern", clock.getPattern(), null) .attr("displayMode", clock.getDisplayMode()) .attr("locale", context.getViewRoot().getLocale().toString()); if (mode.equals("server")) { wb.attr("value", getValueWithTimeZone(context, clock)); if (clock.isAutoSync()) { wb.attr("autoSync", true).attr("syncInterval", clock.getSyncInterval()); } } wb.finish(); }
@Override protected boolean isSandboxed(FacesContext facesContext, UIComponent uiComponent) { // In order to support the "lang" attribute of the YUI object, it is necessary to determine if the user has // specified a locale other than that of the server or view root. If so, then the javascript must be rendered // inline. InputDateTime inputDateTime = (InputDateTime) uiComponent; Locale locale = inputDateTime.getObjectAsLocale(inputDateTime.getLocale(facesContext)); UIViewRoot viewRoot = facesContext.getViewRoot(); Locale viewRootLocale = viewRoot.getLocale(); return !locale.equals(viewRootLocale); }
/** * @param facesContext * @return String A String representing the action URL */ protected String getActionUrl(FacesContext facesContext) { ViewHandler viewHandler = facesContext.getApplication().getViewHandler(); String viewId = facesContext.getViewRoot().getViewId(); return viewHandler.getActionURL(facesContext, viewId); }
@Override public void removeChildrenFromComponentTree(FacesContext facesContext, String clientId) { UIComponent uiComponent = facesContext.getViewRoot().findComponent(clientId); if (uiComponent != null) { uiComponent.getChildren().clear(); uiComponent.getFacets().clear(); } }
@Override public void resetView(FacesContext facesContext, boolean renderResponse) { Application application = facesContext.getApplication(); ViewHandler viewHandler = application.getViewHandler(); UIViewRoot viewRoot = facesContext.getViewRoot(); UIViewRoot emptyView = viewHandler.createView(facesContext, viewRoot.getViewId()); facesContext.setViewRoot(emptyView); if (renderResponse) { facesContext.renderResponse(); } }
private void addQueueResourceComponent(FacesContext context) { List<UIComponent> resources = context.getViewRoot().getComponentResources(context, QUEUE_RESOURCE_COMPONENT_TARGET); for (UIComponent resource : resources) { if (QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE.equals(resource.getRendererType())) { return; } } Application application = context.getApplication(); UIComponent queueResourceComponent = application.createComponent(context, UIOutput.COMPONENT_TYPE, QUEUE_RESOURCE_COMPONENT_RENDERER_TYPE); // fix for JSF duplicate ID exception queueResourceComponent.setId(QueueRegistry.QUEUE_SCRIPT_ID); context.getViewRoot().addComponentResource(context, queueResourceComponent, QUEUE_RESOURCE_COMPONENT_TARGET); }
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); }
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); }
FacesContext context = FacesContext.getCurrentInstance(); String viewId = context.getViewRoot().getViewId(); ViewHandler handler = context.getApplication().getViewHandler(); UIViewRoot root = handler.createView(context, viewId); root.setViewId(viewId); context.setViewRoot(root);
private String getCalculatedDecimalSepartor() { String decimalSeparator = (String) getStateHelper().eval("decimalSeparator", null); if (decimalSeparator == null) { Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale); decimalSeparator = Character.toString(decimalFormatSymbols.getDecimalSeparator()); } return decimalSeparator; }