public static void setValueBinding( UIComponent component, String attributeName, String attributeValue) { FacesContext context = FacesContext.getCurrentInstance(); Application app = context.getApplication(); ValueBinding vb = app.createValueBinding(attributeValue); component.setValueBinding(attributeName, vb); }
protected void setProperties(UIComponent component) { super.setProperties(component); FacesContext context = FacesContext.getCurrentInstance(); UIAction cmpt = (UIAction) component; if (styleClass != null) { if (isValueReference(styleClass)) { ValueBinding vb = context.getApplication().createValueBinding(styleClass); component.setValueBinding("styleClass", vb); } else { component.getAttributes().put("styleClass", styleClass); } } if (actionListener != null) { if (UIComponentTag.isValueReference(actionListener)) { Class args[] = {ActionEvent.class}; MethodBinding vb = FacesContext.getCurrentInstance() .getApplication() .createMethodBinding(actionListener, args); cmpt.setActionListener(vb); } else { Object params[] = {actionListener}; throw new FacesException( Util.getExceptionMessageString("com.sun.faces.INVALID_EXPRESSION", params)); } } } // setProperties()
/** @see javax.faces.webapp.UIComponentTag#setProperties(javax.faces.component.UIComponent) */ protected void setProperties(UIComponent component) { super.setProperties(component); FacesContext context = getFacesContext(); if (value != null) { ValueBinding vb = context.getApplication().createValueBinding(value); component.setValueBinding("value", vb); } if (var != null) { ((UIData) component).setVar(var); } }
protected void setProperties(UIComponent component) { Application app = FacesContext.getCurrentInstance().getApplication(); QueryBuilderComponent builder = (QueryBuilderComponent) component; if (query != null && isValueReference(query)) { ValueBinding vb = app.createValueBinding(query); component.setValueBinding("query", vb); } if (onUpdateTotal != null && isValueReference(onUpdateTotal)) { MethodBinding mb = app.createMethodBinding(onUpdateTotal, new Class[] {QueryUpdateTotalEvent.class}); builder.setOnUpdateTotal(mb); } }
/** Transfer tag attributes to component properties. */ protected void setProperties(UIComponent _component) { super.setProperties(_component); if (converter != null) { if (isValueReference(converter)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(converter); _component.setValueBinding("converter", _vb); } else { Converter _converter = FacesContext.getCurrentInstance().getApplication().createConverter(converter); _component.getAttributes().put("converter", _converter); } } if (escape != null) { if (isValueReference(escape)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(escape); _component.setValueBinding("escape", _vb); } else { _component.getAttributes().put("escape", Boolean.valueOf(escape)); } } if (style != null) { if (isValueReference(style)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(style); _component.setValueBinding("style", _vb); } else { _component.getAttributes().put("style", style); } } if (styleClass != null) { if (isValueReference(styleClass)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(styleClass); _component.setValueBinding("styleClass", _vb); } else { _component.getAttributes().put("styleClass", styleClass); } } if (title != null) { if (isValueReference(title)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(title); _component.setValueBinding("title", _vb); } else { _component.getAttributes().put("title", title); } } if (value != null) { if (isValueReference(value)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(value); _component.setValueBinding("value", _vb); } else { _component.getAttributes().put("value", value); } } }
public void applyMetadata(FaceletContext ctx, Object instance) { ((UIComponent) instance) .setValueBinding( this.name, new LegacyValueBinding(this.attr.getValueExpression(ctx, this.type))); }
public UIComponent buildWidget( String elementName, Map<String, String> attributes, UIMetawidget metawidget) { FacesContext context = FacesContext.getCurrentInstance(); Application application = context.getApplication(); Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null); if (clazz == null) { return null; } // Colors (as of RichFaces 3.3.1) if (Color.class.equals(clazz)) { if (WidgetBuilderUtils.isReadOnly(attributes)) { return FacesContext.getCurrentInstance() .getApplication() .createComponent(HtmlOutputText.COMPONENT_TYPE); } return application.createComponent("org.richfaces.ColorPicker"); } // Suggestion box // // Note: for suggestion box to work in table column footer facets, you need // https://jira.jboss.org/jira/browse/RF-7700 if (String.class.equals(clazz)) { String facesSuggest = attributes.get(FACES_SUGGEST); if (facesSuggest != null) { UIComponent stubComponent = application.createComponent(UIStub.COMPONENT_TYPE); List<UIComponent> children = stubComponent.getChildren(); // Standard text box HtmlInputText inputText = (HtmlInputText) application.createComponent(HtmlInputText.COMPONENT_TYPE); inputText.setStyle(((HtmlMetawidget) metawidget).getStyle()); inputText.setStyleClass(((HtmlMetawidget) metawidget).getStyleClass()); children.add(inputText); UISuggestionBox suggestionBox = (UISuggestionBox) application.createComponent(HtmlSuggestionBox.COMPONENT_TYPE); // Lock the 'id's so they don't get changed. This is important for the // JavaScript getElementById that RichFaces generates. Also, do not just use // 'viewRoot.createUniqueId' because, as per the RenderKit specification: // // "If the value returned from component.getId() is non-null and does not start // with UIViewRoot.UNIQUE_ID_PREFIX, call component.getClientId() and render // the result as the value of the id attribute in the markup for the component." // // Therefore the 'id' attribute is never rendered, therefore the JavaScript // getElementById doesn't work. Add our own prefix instead inputText.setId("suggestionText_" + FacesUtils.createUniqueId()); suggestionBox.setId("suggestionBox_" + FacesUtils.createUniqueId()); // Suggestion box suggestionBox.setFor(inputText.getId()); suggestionBox.setVar("_internal"); children.add(suggestionBox); try { // RichFaces 3.2/JSF 1.2 mode // // Note: we wrap the MethodExpression as an Object[] to stop link-time // dependencies on javax.el.MethodExpression, so that we still work with // JSF 1.1 // // Note: according to JavaDocs returnType is only important when literal // (i.e. without #{...}) expression is used, otherwise Object.class is fine // (http://community.jboss.org/message/516830#516830) Object[] methodExpression = new Object[] { application .getExpressionFactory() .createMethodExpression( context.getELContext(), facesSuggest, Object.class, new Class[] {Object.class}) }; ClassUtils.setProperty(suggestionBox, "suggestionAction", methodExpression[0]); } catch (Exception e) { // RichFaces 3.1/JSF 1.1 mode MethodBinding methodBinding = application.createMethodBinding(facesSuggest, new Class[] {Object.class}); suggestionBox.setSuggestionAction(methodBinding); } // Column // // Note: this must be javax.faces.component.html.HtmlColumn, not // org.richfaces.component.html.HtmlColumn. The latter displayed okay, but when // a value was selected it did not populate back to the HtmlInputText UIColumn column = (UIColumn) application.createComponent(javax.faces.component.html.HtmlColumn.COMPONENT_TYPE); column.setId(FacesUtils.createUniqueId()); suggestionBox.getChildren().add(column); // Output text box UIComponent columnText = application.createComponent(HtmlOutputText.COMPONENT_TYPE); columnText.setId(FacesUtils.createUniqueId()); ValueBinding valueBinding = application.createValueBinding("#{_internal}"); columnText.setValueBinding("value", valueBinding); column.getChildren().add(columnText); return stubComponent; } } return null; }
/** Transfer tag attributes to component properties. */ protected void setProperties(UIComponent _component) { super.setProperties(_component); if (doctypePublic != null) { if (isValueReference(doctypePublic)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(doctypePublic); _component.setValueBinding("doctypePublic", _vb); } else { _component.getAttributes().put("doctypePublic", doctypePublic); } } if (doctypeRoot != null) { if (isValueReference(doctypeRoot)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(doctypeRoot); _component.setValueBinding("doctypeRoot", _vb); } else { _component.getAttributes().put("doctypeRoot", doctypeRoot); } } if (doctypeSystem != null) { if (isValueReference(doctypeSystem)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(doctypeSystem); _component.setValueBinding("doctypeSystem", _vb); } else { _component.getAttributes().put("doctypeSystem", doctypeSystem); } } if (output != null) { if (isValueReference(output)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(output); _component.setValueBinding("output", _vb); } else { _component.getAttributes().put("output", output); } } if (prettyPrinting != null) { if (isValueReference(prettyPrinting)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(prettyPrinting); _component.setValueBinding("prettyPrinting", _vb); } else { _component.getAttributes().put("prettyPrinting", prettyPrinting); } } if (converter != null) { if (isValueReference(converter)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(converter); _component.setValueBinding("converter", _vb); } else { Converter _converter = FacesContext.getCurrentInstance().getApplication().createConverter(converter); _component.getAttributes().put("converter", _converter); } } if (value != null) { if (isValueReference(value)) { ValueBinding _vb = getFacesContext().getApplication().createValueBinding(value); _component.setValueBinding("value", _vb); } else { _component.getAttributes().put("value", value); } } }
public void applyMetadata(FaceletContext ctx, Object instance) { ((UIComponent) instance) .setValueBinding( "converter", new LegacyValueBinding(attr.getValueExpression(ctx, Converter.class))); }
protected void setProperties(UIComponent component) { super.setProperties(component); FacesContext context = FacesContext.getCurrentInstance(); if (value != null) { if (isValueReference(value)) { ValueBinding vb = getFacesContext().getApplication().createValueBinding(value); component.setValueBinding("value", vb); // vb.getValue(context); } else { ((UIData) component).setValue(value); } } if (var != null) { if (isValueReference(var)) { ValueBinding vb = getFacesContext().getApplication().createValueBinding(var); component.setValueBinding("var", vb); } else { ((UIData) component).setVar(var); } } if (width != null) { if (isValueReference(width)) { ValueBinding vb = getFacesContext().getApplication().createValueBinding(width); component.setValueBinding("width", vb); } else { component.getAttributes().put("width", width); } } if (rowSize != null) { if (isValueReference(rowSize)) { ValueBinding vb = context.getApplication().createValueBinding(rowSize); component.setValueBinding("rowSize", vb); } else { component.getAttributes().put("rowSize", rowSize); } } if (pageSize != null) { if (isValueReference(pageSize)) { ValueBinding vb = context.getApplication().createValueBinding(pageSize); component.setValueBinding("pageSize", vb); } else { component.getAttributes().put("pageSize", pageSize); } } if (pageSetting != null) { if (isValueReference(pageSetting)) { ValueBinding vb = getFacesContext().getApplication().createValueBinding(pageSetting); component.setValueBinding("pageSetting", vb); PageSetting setting = (PageSetting) vb.getValue(context); if (rowSize == null || "".equals(rowSize)) { rowSize = (String) getComponentInstance().getAttributes().get("rowSize"); if (rowSize == null || "".equals(rowSize)) rowSize = "10"; } int m = Integer.parseInt(rowSize); if (m < 1) m = 10; setting.setRowOfPage(m); if (pageSize == null || "".equals(pageSize)) { pageSize = (String) getComponentInstance().getAttributes().get("pageSize"); if (pageSize == null || "".equals(pageSize)) pageSize = "10"; } m = Integer.parseInt(pageSize); if (m < 1) m = 10; setting.setPageOfScreen(m); } else { component.getAttributes().put("pageSetting", pageSetting); } } if (actionBinding != null) { component.getAttributes().put("actionBinding", actionBinding); } } // setProperties()
@SuppressWarnings("deprecation") public UIComponent processWidget( UIComponent component, String elementName, Map<String, String> attributes, UIMetawidget metawidget) { // Actions don't get converters if (ACTION.equals(elementName)) { return component; } // Recurse into stubs... if (component instanceof UIStub) { // ...whose children have the same value binding as us... // // (this is important because choice of Converter is based off the attributes Map, and // if the value binding is different then all bets are off as to the accuracy of the // attributes) javax.faces.el.ValueBinding valueBinding = component.getValueBinding("value"); if (valueBinding != null) { String expressionString = valueBinding.getExpressionString(); List<UIComponent> children = component.getChildren(); for (UIComponent componentChild : children) { javax.faces.el.ValueBinding childValueBinding = componentChild.getValueBinding("value"); if (childValueBinding == null) { continue; } if (!expressionString.equals(childValueBinding.getExpressionString())) { continue; } // ...and apply the Converter to them processWidget(componentChild, elementName, attributes, metawidget); } } return component; } // Ignore components that cannot have Converters if (!(component instanceof ValueHolder)) { return component; } // Defer evaluation of EL-based converters, else we will fail trying to store/restore them // from the ViewState ValueHolder valueHolder = (ValueHolder) component; String converterId = attributes.get(FACES_CONVERTER); if (converterId != null && FacesUtils.isExpression(converterId)) { FacesContext context = FacesContext.getCurrentInstance(); component.setValueBinding( "converter", context.getApplication().createValueBinding(converterId)); return component; } // Standard Converter valueHolder.setConverter(getConverter(valueHolder, attributes)); return component; }