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; }
/** * Resolves the search expression, starting from the viewroot, and focus the resolved component. * * @param expression The search expression. */ public void focus(String expression) { focus(expression, FacesContext.getCurrentInstance().getViewRoot()); }
public static List<String> getAutoUpdateComponentClientIds(FacesContext context) { return (List<String>) context.getViewRoot().getAttributes().get(COMPONENT_CLIENT_IDS); }
public DataListState getDataListState(boolean create) { FacesContext fc = getFacesContext(); Map<String, Object> sessionMap = fc.getExternalContext().getSessionMap(); Map<String, DataListState> dlState = (Map) sessionMap.get(Constants.DATALIST_STATE); String viewId = fc.getViewRoot().getViewId().replaceFirst("^/*", ""); String stateKey = viewId + "_" + getClientId(fc); if (dlState == null) { dlState = new HashMap<>(); sessionMap.put(Constants.DATALIST_STATE, dlState); } DataListState ls = dlState.get(stateKey); if (ls == null && create) { ls = new DataListState(); dlState.put(stateKey, ls); } return ls; }
@SuppressWarnings("unchecked") private static Map<String, Boolean> getInitializedWebsockets(FacesContext context) { Map<String, Object> viewScope = context.getViewRoot().getViewMap(); Map<String, Boolean> initializedWebsockets = (Map<String, Boolean>) viewScope.get(WebsocketFacesListener.class.getName()); if (initializedWebsockets == null) { initializedWebsockets = new HashMap<>(); viewScope.put(WebsocketFacesListener.class.getName(), initializedWebsockets); } return initializedWebsockets; }
public String getAsString(final FacesContext context, final UIComponent comp, final Object value) { if (value instanceof Date) { PrettyTime prettyTime; // Use locale of current viewer. Locale locale = context.getViewRoot().getLocale(); synchronized (PRETTY_TIME_LOCALE_MAP) { prettyTime = PRETTY_TIME_LOCALE_MAP.get(locale); if (prettyTime == null) { prettyTime = new PrettyTime(locale); PRETTY_TIME_LOCALE_MAP.put(locale, prettyTime); } } return prettyTime.format((Date) value); } throw new ConverterException("May only be used to convert java.util.Date objects. Got: " + (value != null ? value.getClass() : "null")); } }
private void saveFacesView(FacesContext context) { // first save any current Faces messages in the viewRoot saveFacesMessageState(context); // now place the viewRoot in the request scope Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); requestMap.put(FACES_VIEWROOT, context.getViewRoot()); }
FacesContext context = FacesContext.getCurrentInstance(); PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context); try { UIViewRoot viewRoot = context.getViewRoot(); if (viewRoot != null) { params.put("parameterPrefix", parameterPrefix); encodeCallbackParams(params);
public static List<String> getOrCreateAutoUpdateComponentClientIds(FacesContext context) { List<String> clientIds = getAutoUpdateComponentClientIds(context); if (clientIds == null) { clientIds = new ArrayList<>(); context.getViewRoot().getAttributes().put(COMPONENT_CLIENT_IDS, clientIds); } return clientIds; }
/** * Gets the current thread-safe TimelineUpdater instance by Id. * * @param id Id of the Timeline component in terms of findComponent() * @return TimelineUpdater instance. * @throws FacesException if the Timeline component can not be found by the given Id */ public static TimelineUpdater getCurrentInstance(String id) { FacesContext fc = FacesContext.getCurrentInstance(); @SuppressWarnings("unchecked") Map<String, TimelineUpdater> map = (Map<String, TimelineUpdater>) fc.getAttributes().get(TimelineUpdater.class.getName()); if (map == null) { return null; } UIComponent timeline = fc.getViewRoot().findComponent(id); if (timeline == null || !(timeline instanceof Timeline)) { throw new FacesException("Timeline component with Id " + id + " was not found"); } TimelineUpdater timelineUpdater = map.get(((Timeline) timeline).resolveWidgetVar()); if (timelineUpdater != null) { timelineUpdater.id = id; } return timelineUpdater; }
Object resetValuesObject = context.getExternalContext().getRequestParameterMap().get(Constants.RequestParams.RESET_VALUES_PARAM); boolean resetValues = (null != resetValuesObject && "true".equals(resetValuesObject)); context.getViewRoot().visitTree(visitContext, ResetInputVisitCallback.INSTANCE); context.getViewRoot().invokeOnComponent(context, renderId, contextCallback);
boolean vertical = tree.getOrientation().equals("vertical"); String clientId = tree.getClientId(context); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String rowKey = params.get(clientId + "_expandNode"); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); String filteredValue = params.get(clientId + "_filter"); Locale filterLocale = context.getViewRoot().getLocale();
private void updateBundle() { String newBaseName = getBasename(); FacesContext context = getFacesContext(); Locale currentLocale = context.getViewRoot().getLocale(); boolean reloadRequired = oldLocale == null || !oldLocale.getLanguage().equals(currentLocale.getLanguage()) || !oldBaseName.equals(newBaseName); if (reloadRequired) { bundle = ResourceBundle.getBundle(newBaseName.trim(), currentLocale, MessageUtils.getClassLoader(this)); map = new SerializableMap(); context.getExternalContext().getRequestMap().put(getVar(), map); oldBaseName = newBaseName; oldLocale = currentLocale; } }
@Test public void processEvent() { PreDestroyViewMapEvent event = mock(PreDestroyViewMapEvent.class); UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot(); when(event.getSource()).thenReturn(viewRoot); this.viewScope.getPreDestroyViewMapListener().processEvent(event); }
protected String getValueWithTimeZone(FacesContext context, Clock clock) { Locale locale = context.getViewRoot().getLocale(); String value = ""; if (locale != null) { DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", locale); dateFormat.setTimeZone(CalendarUtils.calculateTimeZone(clock.getTimeZone())); value = dateFormat.format(new Date()); } return value; } }
public TableState getTableState(boolean create) { FacesContext fc = getFacesContext(); Map<String, Object> sessionMap = fc.getExternalContext().getSessionMap(); Map<String, TableState> dtState = (Map) sessionMap.get(Constants.TABLE_STATE); String viewId = fc.getViewRoot().getViewId().replaceFirst("^/*", ""); String stateKey = viewId + "_" + getClientId(fc); if (dtState == null) { dtState = new HashMap<>(); sessionMap.put(Constants.TABLE_STATE, dtState); } TableState ts = dtState.get(stateKey); if (ts == null && create) { ts = new TableState(); dtState.put(stateKey, ts); } return ts; }
public static Map getMarkerMap(FacesContext facesContext) { Map viewMap = facesContext.getViewRoot().getViewMap(); Map markerMap = (Map) viewMap.get(MARKER_MAP); if (null == markerMap) { markerMap = new HashMap(); viewMap.put(MARKER_MAP, markerMap); } return markerMap; }
public void decode(FacesContext context) { super.decode(context); //To change body of overridden methods use File | Settings | File Templates. //Save the current view root for later reference... context.getExternalContext().getRequestMap().put(PREVIOUS_VIEW_ROOT, context.getViewRoot()); //...and remember that this instance needs NO special treatment on rendering: _itemOpenActiveStatesRestored = true; }
/** * @param key */ public void setKey(String key) { FacesContext context = FacesContext.getCurrentInstance(); Map<String, Object> attributes = context.getViewRoot().getAttributes(); attributes.put("propertyKey", key); }
/** * Finds the proper {@link AjaxExceptionHandler} for the given {@link Throwable}. * * @param context The {@link FacesContext}. * @param rootCause The occurred {@link Throwable}. * @return The {@link AjaxExceptionHandler} or <code>null</code>. */ protected AjaxExceptionHandler findHandlerComponent(FacesContext context, Throwable rootCause) { AjaxExceptionHandlerVisitCallback visitCallback = new AjaxExceptionHandlerVisitCallback(rootCause); context.getViewRoot().visitTree(VisitContext.createVisitContext(context), visitCallback); Map<String, AjaxExceptionHandler> handlers = visitCallback.getHandlers(); // get handler by exception type AjaxExceptionHandler handler = handlers.get(rootCause.getClass().getName()); // lookup by inheritance hierarchy if (handler == null) { Class throwableClass = rootCause.getClass(); while (handler == null && throwableClass.getSuperclass() != Object.class) { throwableClass = throwableClass.getSuperclass(); handler = handlers.get(throwableClass.getName()); } } // get default handler if (handler == null) { handler = handlers.get(null); } return handler; }