// // Event processing: Creates a datatable and adds a component to it. // @Override public void processEvent(SystemEvent event) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); if (!context.isPostback()) { Application application = context.getApplication(); HtmlDataTable dataTable = new HtmlDataTable(); dataTable.setVar("_internal"); dataTable.setValueExpression( "value", application .getExpressionFactory() .createValueExpression(context.getELContext(), "#{addBean.list}", Object.class)); getChildren().add(dataTable); UIColumn column = new UIColumn(); column.setId(context.getViewRoot().createUniqueId()); dataTable.getChildren().add(column); HtmlOutputText outputText = new HtmlOutputText(); outputText.setId(context.getViewRoot().createUniqueId()); outputText.setValueExpression( "value", application .getExpressionFactory() .createValueExpression(context.getELContext(), "#{_internal}", Object.class)); column.getChildren().add(outputText); } }
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; }