6 Replies Latest reply on Jan 11, 2010 6:33 PM by Daniel Tavares

    suggestionbox dynamically

    Daniel Tavares Newbie

      Hello.

       

      Im trying add a suggestionbox dynamically, but it does not work. I know this page: http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/faq/faq.html#d0e692, but  i think it need a update since the method setSuggestionAction does not accept MethodBinding. I think this is the problem in my code. See:

       

                HtmlSuggestionBox suggestions = new HtmlSuggestionBox();
                suggestions.setId(getId()+"_suggest");
                suggestions.setFor(getId()+"_ds");
                suggestions.setUsingSuggestObjects(true);
                suggestions.setSuggestionAction(createMethodExpression(
                                            "myBean.autocomplete", 
                                            ctx, 
                                            null ,new Class[]{java.lang.Object.class}));
                suggestions.setVar( "result" );
      
      ....// add columns and other things
      
      
           protected MethodExpression createMethodExpression(String expression, FacesContext ctx, Class<?> returnType, Class<?>[] parans){
                return ctx.getApplication().getExpressionFactory().createMethodExpression(
                                                                                                          ctx.getELContext(),
                                                                                                          "#{"+expression+"}", 
                                                                                                          returnType,
                                                                                                          parans);
      
           }
      
      

       

       

      What is wrong? i`ve noticed that some html representing the suggest was added, but the action neve is called.

       

      (ps: i already change the return type to List.class, in the methodexpression, but did not work too.)

       

      thanks!

        • 1. Re: suggestionbox dynamically
          Nick Belaevski Master

          Hi,

           

          Expression string should be "#{myBean.autocomplete}".

          • 2. Re: suggestionbox dynamically
            Daniel Tavares Newbie

            thanks for replying me, but i think this is not the problem, i concat the "#{" and "}" in the method that create the expression.

             

            it not work yet

            • 3. Re: suggestionbox dynamically
              Srikanth Chakravarthy Newbie

              Hi,

               

              While creating the method expression, the parameter order is wrong according to the code you  have posted. it should be createMethodExpression(ctx,"#{myBean.autoComplete}",and the rest of the params....

               

              Regards,

              Srikanth

              • 4. Re: suggestionbox dynamically
                Daniel Tavares Newbie
                i think it is ok. the faces context is my secound param, and i concat the strings to make the expression correct.
                • 5. Re: suggestionbox dynamically
                  Srikanth Chakravarthy Newbie

                  Sorry, that was my mistake...by oversight I did not see the other method you had posted.

                   

                  But could you tell what does not happen? The event itself does not get called or the fetched value is not populated?

                   

                  I assume you are adding the suggestion box component to the heirarchy of a form. Once of the reasons I have seen for the action not getting called is that the component does not have a form up in its heirarchy.

                   

                  Regards,

                  Srikanth

                  • 6. Re: suggestionbox dynamically
                    Daniel Tavares Newbie

                    There is nothing wrong with the code i've posted.

                     

                    the problem is that i was creating the input element dynamically to and it was't redering the id.

                     

                    Let me explain: I want create a component that create a input and sujention in a single tag. i created the input component like this:

                     

                         dsinput =  (UIInput) ctx.getApplication().createComponent(UIInput.COMPONENT_TYPE);
                         dsinput.setId(getId()+"_ds");
                    ...
                    

                     

                    the input was added, but withou id. Why? becase this in com.sun.faces.renderkit.html_basic.HtmlBasicRenderer .

                             protected boolean shouldWriteIdAttribute(UIComponent component) {
                    
                                 String id;
                                 return (null != (id = component.getId()) &&
                                             !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX));
                    
                             }
                    

                     

                    the solution? simple! i just added a prefix to the input id. it is working!

                     

                    Thanks for the help!