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 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 void restoreTransientDescendantComponentStates(FacesContext facesContext, Iterator<UIComponent> childIterator, Map<String, Object> state, boolean restoreChildFacets) { while (childIterator.hasNext()) { UIComponent component = childIterator.next(); // reset the client id (see spec 3.1.6) component.setId(component.getId()); if (!component.isTransient()) { component.restoreTransientState(facesContext, (state == null) ? null : state.get(component.getClientId(facesContext))); Iterator<UIComponent> childsIterator; if (restoreChildFacets) { childsIterator = component.getFacetsAndChildren(); } else { childsIterator = component.getChildren().iterator(); } restoreTransientDescendantComponentStates(facesContext, childsIterator, state, true); } } }
protected boolean visitColumnContent(VisitContext context, VisitCallback callback, UIComponent component) { if (component.getChildCount() > 0) { for (UIComponent grandkid : component.getChildren()) { if (grandkid.visitTree(context, callback)) { return true; } } } return false; }
public static void processDecodesOfFacetsAndChilds(UIComponent component, FacesContext context) { if (component.getFacetCount() > 0) { for (UIComponent facet : component.getFacets().values()) { facet.processDecodes(context); } } if (component.getChildCount() > 0) { for (int i = 0, childCount = component.getChildCount(); i < childCount; i++) { UIComponent child = component.getChildren().get(i); child.processDecodes(context); } } }
public static void processValidatorsOfFacetsAndChilds(UIComponent component, FacesContext context) { if (component.getFacetCount() > 0) { for (UIComponent facet : component.getFacets().values()) { facet.processValidators(context); } } if (component.getChildCount() > 0) { for (int i = 0, childCount = component.getChildCount(); i < childCount; i++) { UIComponent child = component.getChildren().get(i); child.processValidators(context); } } }
protected void encodeContent(FacesContext context, ContentFlow cf) throws IOException { ResponseWriter writer = context.getResponseWriter(); String var = cf.getVar(); writer.startElement("div", null); writer.writeAttribute("class", "flow", null); if (var == null) { for (UIComponent child : cf.getChildren()) { if (child.isRendered()) { writer.startElement("div", null); writer.writeAttribute("class", "item", null); child.encodeAll(context); writer.endElement("div"); } } } else { Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); Collection<?> value = (Collection<?>) cf.getValue(); if (value != null) { for (Iterator<?> it = value.iterator(); it.hasNext(); ) { requestMap.put(var, it.next()); writer.startElement("div", null); writer.writeAttribute("class", "item", null); renderChildren(context, cf); writer.endElement("div"); } } } writer.endElement("div"); }
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); UIComponent middle = component.getFacet("middle"); if (middle != null) { middle.encodeAll(context); UIViewRoot viewRoot = context.getViewRoot(); List<UIComponent> resources = viewRoot.getComponentResources(context, "head"); for (int i = 0; i < resources.size(); i++) { UIComponent resource = resources.get(i); resource.encodeAll(context); writer.startElement("script", null); writer.writeAttribute("type", "text/javascript", null); writer.write("if(window.PrimeFaces){"); writer.write("PrimeFaces.settings.locale='" + context.getViewRoot().getLocale() + "';");
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 void encodeFacet(FacesContext context, UIData data, String facet, String styleClass) throws IOException { ResponseWriter writer = context.getResponseWriter(); UIComponent component = data.getFacet(facet); if (component != null && component.isRendered()) { writer.startElement("div", null); writer.writeAttribute("class", styleClass, null); component.encodeAll(context); writer.endElement("div"); } }
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); }
/** * Create a new UIPanel for the use as a dynamically * created container for multiple children in a facet. * Duplicate in javax.faces.webapp.UIComponentClassicTagBase. * @param facesContext * @return */ private static UIComponent createFacetUIPanel(FacesContext facesContext) { UIComponent panel = facesContext.getApplication().createComponent(UIPanel.COMPONENT_TYPE); panel.setId(facesContext.getViewRoot().createUniqueId()); panel.getAttributes().put(FACET_CREATED_UIPANEL_MARKER, Boolean.TRUE); return panel; }
public static boolean isRequestSource(UIComponent component, FacesContext context) { return component.getClientId(context).equals(context.getExternalContext().getRequestParameterMap().get(Constants.RequestParams.PARTIAL_SOURCE_PARAM)); }
@Override protected UIComponent getPopup(ActionEvent actionEvent) { String id = (String) popupIdExpression.getValue(FacesContext.getCurrentInstance().getELContext()); UIComponent popup = FindComponentUtils.findComponent(actionEvent.getComponent(), id); if (popup == null) { LOG.error("Found no popup for \"" + popupIdExpression.getExpressionString() + "\" := \"" + id + "\"! Search base componentId : " + actionEvent.getComponent().getClientId(FacesContext.getCurrentInstance())); } return popup; }
private List<UIComponent> getComponentResources(FacesContext context, String target, boolean create) { String location = getIdentifier(target); UIComponent facet = getFacet(location); if (facet == null && create) { // Using an implementation specific component type to prevent // component resources being rendered at the incorrect time if // a caller calls UIViewRoot.encodeAll(). facet = context.getApplication().createComponent("javax.faces.ComponentResourceContainer"); facet.setId(location); getFacets().put(location, facet); } return ((facet != null) ? facet.getChildren() : null); }
@Override public void decode(FacesContext context, UIComponent component) { CommandButton button = (CommandButton) component; if (button.isDisabled()) { return; } String param = component.getClientId(context); if (context.getExternalContext().getRequestParameterMap().containsKey(param)) { component.queueEvent(new ActionEvent(component)); } decodeBehaviors(context, component); }
private static String getResolvedId(UIComponent component, String id) { UIComponent resolvedComponent = component.findComponent(id); if (resolvedComponent == null) { if (id.charAt(0) == UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance())) { return id.substring(1); } return id; } return resolvedComponent.getClientId(); } }
protected NavigationCase findNavigationCase(FacesContext context, UIOutcomeTarget outcomeTarget) { ConfigurableNavigationHandler navigationHandler = (ConfigurableNavigationHandler) context.getApplication().getNavigationHandler(); String outcome = outcomeTarget.getOutcome(); if (outcome == null) { outcome = context.getViewRoot().getViewId(); } if (PrimeApplicationContext.getCurrentInstance(context).getEnvironment().isAtLeastJsf22()) { if (outcomeTarget instanceof UIComponent) { String toFlowDocumentId = (String) ((UIComponent) outcomeTarget).getAttributes().get(ActionListener.TO_FLOW_DOCUMENT_ID_ATTR_NAME); if (toFlowDocumentId != null) { return navigationHandler.getNavigationCase(context, null, outcome, toFlowDocumentId); } } } return navigationHandler.getNavigationCase(context, null, outcome); }
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); } }
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = component.getClientId(context); writer.startElement("body", component); if (shouldWriteId(component)) { writer.writeAttribute("id", clientId, "id"); } String styleClass = (String) component.getAttributes().get("styleClass"); if (styleClass != null && styleClass.length() != 0) { writer.writeAttribute("class", styleClass, "styleClass"); } renderPassThruAttributes(context, component, HTML.BODY_ATTRS); }