2 Replies Latest reply on Jan 28, 2010 6:06 PM by bp2s

    Creating a non-deprecated rich:dropDownMenu dynamically

    bp2s

      ref: http://community.jboss.org/thread/6678?tstart=0

       

      hi

      i followed the thread above to the end, and the one full example code included worked ok on my system and looks nice, but includes deprecated code.

       

      can anyone include a full example of how to do a rich:dropDownMenu dynamically, including both jsp and non-deprecated server side code so i can see how it's done?

       

      thanks ia

      mark

        • 1. Re: Creating a non-deprecated rich:dropDownMenu dynamically
          bp2s

          This seems to have done it:

           

              public HtmlDropDownMenu getNodeMenu()
          

           

              {
                  HtmlDropDownMenu menu = new HtmlDropDownMenu();
                  menu.setValue( "Node Select" );
          
                  HtmlMenuItem menuItem = new HtmlMenuItem();
                  // TODO programmatically pass from getNodes into a String[] rather than an ArrayList of SelectItems
                  String subOption = "myitem";            
                  menuItem.setValue( subOption );
          
                  Application app = FacesContext.getCurrentInstance().getApplication();
                  MethodExpression methodExpression = app.getExpressionFactory().createMethodExpression(
                           FacesContext.getCurrentInstance().getELContext(), 
                           "#{BackingBean.onItemClick}", 
                           null, 
                           new Class[] { ActionEvent.class });
                  menuItem.setActionExpression(methodExpression);
          
                  menu.getChildren().add( menuItem );
                  return( menu );
              }
          
              public void onItemClick( ActionEvent event )
              {
                  Object obj = event.getSource();
          
                  if( obj instanceof HtmlMenuItem )
                  {
                      HtmlMenuItem item =    (HtmlMenuItem)obj;
                      if( item != null )
                      {
                          lastItem = item.getValue().toString();
                          logger.info("lastItem selected is " + lastItem);
                      }
                  }
              }
          
          
          • 2. Re: Creating a non-deprecated rich:dropDownMenu dynamically
            bp2s

            oh, and in your jsp:

                            <h:form>
                                <rich:dropDownMenu binding="#{PrismBacking.nodeMenu}">
                                </rich:dropDownMenu>
                            </h:form>