4 Replies Latest reply on Aug 19, 2008 6:12 AM by dreu zel

    How to build rich:HtmlSuggestionBox dynamically

    Stephen More Newbie

      I am pretty close to gettting this working.
      My drop down is not displaying the text of the selection, can anyone see the error ?


      org.apache.myfaces.component.html.ext.HtmlInputText searchBox =
       new org.apache.myfaces.component.html.ext.HtmlInputText();
       searchBox.setId( "inputQuery" );
       bar.getChildren().add( searchBox );
      
       org.richfaces.component.html.HtmlSuggestionBox suggestions =
       new org.richfaces.component.html.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" );
      
       javax.faces.el.ValueBinding resultBinding = app.createValueBinding( "#{result.text}" );
       suggestions.setFetchValue( resultBinding );
       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.component.html.ext.HtmlOutputText();
       text.setId( "text1" );
      
       javax.faces.el.ValueBinding vb = app.createValueBinding( "#{result.text}" );
       text.setValueBinding( "results", vb );
       column.getChildren().add( text );
       suggestions.getChildren().add( column );
       bar.getChildren().add( suggestions );


        • 1. Re: How to build rich:HtmlSuggestionBox dynamically
          Stephen More Newbie

          This is now working !

          org.apache.myfaces.component.html.ext.HtmlInputText searchBox = new org.apache.myfaces.component.html.ext.HtmlInputText();
           searchBox.setId( "inputQuery" );
           bar.getChildren().add( searchBox );
          
           org.richfaces.component.html.HtmlSuggestionBox suggestions = new org.richfaces.component.html.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.component.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 );
          


          • 2. Re: How to build rich:HtmlSuggestionBox dynamically
            Sergey Smirnov Master

            It looks like you was really close :-)

            P.S. I will add this code to the cookbook

            • 3. Re: How to build rich:HtmlSuggestionBox dynamically
              Mariappan Pandy Newbie

              Can you post entire source code for this componet?

              • 4. Re: How to build rich:HtmlSuggestionBox dynamically
                dreu zel Novice

                code is old and uses obsolete createMethodBinding

                Does someone has improved code