Refine search
UIOutput css = new UIOutput(); css.setRendererType("javax.faces.resource.Stylesheet"); css.getAttributes().put("library", "mylibrary"); css.getAttributes().put("name", "bar.css"); UIOutput js = new UIOutput(); js.setRendererType("javax.faces.resource.Script"); js.getAttributes().put("library", "mylibrary"); js.getAttributes().put("name", "bar.js"); FacesContext context = FacesContext.getCurrentInstance(); context.getViewRoot().addComponentResource(context, css, "head"); context.getViewRoot().addComponentResource(context, js, "head");
String fieldsetHTMLText ="<fieldset id=\"blah\"></fieldset>"; UIOutput verbatim = new UIOutput(); verbatim.setRendererType("javax.faces.Text"); verbatim.getAttributes().put("escape", false); verbatim.setValue(fieldsetHTMLText);
/** * value to be set in the variable. * * @JSFProperty * required="true" */ public Object getValue() { return super.getValue(); }
private static UIComponent createJsfJs() { UIOutput output = new UIOutput(); output.setRendererType("javax.faces.resource.Script"); output.getAttributes().put("name", JSF_SCRIPT_RESOURCE_NAME); output.getAttributes().put("library", JSF_SCRIPT_LIBRARY_NAME); return output; }
if (name != null && name.length() > 0) name = ELText.parse(getExpressionFactory(), context.getELContext(), name).toString(context.getELContext()); String rendererType = context.getApplication().getResourceHandler().getRendererTypeForResourceName(name); output.setRendererType(rendererType); Map<String, Object> attributes = output.getAttributes(); Resource resource = (Resource)component.getAttributes().get(Resource.COMPONENT_RESOURCE_KEY); if (resource != null) context.getViewRoot().addComponentResource(context, output, target); context.getViewRoot().addComponentResource(context, output);
/** * <p>Creates a transient UIOutput using the Application, with the following characteristics:</p> * <p/> * <p><code>componentType</code> is * <code>javax.faces.HtmlOutputText</code>.</p> * <p/> * <p><code>transient</code> is <code>true</code>.</p> * <p/> * <p><code>escape</code> is <code>false</code>.</p> * <p/> * <p><code>id</code> is * <code>FacesContext.getViewRoot().createUniqueId()</code></p> */ protected UIOutput createVerbatimComponent() { UIOutput verbatimComp = (UIOutput) getFacesContext().getApplication() .createComponent("javax.faces.HtmlOutputText"); verbatimComp.setTransient(true); verbatimComp.getAttributes().put("escape", Boolean.FALSE); verbatimComp.setId(getFacesContext().getViewRoot().createUniqueId()); return verbatimComp; }
@Override public void buildView(FacesContext facesContext, UIViewRoot uiViewRoot) throws IOException { super.buildView(facesContext, uiViewRoot); UIComponent coreForm = findCoreFormRecurse(uiViewRoot); if (coreForm != null) { // Since the JSF-1.2-based TCK does not have h:head tags in any of the JSPs, need to add one dynamically so // that the jsf.js script resource can be rendered. This is necessary so that Trinidad Partial Page // Rendering (PPR) will work properly. HtmlHead htmlHead = new HtmlHead(); uiViewRoot.getChildren().add(htmlHead); // Add the "jsf.js" script resource to the h:head component. UIOutput uiOutput = new UIOutput(); uiOutput.setRendererType("javax.faces.resource.Script"); uiOutput.getAttributes().put("name", "jsf.js"); uiOutput.getAttributes().put("library", "javax.faces"); uiViewRoot.addComponentResource(facesContext, uiOutput, "head"); // Due to a bug in the Trinidad tr:form renderer, need to add the javax.faces.encodedURL hidden field // dynamically. See: https://issues.apache.org/jira/browse/TRINIDAD-2284 String viewId = uiViewRoot.getViewId(); String actionURL = facesContext.getApplication().getViewHandler().getActionURL(facesContext, viewId); ExternalContext externalContext = facesContext.getExternalContext(); String encodedPartialActionURL = externalContext.encodePartialActionURL(actionURL); EncodedURLHiddenField encodedURLHiddenField = new EncodedURLHiddenField(); encodedURLHiddenField.setValue(encodedPartialActionURL); coreForm.getChildren().add(encodedURLHiddenField); } }
HashSet<ResourceEntry> collectedResourceEntries = new HashSet<ResourceEntry>(); HashSet<ResourceEntry> currentResourceEntries = new HashSet<ResourceEntry>(); List children = resourceContainer.getChildren(); Map attributes = next.getAttributes(); String name = (String) attributes.get("name"); String library = normalizeLibraryName((String) attributes.get("library")); resourceContainer.setInView(false); UIOutput c = new UIOutput(); String rendererType = context.getApplication().getResourceHandler().getRendererTypeForResourceName(next.name); c.setTransient(true); c.setRendererType(rendererType); Map attributes = c.getAttributes(); attributes.put("name", next.name); attributes.put("library", next.library); attributes.put("version", "fubar"); root.addComponentResource(context, c, next.target);
private void create(FacesContext context, String rendererType) { if (!infoBuilder.isEmpty() && !isAjaxRequestWithPartialRendering(context)) { // #273, #301 if (componentResource == null) { componentResource = new UIOutput(); context.getViewRoot().addComponentResource(context, componentResource, target); } String resourceName = infoBuilder.create() + extension; componentResource.getAttributes().put("library", LIBRARY_NAME); componentResource.getAttributes().put("name", resourceName); componentResource.setRendererType(rendererType); Resource resource = context.getApplication().getResourceHandler().createResource(resourceName, LIBRARY_NAME); if (resource instanceof CDNResource) { String fallback = ((CDNResource) resource).getLocalRequestPath(); if (RENDERER_TYPE_JS.equals(rendererType)) { componentResource.getPassThroughAttributes().put("onerror", "document.write('<script src=\"" + fallback + "\"></script>')"); } else if (RENDERER_TYPE_CSS.equals(rendererType)) { componentResource.getPassThroughAttributes().put("onerror", "this.onerror=null;this.href='" + fallback + "'"); } else if (DeferredScriptRenderer.RENDERER_TYPE.equals(rendererType)) { componentResource.getAttributes().put("onerror", "document.write('<script src=\"" + fallback + "\"><\\/script>')"); } } else if (RENDERER_TYPE_JS.equals(rendererType)) { componentResource.getPassThroughAttributes().put("crossorigin", "anonymous"); } } removeComponentResources(context, componentResourcesToRemove, target); }
private static UIComponent addScriptResource(String libraryName, String resourceName, String target) { FacesContext context = FacesContext.getCurrentInstance(); String id = (libraryName != null ? (libraryName.replaceAll("\\W+", "_") + "_") : "") + resourceName.replaceAll("\\W+", "_"); for (UIComponent existingResource : context.getViewRoot().getComponentResources(context, target)) { if (id.equals(existingResource.getId())) { return existingResource; } } UIOutput outputScript = createScriptResource(); outputScript.setId(id); if (libraryName != null) { outputScript.getAttributes().put("library", libraryName); } outputScript.getAttributes().put("name", resourceName); return addComponentResource(outputScript, target); }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException { boolean disabled = getDisabled(ctx); if (!disabled) { FacesContext context = FacesContext.getCurrentInstance(); Map attrs = context.getAttributes(); if (!attrs.containsKey(RefreshHandler.class.getName())) { Map<String, Object> viewMap = context.getViewRoot().getViewMap(); viewMap.put(INTERVAL, getInterval(ctx)); viewMap.put(DURATION, getDuration(ctx)); UIOutput refreshSetup = new RefreshSetupOutput(); refreshSetup.setId("refreshSetup"); refreshSetup.setTransient(true); parent.setInView(false); parent.getChildren().add(0, refreshSetup); parent.setInView(true); attrs.put(RefreshHandler.class.getName(), true); } } }
private void initializeFacetContainer(String target) { final FacesContext context = FacesContext.getCurrentInstance(); final UIViewRoot root = context.getViewRoot(); UIComponent container = CoreUtils.getResourceContainer(root, target); if (container == null) { List<SystemEventListener> postAddToViewListeners = root.getViewListenersForEventClass(PostAddToViewEvent.class); if (postAddToViewListeners != null) { postAddToViewListeners = new ArrayList<SystemEventListener>(postAddToViewListeners); for (SystemEventListener l : postAddToViewListeners) { root.unsubscribeFromViewEvent(PostAddToViewEvent.class, l); List<SystemEventListener> preRemoveFromViewListeners = root.getViewListenersForEventClass(PreRemoveFromViewEvent.class); if (preRemoveFromViewListeners != null) { preRemoveFromViewListeners = new ArrayList<SystemEventListener>(preRemoveFromViewListeners); UIComponent c = new UIOutput(); c.setId("initialize_" + target); root.addComponentResource(context, c, target); root.removeComponentResource(context, c, target);
protected void onComponentCreated(FaceletContext faceletContext, UIComponent separator, UIComponent parent) { Application application = faceletContext.getFacesContext().getApplication(); UIViewRoot root = ComponentSupport.getViewRoot(faceletContext, parent); UIOutput label = (UIOutput) application.createComponent(UILabel.COMPONENT_TYPE); label.setId(root.createUniqueId()); label.setRendererType("Label"); setAttributes(faceletContext, label); separator.getFacets().put(Facets.LABEL, label); if (labelAttribute != null) { if (labelAttribute.isLiteral()) { label.setValue(labelAttribute.getValue(faceletContext)); } else { ValueExpression expression = labelAttribute.getValueExpression(faceletContext, String.class); ELAdaptor.setExpression(label, Attributes.VALUE, expression); } } }
/** * {@inheritDoc} */ public void restoreState(FacesContext facesContext, Object state) { if (state == null) { return; } Object[] values = (Object[]) state; super.restoreState(facesContext, values[0]); this.windowContextId = (String) values[1]; //TODO test if we can remove the request-map based cache (there is a new approach) facesContext.getExternalContext().getRequestMap() .put(WindowContextManager.WINDOW_CONTEXT_ID_PARAMETER_KEY, this.windowContextId); }
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException { UIOutput component = (UIOutput) uiComponent; ResponseWriter writer = facesContext.getResponseWriter(); String clientId = uiComponent.getClientId(facesContext); //This is not ice:outputText, so just render the value //this will be true for open HTML in the JSP if (!(component instanceof HtmlOutputText)) { Object value = component.getValue(); if (value != null) { String svalue = String.valueOf(value); if (svalue.length() > 0) { writer.write(svalue); } } return; } if (!requiresSpan(uiComponent)) return; Object styleClass = uiComponent.getAttributes().get("styleClass"); writer.startElement(HTML.SPAN_ELEM, uiComponent); writer.writeAttribute(HTML.ID_ATTR, clientId, HTML.ID_ATTR); renderHtmlAttributes(facesContext, writer, uiComponent); if (styleClass != null) { writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null); } }
/** * {@inheritDoc} */ @Override public void apply(FaceletContext context, UIComponent parent) { PageMetaModel page = this.getPageMetaModel(context); UIOutput component = new UIOutput(); component.setValue(new PageTitleHolder(page)); parent.getChildren().add(component); } }
private void addResourceIfNecessary(UIViewRoot root, FacesContext context, UIOutput output) { Object libToAdd = output.getAttributes().get("library"); Object nameToAdd = output.getAttributes().get("name"); for (UIComponent c : root.getComponentResources(context, "head")) { String library = (String) c.getAttributes().get("library"); String name = (String) c.getAttributes().get("name"); if (library != null && library.equals(libToAdd) && name != null && name.equals(nameToAdd)) return; } root.addComponentResource(context, output, "head"); }
public void encodeEnd(FacesContext context, UIComponent component) throws IOException { this.renderer.encodeEnd(context, component); if (shadowValueSet) { Map attributesMap = component.getAttributes(); String styleClass = removeStyleClass((String) attributesMap.get("styleClass"), UNINITITIALIZED_STYLE_CLASS); //NOI18N if (styleClass == null || styleClass.length() == 0) attributesMap.put("styleClass", null); //NOI18N else attributesMap.put("styleClass", styleClass); //NOI18N ((UIOutput) component).setValue(null); } }
public static UIComponent createResourceComponent(String name, String lib, String rendererType, boolean isTransient){ UIOutput res = new UIOutput(); res.setRendererType(rendererType); res.setTransient(isTransient); Map attrs = res.getAttributes(); attrs.put("name", name); if (lib != null && lib.trim().length() > 0) { attrs.put("library", lib); } attrs.put("version", "fubar"); return res; }
@Override public void clearInitialState() { if (initialStateMarked()) { super.clearInitialState(); Converter c = getConverter(); if (c != null && c instanceof PartialStateHolder) { ((PartialStateHolder) c).clearInitialState(); } } }