1 Reply Latest reply on Jan 8, 2009 6:16 AM by nbelaevski

    Call action method before refreshing component from binding?

    g.i.joe

      I'm using a dynamically created HtmlDropDownMenu. The menu is created by a bean and loaded by binding it with "<rich:dropDownMenu binding="#{...". I've had some problems creating this, but now everything works fine.

      The only problem I still have is that the setter method for the menu binding gets called before the method expression bound to the menu items. This is a problem, because I want to hide items once they were clicked. But to do this the method expression would have to be executed before the binding method.
      I've tried setting immediate and bypassUpdates to true, but this doesn't help.

      Here's the source code:

      <rich:dropDownMenu id="dropDownShowColumns" submitMode="ajax" binding="#{searchService.availableShowColumnsDropDownMenu}"/>


      public void setAvailableShowColumnsDropDownMenu(final HtmlDropDownMenu menu){
       this.updateAvailableShowColumnsDropDownMenu(menu);
      }
      
      public HtmlDropDownMenu getAvailableShowColumnsDropDownMenu(){
       final HtmlDropDownMenu menu = new HtmlDropDownMenu();
       menu.setValue(">>");
      
       final FacesContext fc = FacesContext.getCurrentInstance();
       final ExpressionFactory ef = fc.getApplication().getExpressionFactory();
      
       for(final AbstractShowColumn column : availableShowColumns){
       final HtmlMenuItem item = new HtmlMenuItem();
       final String name = column.getName();
       item.setValue(name);
       item.setSubmitMode("ajax");
       item.setReRender("tickets");
      
       final MethodExpression me = ef.createMethodExpression(fc.getELContext(), "#{searchService.addShowColumnByName('" + name + "')}", null, new Class[]{String.class});
       item.setActionExpression(me);
      
       menu.getChildren().add(item);
       }
      
      
       this.updateAvailableShowColumnsDropDownMenu(menu);
      
       return menu;
      }
      
      private void updateAvailableShowColumnsDropDownMenu(final HtmlDropDownMenu menu){
       final Set<String> visible = new HashSet<String>();
       for(final AbstractShowColumn col : this.getAvailableShowColumns())
       visible.add(col.getName());
      
       for(final UIComponent c : menu.getChildren())
       if(c instanceof HtmlMenuItem)
       c.setRendered(visible.contains(((HtmlMenuItem)c).getValue().toString()));
      }