3 Replies Latest reply on Jul 12, 2007 9:42 AM by Bryan Babula

    Dynamically create Richfaces toolbar/dropdown menu from back

    Bryan Babula Newbie

      we've been trying to create a menu dynamically from a bean. we are having no luck and found no specific examples on doing this anywhere on the internet. Has anybody done this? if so, can you point us to an example on how to do this?

      thank you very much
      Bryan

        • 1. Re: Dynamically create Richfaces toolbar/dropdown menu from
          Sergey Smirnov Master

          If you look at any unit test used for testing components you can see how they created dynamically there.
          http://anonsvn.jboss.org/repos/richfaces/branches/3.0.2/richfaces/

          path:

          <component>/src/test/<package>/component/<name>ComponentTest.java
          

          For example: http://tinyurl.com/yqtlrz

          Take the data from your model and you get what you desire to have.



          • 2. Re: Dynamically create Richfaces toolbar/dropdown menu from
            Bryan Babula Newbie

            thanks for the reply, this did help but we are still having problems.
            we created the bean and just want to return a blank toolbar, just to do as little as possible to see if it works. we got the following error ( i'm pasting the html, the error we get and the bean underneath.

            again, thanks for your reply, it definetly pointed us in the right direction.
            thanks

            error we get is:
            Component frmMain:toolbarmain not instance of org.richfaces.component.UIToolBar

            html
            <rich:toolBar id="toolbarmain" binding="#{applicationUserSession.menubar}" />

            bean
            package com.medrisk.seam.POC;
            import java.io.Serializable;
            import java.util.ArrayList;
            import java.util.List;
            import javax.ejb.Remove;
            import javax.ejb.Stateful;
            import javax.faces.application.Application;
            import javax.faces.context.FacesContext;
            import javax.persistence.EntityManager;
            import javax.persistence.PersistenceContext;
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Destroy;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Scope;
            import org.richfaces.component.UIDropDownMenu;
            import org.richfaces.component.UIToolBar;
            import org.richfaces.component.html.HtmlToolBar;
            import org.richfaces.component.html.HtmlDropDownMenu;
            @Stateful
            @Name("applicationUserSession")
            @Scope(ScopeType.SESSION)
            public class ApplicationUserSession implements Serializable, IApplicationUserSession {
            /**
            *
            */
            private static final long serialVersionUID = -2919659648259413602L;

            private HtmlToolBar fileMenu;
            @In
            private FacesContext facesContext;
            @PersistenceContext
            private EntityManager em;
            /* (non-Javadoc)

            * @see com.medrisk.common.website.IApplicationUserSession#getFileMenu()

            */
            private void buildFileMenu(){
            fileMenu = new HtmlToolBar();
            }
            @Destroy @Remove
            public void destroy() {}
            public HtmlToolBar getMenubar() {
            if (fileMenu ==null){
            buildFileMenu();
            }
            return fileMenu;
            }
            public void setMenubar(HtmlToolBar menubar) {
            this.fileMenu = menubar;
            }
            }


            • 3. Re: Dynamically create Richfaces toolbar/dropdown menu from
              Bryan Babula Newbie

              we found the problem. the problem was because we had the richfaces jar in 2 places. when we originally started, we had it in the .war file since we were only using it for the website. but then when we wanted to create it using a bean, we needed to add the richfaces jar to the ear so the ejb server could reference it so we could use it in the beans. What we forgot to do was remove it from the war. so basically, the bean was using one jar while the website was using another one and it no likey that....
              removing it from the war and having them both use it from the ear worked.

              Thanks for your help getting us started in the right direction.