Creating suggestionBox dynamically
This is a working example:
org.apache.myfaces.component.html.ext.HtmlInputText searchBox = new org.apache.myfaces.component.htm l.ext.HtmlInputText(); searchBox.setId( "inputQuery" ); bar.getChildren().add( searchBox ); org.richfaces.component.html.HtmlSuggestionBox suggestions = new org.richfaces.component.htm l.HtmlSuggestionBox(); suggestions.setId( "sugg" ); suggestions.setFor( "inputQuery" ); suggestions.setTokens( ",[" ); suggestions.setRules( "none" ); javax.faces.el.MethodBinding mb = app.createMethodBinding( "#{suggestionBox.autocomplete}", new Class[] { Object.class } ); suggestions.setSuggestionAction( mb ); suggestions.setVar( "result" ); suggestions.setRows( 0 ); suggestions.setFirst( 0 ); suggestions.setMinChars( "#{suggestionBox.minchars}" ); suggestions.setShadowOpacity( "4" ); suggestions.setBorder( "1" ); suggestions.setWidth( "200" ); suggestions.setHeight( "150" ); suggestions.setShadowDepth( "4" ); suggestions.setCellpadding( "2" ); org.apache.myfaces.custom.column.HtmlSimpleColumn column = new org.apache.myfaces.custom .column.HtmlSimpleColumn(); column.setId( "col1" ); org.apache.myfaces.component.html.ext.HtmlOutputText text = new org.apache.myfaces.c omponent.html.ext.HtmlOutputText(); text.setId( "text1" ); javax.faces.el.ValueBinding vb = app.createValueBinding( "#{result.text}" ); text.setValueBinding( "value", vb ); column.getChildren().add( text ); suggestions.getChildren().add( column ); bar.getChildren().add( suggestions );
Source: JBoss RichFaces forum, mores
Comments