/** * Render any "passthru" attributes, where we simply just output the raw name and value of the * attribute. This method is aware of the set of HTML4 attributes that fall into this bucket. * Examples are all the javascript attributes, alt, rows, cols, etc. * * @param writer writer the {@link javax.faces.context.ResponseWriter} to be used when writing the * attributes * @param component the component * @param attributes an array off attributes to be processed * @throws IOException if an error occurs writing the attributes */ public static void renderPassThruAttributes( ResponseWriter writer, UIComponent component, String[] attributes) throws IOException { assert (null != writer); assert (null != component); Map<String, Object> attrMap = component.getAttributes(); // PENDING - think anyone would run the RI using another implementation // of the jsf-api? If they did, then this would fall apart. That // scenario seems extremely unlikely. if (canBeOptimized(component)) { //noinspection unchecked List<String> setAttributes = (List<String>) component.getAttributes().get(ATTRIBUTES_THAT_ARE_SET_KEY); if (setAttributes != null) { renderPassThruAttributesOptimized(writer, component, attributes, setAttributes); } } else { // this block should only be hit by custom components leveraging // the RI's rendering code. We make no assumptions and loop through // all known attributes. boolean isXhtml = RIConstants.XHTML_CONTENT_TYPE.equals(writer.getContentType()); for (String attrName : attributes) { Object value = attrMap.get(attrName); if (value != null && shouldRenderAttribute(value)) { writer.writeAttribute(prefixAttribute(attrName, isXhtml), value, attrName); } } } }
protected void encodeTypeAndImage(FacesContext context, UIComponent uiComponent) throws IOException { ResponseWriter writer = context.getResponseWriter(); String type = (String) uiComponent.getAttributes().get("type"); String image = (String) uiComponent.getAttributes().get("image"); if (image != null) { if (!image.contains(ResourceHandler.RESOURCE_IDENTIFIER)) { image = context.getApplication().getViewHandler().getResourceURL(context, image); image = context.getExternalContext().encodeResourceURL(image); } writer.writeAttribute("type", "image", "image"); writer.writeURIAttribute("src", image, "image"); Object value = uiComponent.getAttributes().get("value"); if (null == uiComponent.getAttributes().get("alt") && null != value) { writer.writeAttribute("alt", value, "value"); } } else { if (!Strings.isNullOrEmpty(type)) { writer.writeAttribute("type", type.toLowerCase(Locale.US), "type"); } else { writer.writeAttribute("type", "submit", "type"); } } }
public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); String styleClass = (String) component.getAttributes().get("styleClass"); String selectedStyleClass = (String) component.getAttributes().get("selectedStyleClass"); @SuppressWarnings("rawtypes") UiRepeatInterface handler = (UiRepeatInterface) component.getAttributes().get("handler"); int currentpage = handler.getCurrentPage(); int pagesize = handler.getPageSize(); int itemcount = handler.totalSize(); int showpages = toInt(component.getAttributes().get("showpages")); Integer[] linkedPages = computeLinks(currentpage, pagesize, itemcount, showpages); String[] symbols = computeSymbols(currentpage, pagesize, itemcount, showpages); // Boolean[] currents = computeCurrent(currentpage, pagesize, showpages, // itemcount); writeLinks( writer, component, styleClass, selectedStyleClass, linkedPages, symbols, currentpage, JSFUtils.getQueryStringParameters(), handler.getCurrentPageParam()); }
protected void encodeProgressStateProlog( FacesContext context, UIComponent component, ProgressBarState currentState) throws IOException { ResponseWriter responseWriter = context.getResponseWriter(); responseWriter.startElement(HtmlConstants.DIV_ELEM, component); responseWriter.writeAttribute( HtmlConstants.ID_ATTRIBUTE, component.getClientId(context) + ".rmng", null); responseWriter.writeAttribute( HtmlConstants.CLASS_ATTRIBUTE, HtmlUtil.concatClasses("rf-pb-rmng", component.getAttributes().get("remainingClass")), null); responseWriter.writeAttribute( HtmlConstants.STYLE_ATTRIBUTE, getContentStyle(currentState == ProgressBarState.progressState), null); responseWriter.startElement(HtmlConstants.DIV_ELEM, component); responseWriter.writeAttribute( HtmlConstants.CLASS_ATTRIBUTE, HtmlUtil.concatClasses("rf-pb-prgs", component.getAttributes().get("progressClass")), null); responseWriter.writeAttribute( HtmlConstants.ID_ATTRIBUTE, component.getClientId(context) + ".prgs", null); responseWriter.writeAttribute( HtmlConstants.STYLE_ATTRIBUTE, "width: " + getWidth(component) + "%", null); responseWriter.endElement(HtmlConstants.DIV_ELEM); }
public UIComponent findCompositeComponentUsingLocation(FacesContext ctx, Location location) { StackHandler sh = getStackHandler(StackType.TreeCreation); Stack<UIComponent> s = sh.getStack(false); if (s != null) { String path = location.getPath(); for (int i = s.size(); i > 0; i--) { UIComponent cc = s.get(i - 1); Resource r = (Resource) cc.getAttributes().get(Resource.COMPONENT_RESOURCE_KEY); if (path.endsWith('/' + r.getResourceName()) && path.contains(r.getLibraryName())) { return cc; } } } else { // runtime eval String path = location.getPath(); UIComponent cc = UIComponent.getCurrentCompositeComponent(ctx); while (cc != null) { Resource r = (Resource) cc.getAttributes().get(Resource.COMPONENT_RESOURCE_KEY); if (path.endsWith('/' + r.getResourceName()) && path.contains(r.getLibraryName())) { return cc; } cc = UIComponent.getCompositeComponentParent(cc); } } // we could not find the composite component because the location was not found, // this will happen if the #{cc} refers to a composite component one level up, // so we are going after the current composite component. // return UIComponent.getCurrentCompositeComponent(ctx); }
/** * This method returns any facets that should be applied to the <code>TreeNode (comp)</code>. * Useful facets for the sun <code>TreeNode</code> component are: "content" and "image". * * <p>Facets that already exist on <code>comp</code>, or facets that are directly added to <code> * comp</code> do not need to be returned from this method. * * <p>This implementation directly adds a "content" facet and returns <code>null</code> from this * method. * * @param comp The tree node <code>UIComponent</code>. * @param nodeObject The (model) object representing the tree node. */ public Map<String, UIComponent> getFacets(UIComponent comp, Object nodeObject) { if (nodeObject == null) { return null; } if (nodeObject.toString().equals(_objectName)) { return null; } Properties props = new Properties(); LayoutComponent desc = this.getLayoutComponent(); // Check to see if a childActionListener was added // NOTE: This is not needed when a "command" event is used. In the // case of a CommandEvent an ActionListener will be // automatically registered by the ComponentFactoryBase class // during "setOptions()". Also, setting a childActionListener // here should not stop "command" handlers from being invoked. setProperty(props, "actionListener", desc.getOption("childActionListener")); // Also se the target and text... setProperty(props, "target", desc.getOption("childTarget")); setProperty(props, "text", comp.getAttributes().get("text")); // FIXME: Add support for other hyperlink properties?? // Create Hyperlink // NOTE: Last attribute "content" will be the facet named used. UIComponent link = ComponentUtil.getChild( comp, "link", "com.sun.jsftemplating.component.factory.sun.HyperlinkFactory", props, "content"); // Check to see if we have a childURL, evalute it here (after component // is created, before rendered) so we can use the link itself to define // the URL. This has proven to be useful... Object val = desc.getOption("childURL"); if (val != null) { link.getAttributes() .put("url", desc.resolveValue(FacesContext.getCurrentInstance(), link, val)); } // Set href's handlers... // We do it this way rather than earlier b/c the factory will not // recognize this as a property, it requires it to be defined in the // LayoutComponent as a handler. So we must do this manually like // this. List handlers = desc.getHandlers("childCommand"); if (handlers != null) { link.getAttributes().put("command", handlers); // This adds the required action listener to proces the commands // This is needed here b/c the factory has already executed -- the // factory is normally the place where this is added (iff there is // at least one command handler). ((ActionSource) link).addActionListener(CommandActionListener.getInstance()); } // We already added the facet, return null... return null; }
public void testWidgetProcessor() throws Exception { CssStyleProcessor processor = new CssStyleProcessor(); // Pass through HtmlMetawidget metawidget = new HtmlMetawidget(); UIComponent component = new HtmlInputText(); assertEquals(component, processor.processWidget(component, PROPERTY, null, metawidget)); assertEquals(null, component.getAttributes().get("style")); assertEquals(null, component.getAttributes().get("styleClass")); // Simple styles and styleClasses metawidget.setStyle("foo1"); metawidget.setStyleClass("bar1"); assertEquals(component, processor.processWidget(component, PROPERTY, null, metawidget)); assertEquals("foo1", component.getAttributes().get("style")); assertEquals("bar1", component.getAttributes().get("styleClass")); // Compound styles and styleClasses metawidget.setStyle("foo2"); metawidget.setStyleClass("bar2"); assertEquals(component, processor.processWidget(component, PROPERTY, null, metawidget)); assertEquals("foo1 foo2", component.getAttributes().get("style")); assertEquals("bar1 bar2", component.getAttributes().get("styleClass")); }
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, ELException { Util.notNull("parent", parent); UIComponent facetComponent = parent.getFacets().get(UIViewRoot.METADATA_FACET_NAME); if (facetComponent == null) { parent.getAttributes().put(FacetHandler.KEY, UIViewRoot.METADATA_FACET_NAME); try { this.nextHandler.apply(ctx, parent); } finally { parent.getAttributes().remove(FacetHandler.KEY); } facetComponent = parent.getFacets().get(UIViewRoot.METADATA_FACET_NAME); if (!(facetComponent instanceof UIPanel)) { UIComponent panelGroup = ctx.getFacesContext().getApplication().createComponent(UIPanel.COMPONENT_TYPE); panelGroup.getAttributes().put(UIComponent.ADDED_BY_PDL_KEY, Boolean.TRUE); panelGroup.getChildren().add(facetComponent); parent.getFacets().put(UIViewRoot.METADATA_FACET_NAME, panelGroup); facetComponent = panelGroup; facetComponent.setId(UIViewRoot.METADATA_FACET_NAME); } } }
/** * @param facesContext * @param uiComponent * @throws IOException */ public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException { if (facesContext == null || uiComponent == null) { throw new NullPointerException("facesContext or uiComponent is null"); } UIOutput output = (UIOutput) uiComponent; String linkVal = getValue(facesContext, uiComponent); if (!output.isRendered()) return; ResponseWriter writer = facesContext.getResponseWriter(); if (writer == null) { throw new NullPointerException("ResponseWriter is null"); } if (!checkDisabled(uiComponent)) { writer.startElement("a", uiComponent); } else { writer.startElement("span", uiComponent); } writer.writeAttribute("id", uiComponent.getClientId(facesContext), "id"); if (null == linkVal || 0 == linkVal.length()) { linkVal = ""; } clientId = output.getClientId(facesContext); linkVal = appendParameters(facesContext, uiComponent, linkVal); if (!checkDisabled(uiComponent)) { writer.writeURIAttribute( "href", facesContext.getExternalContext().encodeResourceURL(linkVal), "href"); } // ICE-2169 PassThruAttributeWriter.renderHtmlAttributes(writer, uiComponent, passThruAttributes); Boolean visibleAttribute = (Boolean) uiComponent.getAttributes().get("visible"); boolean isVisible = visibleAttribute == null ? true : visibleAttribute.booleanValue(); String style = (String) uiComponent.getAttributes().get(HTML.STYLE_ATTR); if (!isVisible) { if (style == null) { style = ""; } else if (style.trim().length() == 0 || style.trim().endsWith(";")) { // nothing } else { style += ";"; } style += "display:none;"; } if (style != null) writer.writeAttribute(HTML.STYLE_ATTR, style, HTML.STYLE_ATTR); String styleClass = (String) output.getAttributes().get("styleClass"); if (styleClass != null) writer.writeAttribute("class", styleClass, "styleClass"); writer.flush(); }
private static void addStyleClass(UIComponent component, String newStyleClass) { String styleClass = (String) component.getAttributes().get(ATTR_STYLECLASS); if (StringUtils.isEmpty(styleClass)) { styleClass = newStyleClass; } else { styleClass += " " + newStyleClass; } component.getAttributes().put(ATTR_STYLECLASS, styleClass); }
private void setInitialRender(UIComponent component) { Iterator<UIComponent> kids = component.getChildren().iterator(); while (kids.hasNext()) { UIComponent kid = kids.next(); setInitialRender(kid); } if (component.getAttributes().get("styleClass") != null) { component.getAttributes().remove("styleClass"); } }
/** * Faces render output method . * * <p>Method Generator: org.sakaiproject.tool.assessment.devtoolsRenderMaker * * @param context <code>FacesContext</code> for the current request * @param component <code>UIComponent</code> being rendered * @throws IOException if an input/output error occurs */ public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResourceLoader rb = new ResourceLoader("org.sakaiproject.tool.assessment.bundle.AssessmentSettingsMessages"); ResponseWriter writer = context.getResponseWriter(); String contextPath = context.getExternalContext().getRequestContextPath(); Object value = null; if (component instanceof UIInput) { value = ((UIInput) component).getSubmittedValue(); } if (value == null && component instanceof ValueHolder) { value = ((ValueHolder) component).getValue(); } String valString = ""; if (value != null) { valString = value.toString(); } String size = (String) component.getAttributes().get("size"); if (size == null) { size = "20"; } String jsfId = (String) component.getAttributes().get("id"); String id = jsfId; if (component.getId() != null && !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) { id = component.getClientId(context); } writer.write(""); writer.write("<input "); writer.write(""); writer.write(" value=\"" + valString + "\" "); writer.write(" type=\"" + TYPE + "\" "); writer.write(" size=\"" + size + "\" "); writer.write(" name=\"" + id + "\""); writer.write(" id=\"" + id + "\" /> "); writer.write("<img "); writer.write(" style=\"" + CURSORSTYLE + "\" "); writer.write(" height=\"" + HEIGHT + "\" "); writer.write(" width=\"" + WIDTH + "\""); writer.write(" src=\"" + contextPath + "/images/sel.gif\" "); writer.write(" border=\"0\""); writer.write(" alt=\"" + rb.getString("cp_CLICKALT") + "\" "); writer.write(" id=\"_colorPickerPop_" + id + "\""); writer.write( " onclick=\"javascript:TCP.popup(" + "document.getElementById('" + id + "'),'','" + contextPath + "/jsf/widget/colorpicker/')\" />"); writer.write(" "); }
/** * If the component's type attribute is null or not equal to <code>reset</code>, <code>submit * </code> or <code>button</code>, default to <code>submit</code>. * * @param component the component of interest * @return the type for this button */ private static String getButtonType(UIComponent component) { String type = (String) component.getAttributes().get("type"); if (type == null || (!"reset".equals(type) && !"submit".equals(type) && !"button".equals(type))) { type = "submit"; // This is needed in the decode method component.getAttributes().put("type", type); } return type; }
/** * Write pass thru attributes associated with the UIComponent parameter. * * @param writer * @param uiComponent * @throws IOException */ public static void renderHtmlAttributes( ResponseWriter writer, UIComponent uiComponent, String[] htmlAttributes) throws IOException { if (writer == null) { throw new FacesException("Null pointer exception"); } if (uiComponent == null) { throw new FacesException("Component instance is null"); } // For now, we just support accelerating h: component rendering boolean stockAttribTracking = ImplementationUtil.isStockAttributeTracking(); boolean attribTracking = stockAttribTracking && uiComponent.getClass().getName().startsWith("javax.faces.component."); List attributesThatAreSet = (!attribTracking) ? null : (List) uiComponent .getAttributes() .get("javax.faces.component.UIComponentBase.attributesThatAreSet"); if (!attribTracking || (attributesThatAreSet != null && attributesThatAreSet.size() > 0)) { String nextPassThruAttributeName = null; Object nextPassThruAttributeValue = null; for (int i = 0; i < htmlAttributes.length; i++) { nextPassThruAttributeName = htmlAttributes[i]; if (attribTracking && (attributesThatAreSet == null || !attributesThatAreSet.contains(nextPassThruAttributeName))) { continue; } nextPassThruAttributeValue = uiComponent.getAttributes().get(nextPassThruAttributeName); // Only render non-null attributes. // Some components have integer attribute values // set to the Wrapper classes' minimum value - don't render // an attribute with this sentinel value. if (nextPassThruAttributeValue != null && !valueIsIntegerSentinelValue(nextPassThruAttributeValue)) { writer.writeAttribute( nextPassThruAttributeName, nextPassThruAttributeValue, nextPassThruAttributeValue.toString()); } } } // this call maintains the css related changes made by the effects on the client // especially the "visible" attribute. CurrentStyle.apply(FacesContext.getCurrentInstance(), uiComponent, writer); }
/** * Converts the value into an entity. The type of the entity depends on the type that the daoCrud * returns. * * @param facesContext current faces context * @param component current component * @param value current value submitted from user. * @return An Entity */ public Object getAsObject( final FacesContext facesContext, final UIComponent component, final String value) { logger.debug( String.format( "getAsObject() called value=%s, component=%s, value class=%s", value, component.getClientId(facesContext), value.getClass().getName())); UIInput input = (UIInput) component; if (value.equals("-1") && (input.isRequired() || component.getAttributes().get("required_bean") != null)) { logger.debug("Required field and the value was -1"); throw new ConverterException(new FacesMessage("Required", "Required")); } try { Serializable entityId = CrudUtils.getIdObject(value, this.idType); logger.debug(String.format("entityId %s", entityId)); if (dao == null) { ObjectRegistry objectRegistry = CrankContext.getObjectRegistry(); Map<String, GenericDao> repos = (Map<String, GenericDao>) objectRegistry.getObject("repos"); if (managedObject != null) { logger.debug("Looking up DAO by managedObject"); dao = repos.get(managedObject.getName()); } else { Object key = component.getAttributes().get("beanType"); logger.debug("Looking up DAO by beanType"); dao = repos.get((String) key); } } Object object = dao.read(entityId); logger.debug(String.format("Read object %s", object)); if (object == null) { if ("-1".equals(value)) { logger.debug("No object found and the value was -1"); throw new ConverterException(new FacesMessage("Required", "Required")); } else { throw new ConverterException( new FacesMessage( "Can't find object with id " + value, "Can't find object with id " + value)); } } LogUtils.debug(logger, "Returning converted object %s", object); return object; } catch (ConverterException ex) { throw ex; } catch (Exception ex) { logger.error("Unable to convert object", ex); String message = String.format("Unable to convert, fatal issue, %s ", ex.getMessage()); throw new ConverterException(new FacesMessage(message, message)); } }
/** * Handle the add. * * @param context the Faces context. * @param component the UI component to add to the list as an ADD. */ private void handleAdd(FacesContext context, UIComponent component) { if (!component.isTransient() && !hasTransientAncestor(component)) { if (component.getParent() != null && component.getParent().isInView()) { String id = component.getId(); /* * Since adding a component, can mean you are really reparenting * it, we need to make sure the OLD clientId is not cached, we do * that by setting the id. */ if (id != null) { component.setId(id); } if (component.getParent().getFacets().containsValue(component)) { Map facets = component.getParent().getFacets(); Iterator entries = facets.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); if (entry.getValue() == component) { incrementDynamicChildCount(component.getParent()); component.clearInitialState(); component .getAttributes() .put(DYNAMIC_COMPONENT, component.getParent().getChildren().indexOf(component)); ComponentStruct struct = new ComponentStruct(); struct.action = ComponentStruct.ADD; struct.facetName = entry.getKey().toString(); struct.parentClientId = component.getParent().getClientId(context); struct.clientId = component.getClientId(context); struct.id = component.getId(); handleAddRemoveWithAutoPrune(component, struct); } } } else { incrementDynamicChildCount(component.getParent()); component.clearInitialState(); component .getAttributes() .put(DYNAMIC_COMPONENT, component.getParent().getChildren().indexOf(component)); ComponentStruct struct = new ComponentStruct(); struct.action = ComponentStruct.ADD; struct.parentClientId = component.getParent().getClientId(context); struct.clientId = component.getClientId(context); struct.id = component.getId(); handleAddRemoveWithAutoPrune(component, struct); } } } }
public static void decorateAttribute(UIComponent component, String attribute, String value) { String attributeValue = (String) component.getAttributes().get(attribute); if (attributeValue != null) { if (attributeValue.indexOf(value) == -1) { String decoratedValue = attributeValue + ";" + value; component.getAttributes().put(attribute, decoratedValue); } else { component.getAttributes().put(attribute, attributeValue); } } else { component.getAttributes().put(attribute, value); } }
/** * Copies attributes and value expressions with given name from parent component to child * component. */ public static void copyValues(UIComponent parent, UIComponent child, String[] valueNames) { Map<String, Object> parentAttributes = parent.getAttributes(); Map<String, Object> childAttributes = child.getAttributes(); for (String name : valueNames) { // attributes if (parentAttributes.containsKey(name)) { childAttributes.put(name, parentAttributes.get(name)); } // value expressions ValueExpression ve = parent.getValueExpression(name); if (ve != null) { child.setValueExpression(name, ve); } } }
@Override public BeanInfo getComponentMetadata(FacesContext context, Resource ccResource) { // PENDING this implementation is terribly wasteful. // Must find a better way. CompositeComponentBeanInfo result; FaceletContext ctx = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); FaceletFactory factory = (FaceletFactory) RequestStateManager.get(context, RequestStateManager.FACELET_FACTORY); VariableMapper orig = ctx.getVariableMapper(); UIComponent tmp = context.getApplication().createComponent("javax.faces.NamingContainer"); UIPanel facetComponent = (UIPanel) context.getApplication().createComponent("javax.faces.Panel"); facetComponent.setRendererType("javax.faces.Group"); tmp.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facetComponent); // We have to put the resource in here just so the classes that eventually // get called by facelets have access to it. tmp.getAttributes().put(Resource.COMPONENT_RESOURCE_KEY, ccResource); Facelet f; try { f = factory.getFacelet(ccResource.getURL()); VariableMapper wrapper = new VariableMapperWrapper(orig) { @Override public ValueExpression resolveVariable(String variable) { return super.resolveVariable(variable); } }; ctx.setVariableMapper(wrapper); context.getAttributes().put(IS_BUILDING_METADATA, Boolean.TRUE); f.apply(context, facetComponent); } catch (Exception e) { if (e instanceof FacesException) { throw (FacesException) e; } else { throw new FacesException(e); } } finally { context.getAttributes().remove(IS_BUILDING_METADATA); ctx.setVariableMapper(orig); } result = (CompositeComponentBeanInfo) tmp.getAttributes().get(UIComponent.BEANINFO_KEY); return result; }
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); DashboardColumn column = (DashboardColumn) component; // Start elements writer.startElement("div", component); String clientId = generateId(context, component, "column"); writer.writeAttribute("id", clientId, null); writer.writeAttribute("data-layout-id", column.getLayoutId(), null); String sClass = "column "; if (component.getAttributes().get("styleClass") != null) sClass += (String) component.getAttributes().get("styleClass"); writer.writeAttribute("class", sClass, "class"); }
/** 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 Object getAsObject(FacesContext fc, UIComponent uic, String value) { if (value != null && !value.isEmpty()) { return (Competence) uic.getAttributes().get(value); } return null; }
protected void encodeScript(FacesContext facesContext, UIComponent component) throws IOException { JavaScriptService javaScriptService = ServiceTracker.getService(JavaScriptService.class); JSFunction messageObject = new JSObject(getJSClassName(), component.getClientId(facesContext)); Map<String, Object> attributes = component.getAttributes(); Builder<String, Object> parametersBuilder = ImmutableMap.builder(); String forId = (String) attributes.get("for"); RendererUtils rendererUtils = RendererUtils.getInstance(); if (!Strings.isNullOrEmpty(forId)) { UIComponent target = rendererUtils.findComponentFor(component, forId); if (null != target) { parametersBuilder.put("forComponentId", target.getClientId(facesContext)); } } Severity level = getLevel(component); if (FacesMessage.SEVERITY_INFO != level) { parametersBuilder.put("level", level.getOrdinal()); } if (!rendererUtils.isBooleanAttribute(component, "showSummary")) { parametersBuilder.put("showSummary", false); } if (rendererUtils.isBooleanAttribute(component, "showDetail")) { parametersBuilder.put("showDetail", true); } if (rendererUtils.isBooleanAttribute(component, "tooltip")) { parametersBuilder.put("tooltip", true); } if (isComponentMessages(component)) { parametersBuilder.put("isMessages", true); } messageObject.addParameter(parametersBuilder.build()); // RendererUtils.getInstance().writeScript(facesContext, component, messageObject); javaScriptService.addPageReadyScript(facesContext, messageObject); }
@SuppressWarnings("unchecked") public UIComponent generate(FacesContext context, String id) { UIComponent component = this.createOutputTextComponent(context, id); component.getAttributes().put("escape", Boolean.FALSE); return component; }
private static void renderPassThruAttributesUnoptimized( FacesContext context, ResponseWriter writer, UIComponent component, Attribute[] knownAttributes, Map<String, List<ClientBehavior>> behaviors) throws IOException { boolean isXhtml = XHTML_CONTENT_TYPE.equals(writer.getContentType()); Map<String, Object> attrMap = component.getAttributes(); for (Attribute attribute : knownAttributes) { String attrName = attribute.getName(); String[] events = attribute.getEvents(); boolean hasBehavior = ((events != null) && (events.length > 0) && (behaviors.containsKey(events[0]))); Object value = attrMap.get(attrName); if (value != null && shouldRenderAttribute(value) && !hasBehavior) { writer.writeAttribute(prefixAttribute(attrName, isXhtml), value, attrName); } else if (hasBehavior) { renderHandler(context, component, null, attrName, value, events[0]); } } }
@Override protected void setProperties(UIComponent component) { super.setProperties(component); if (resource != null) { component.getAttributes().put("resource", resource); } }
/** * This handler is used for the navigation nodes that request content from an external URL. This * handler pulls the "real url" from from the component specified by the <code>compId</code> * parameter (this necessarily depends on the presence of the navigation container in the view for * the component look up to work). Once the component has been found, the url is retrieved from * the attribute map, and its contents retrieved. If <code>processPage</code> is true, the URL * contents are interpretted and the resulting component(s) are added to the component tree (This * feature is not currently supported).. Otherwise, the contents are returned in the output * parameter <code>pluginPage</code> to be output as-is on the page. * * @param handlerCtx The <code>HandlerContext</code>. */ @Handler( id = "retrievePluginPageContents", input = {@HandlerInput(name = "compId", type = String.class, required = true)}, output = {@HandlerOutput(name = "pluginPage", type = String.class)}) public static void retrievePluginPageContents(HandlerContext handlerCtx) { String id = (String) handlerCtx.getInputValue("compId"); UIComponent comp = handlerCtx.getFacesContext().getViewRoot().findComponent(id); String urlContents = ""; if (comp != null) { String url = (String) comp.getAttributes().get(NavigationNodeFactory.REAL_URL); try { // Read from the URL... URL contentUrl = FileUtil.searchForFile(url, null); if (contentUrl == null) { throw new IOException("Unable to locate file: " + url); } urlContents = new String(FileUtil.readFromURL(contentUrl)); // FIXME: Implement processPage support /* if (processPage) { // probably do something like what includeIntegrations does ... } */ } catch (IOException ex) { Logger.getLogger(PluginHandlers.class.getName()) .log(Level.SEVERE, "Unable to read url: " + url, ex); } } // Set the content to output... handlerCtx.setOutputValue("pluginPage", urlContents); }
private NGSecurityFilter findAndVerifySecurityFilter(FacesContext context, UIComponent component) throws IOException { String checkedBy = (String) component.getAttributes().get("checkedBy"); NGSecurityFilter filter = new NGDefaultSecurityFilter(); if (null != checkedBy) { try { Class<?> clazz = Class.forName(checkedBy); filter = (NGSecurityFilter) clazz.newInstance(); } catch (ClassNotFoundException e) { context .getResponseWriter() .append( "<div style=\"color:#F00\">Configuration error: security class filter not found</div>"); } catch (InstantiationException e) { context .getResponseWriter() .append( "<div style=\"color:#F00\">Configuration error: security class filter could not be instantiated</div>"); } catch (IllegalAccessException e) { context .getResponseWriter() .append( "<div style=\"color:#F00\">Configuration error: security class filter has been forbidden to be instantiated</div>"); } NGSecureUtilities.setCheckedBy(filter); } return filter; }
@Override public String getAsString(FacesContext context, UIComponent component, Object value) { Map<String, Object> attributes = component.getAttributes(); if (attributes.containsKey("pattern")) { pattern = (String) attributes.get("pattern"); } setPattern(pattern); if (attributes.containsKey("locale")) { locale = (Locale) attributes.get("locale"); } setLocale(locale); if (attributes.containsKey("timeZone")) { timeZone = (TimeZone) attributes.get("timeZone"); } setTimeZone(timeZone); if (attributes.containsKey("dateStyle")) { dateStyle = (String) attributes.get("dateStyle"); } setDateStyle(dateStyle); if (attributes.containsKey("timeStyle")) { timeStyle = (String) attributes.get("timeStyle"); } setTimeStyle(timeStyle); if (attributes.containsKey("type")) { type = (String) attributes.get("type"); } setType(type); XMLGregorianCalendar xmlGregCal = (XMLGregorianCalendar) value; Date date = xmlGregCal.toGregorianCalendar().getTime(); return super.getAsString(context, component, date); }
public String getAsString(FacesContext ctx, UIComponent component, Object value) { if (value != null && !"".equals(value)) { if (!(value instanceof IBaseEntity)) { throw new ConverterException( "SimpleEntityConverter - Conversion failed because the object is not an instance of IBaseEntity!"); } IBaseEntity<?> entity = (IBaseEntity<?>) value; String id; if (entity.getId() != null) { id = String.valueOf(entity.getId()); } else { id = ""; } component.getAttributes().put(id, value); return id; } else { return VALUE_NULL; } }