9 Replies Latest reply on Mar 18, 2011 6:44 AM by Jesper Vrelits

    <rich:toolbar> and binding

    Jesper Vrelits Newbie



      I use RF 4-M6 and display a dropdown menu using:


      <rich:toolbar binding="#{pif_menucontroller.toolBar}"/>


      It does not work, however, but if I do:


      <rich:toolbar height="26px">

                          <rich:dropDownMenu mode="ajax">

                              <f:facet name="label">

                                  <h:panelGrid cellpadding="0" cellspacing="0" columns="2"


                                      <h:outputText value="Links"/>



                                  <rich:menuItem submitMode="none" label="RichFaces Home Page"



                                  <rich:menuItem submitMode="none" label="http://jboss.com/index.html?module=bb&op=viewforum&f=261"





                      <rich:toolbar binding="#{pif_menucontroller.toolBar}"/>


      it WORKS!


      So somehow when I only use <rich:toolbar> with the binding attribute it is as if scipt/css does not get loaded.


      It seems that the html is rendered okay (but inactive and not styled).


      Is there something I am missing here?

        • 1. <rich:toolbar> and binding
          Nick Belaevski Master

          Hi Jesper,


          I guess you are creating components incorrectly. You shoudl be using application.createComponent(FacesContext, String, String) and not 'new ComponentClass()'.

          • 2. <rich:toolbar> and binding
            Jesper Vrelits Newbie

            Hi Nick!


            Actually I use application.createComponent. Here's a code snippet:


                                if (dropDownMenu == null) {

                                    dropDownMenu = (UIDropDownMenu) app.createComponent(UIDropDownMenu.COMPONENT_TYPE);


                                    HtmlOutputText label = (HtmlOutputText) app.createComponent(HtmlOutputText.COMPONENT_TYPE);


                                    dropDownMenu.getFacets().put(UIDropDownMenu.Facets.label.name(), label);





            where 'app' is FacesContext.getCurrentInstance().getApplication();


            I've ported the code from Richfaces 3.3 where I didn't have this issue.

            • 4. <rich:toolbar> and binding
              Jesper Vrelits Newbie

              The javadoc for JSF 2.0 rev A says this:


              "... Instantiate and return a new UIComponent instance of the class specified by a previous call to addComponent() for the specified component type.


              Before the component instance is returned, it must be inspected for the presence of a ListenerFor (or ListenersFor) or ResourceDependency (or ResourceDependencies) annotation. If any of these annotations are present, the action listed in ListenerFor or ResourceDependency must be taken on the component, before it is returned from this method. This variant of createComponent must not inspect the Renderer for the component to be returned for any of the afore mentioned annotations. Such inspection is the province of createComponent(ValueExpression, FacesContext, String, String) or createComponent(FacesContext, String, String). ...."


              This is what MyFaces does, and we can't change it. Any change should be done at spec level. It is known this problem prevent JSF 2.0 resource API to work correctly on jsp case.



              • 5. <rich:toolbar> and binding
                Nick Belaevski Master

                This means that you should specify both component type and renderer type when you call createComponent. In this case it will work as expected.

                • 6. <rich:toolbar> and binding
                  Jesper Vrelits Newbie

                  Okay, tried this:


                  if (toolBar == null) {

                              FacesContext ctx = FacesContext.getCurrentInstance();

                              UIToolbar newToolBar = (UIToolbar) ctx.getApplication()

                                      .createComponent(ctx, UIToolbar.COMPONENT_TYPE, "org.richfaces.renderkit.html.ToolbarRenderer");

                              for (Module module : portal.getModules()) {

                                  addModuleMenus(ctx.getApplication(), newToolBar, module);


                              // If user is authorized to no modules, add empty dropdown to get the menubar drawn.

                              if (newToolBar.getChildren().size() == 0) {

                                  UIDropDownMenu dropDownMenu = (UIDropDownMenu) ctx.getApplication().createComponent(ctx,UIDropDownMenu.COMPONENT_TYPE,







                              toolBar = newToolBar;



                  but it didn't do any different. Do I call createComponent wrongly?

                  • 7. <rich:toolbar> and binding
                    Jesper Vrelits Newbie

                    A small bump here. Is this supposed to be able to work? I can see others have problems with bindings too.


                    I know you guys are busy with the forthcomming release but a small code example how to create a dropdown menu code and display it using the binding variable would be very appreciated.


                    We'are converting a RF 3 project and this is really a showstopper.


                    Running on Mojarra 2.1.0-b11

                    • 8. <rich:toolbar> and binding
                      Ilya Shaikovsky Master

                      Sorry for the delay :/ Plates are really full during that time Seems I get the problem source now. Actually it's just JSF 2 problem which I believe should be solved at some point by the Oracle and Apache guys. Dynamicall rendering of the components (which was at component tree before but just not rendered) works fine in JSF as it pre-renders resources for all the components even for those which are not rendered. But that is not applied to the case when the component was not present in JSF tree at all. And unfortunatelly it's your case. And the only workaround we found:


                      add <dropDownMenu rendered="false"/> to the page.

                      • 9. <rich:toolbar> and binding
                        Jesper Vrelits Newbie

                        Got it working, but I had to add all component types toolbar, dropDownMenu, MenuGroup and menuItem with rendered="false".


                        Thanks for the hint.