8 Replies Latest reply on Mar 18, 2011 1:39 PM by Nick Belaevski

    JSF Component development with Rich SuggestionBox

    Shantanu Upadhyaya Newbie

      I'd like to write a JSF component which has :

      - rich:suggestionBox

      - some  h:inputText , and

      - some h:selectOneMenu


      Here's my stack :

      1. JSF 1.1

      2. Facelets 1.1

      3. RichFaces 3.1.6


      I've been searching everywhere to find out how I can make this into REAL component instead of ui:include.


      So far, here's what I did to make it into the "component" as one of the ways without extending UIComponent / UIComponentBase / etc    

      4. Created xhtml for the 'grouped' widgets

      5. Declared the xhtml in my taglib.xml ( in <facelet-taglib ...>   )

      6. Declared the facelet taglib in web.xml







      7. Different pages are able to use this component

                                          <my:customComponent id="someId" binding="#{pageBean.componentHandler}"

                                              eventQueue="ruleQueue" nothingLabel="No matching offers found"

                                              suggestionDelay = "500" style="width: 80%;"

                                              ........ />

      8. component xhtml takes id attrib and prepends it against all the widget id within - so that I can have 2 or more components in a page


      Problem :

      9. I don't like this approach - I'd like a real component

      10. For each tag, I need a binding i.e. a componentHandler in my page bean


      Questions :

      11. Is it possible to make a composite control like this ?

      12. If so, what will my component class extend - UIPanel or UIComponent or....

      13. Do I need a renderer ?

      14. When the suggestion fires, will it be handled by the component class ?

      15. Is there a link which properly describes what I need to do ? Or a book ? All the links I've seen have simple examples.

      16. If I extend UIComponentBase, how do I render the SuggestionBox to the ResponseWriter.

      17. When using facelets, do all component need to be declared in the facelet taglib ? Can I use other taglibs ?

      18. Since I use XHTML, is the tag writing mechanism for JSPX different ?


      Help really appreciated on this. Thank you.

        • 1. JSF Component development with Rich SuggestionBox
          Rocky S Master

          Your best bet is follow this book, Core.JavaServer.Faces.3rd.Edition. Go through chapter composite components.

          • 2. JSF Component development with Rich SuggestionBox
            Shantanu Upadhyaya Newbie

            Ok. But there got to be some pointers on this forum. Richfaces has components in itself .

            • 3. JSF Component development with Rich SuggestionBox
              Manoj Khandelwal Newbie

              I am confused here. Are you looking for facelets composite control or a JSF component which has these three inputs.

              In case if you are looking for JSF component, You have to write the component class extending to rich:suggestionBox comp class or UIInput. Since rich:suggestionBox comp class internally extend the UIInput, I would suggest you to use that as your class's parent. You have to provide the encodeBegin & encodeEnd implementation in your class or write a separate renderer itself. I always prefer writing the separate renderer to dinstinguish component with the renderer. You will be calling the individual componet renderer's respective functions in your encodeBegin/End implementation and need not to write html code in your renderer in order to put them in response writer (e.g. suggestion box renderer encodebegin, inputtext renderer encodebegin & selectmeny renderer encodebegin).

              In case if any event gets triggered from any of the component resides in composite comp, it will call the decode function in the renderer which accepts the component as parameter. You need to set the submitted values in this component entered by user from request.

              I hope it helps you.

              • 4. JSF Component development with Rich SuggestionBox
                Nick Belaevski Master

                Hi Shantanu,


                If you need to wire several existing components together, you can develop Facelets TagHandler that will create those and setup realtionships between them. Otherwise you'll need to create component class extending UIComponentBase, implement renderer, etc.

                • 5. JSF Component development with Rich SuggestionBox
                  Shantanu Upadhyaya Newbie

                  There's really nothing confusing . I'm already using the facelet templating feature to create a reusable component - points 2,5 and 6. This is with xhtml only.


                  Extending suggestion box is out of the question because I have multiple widgets withing the custom component. Suggestion box happens to be one of them.

                  • 6. JSF Component development with Rich SuggestionBox
                    Shantanu Upadhyaya Newbie



                    I did extend the UIComponentBase class and programmatically create the component. It's working but have these problems :


                    19. On reloading the page with the component, I get a duplicate id exception for the custom component. I tried the save and restore state as well.

                    20. I need to do this for the suggestion box as well

                            <a4j:ajaxListener type="org.ajax4jsf.ajax.ForceRender"/>

                            <a4j:support event="onselect" >

                                <f:setPropertyActionListener value="#{suggestedObject}" target="#{binding.suggestedObject}" />



                    Java code would be HtmlAjaxSupport.addActionListener(...);


                    There is no implementation for set property action listener in JSF 1.1 . Facelets 1.1 LegacySetPropertyListener is private in SetPropertyActionListenerHandler taghandler. I will try f:attribute.


                    It is my understanding that I don't need a renderer or a component handler.

                    • 7. JSF Component development with Rich SuggestionBox
                      Manoj Khandelwal Newbie

                      If you extend UIComponentBase class, you will end up writing the code for suggestion box funtionality which is already available to you in the component. You can still render the other widget comp after extending the rich suggestion box class. please call me if you want to discuss this in detail. I am sure we can find some solution out of that.

                      • 8. Re: JSF Component development with Rich SuggestionBox
                        Nick Belaevski Master



                        It's the job of TagHandler to create view, so I'd recommend to leave this responsibility to it. For implementing f:setPropertyActionListener: create your own version of ActionListener that will update ValueExpression.


                        If you've created composition of several JSF components then yes, renderer is not necessary.