2 Replies Latest reply on Feb 18, 2009 8:30 PM by nbelaevski

    simpleTogglePanel onExpand event

    nkr1pt

      Hi,

      I have a simpleTogglePanel in my view, in which resides a htmlPickList.
      Initially the togglePanel is not opened.
      When the user expands the panel the htmlPickList inside it must be populated, not before, as it is a fairly expensive operation.

      I have some code at the moment, which works, in a way, but the onExpand event is always executed for some reason (during page load, expanding and collapsing), but I only want it to execute when expanding the togglePanel.

      the code:


      <rich:simpleTogglePanel
       switchType="server"
       opened="false"
       width="370"
       bodyClass="selectUsersModule"
       label="User Criteria"
       onexpand="#{selectUsersModuleBean.populateUsersPickList}">
       <rich:pickList id="usersPickList"
       value="#{selectUsersModuleBean.targetUsers}"
       showButtonsLabel="false"
       converter="UserConverter">
       <f:selectItems value="#{selectUsersModuleBean.users}" />
       </rich:pickList>
       </rich:simpleTogglePanel>
      


      and in SelectUsersModuleBean:

      private String populateUsersPickList;
      
      ...
      
      public String getPopulateUsersPickList() {
       clearUsers();
      
       for (User user : userManager.createDummyUsers()) {
       SelectItem item = new SelectItem(user, user.getUsername());
       users.add(item);
       }
      
       return null;
       }
      


      As a side question, is is normal that I have to define the onExpand method in SelectUsersMouleBean like I do?
      It feels strange...

      Any ideas?

      thx

        • 1. Re: simpleTogglePanel onExpand event
          nkr1pt

          Seems like I needed to use the actionListener attribute and bind it to a method that takes an ActionEvent parameter in the backing bean.

          I still don't know how best to differentiate between an expand and a collapse event, however

          • 2. Re: simpleTogglePanel onExpand event
            nbelaevski

            on* handlers are client-side event handlers and contain Javascript code to execute when some event happened (like common onclick attribute). These handlers are requested each time the component is rendered.

            Cast ActionEvent to org.richfaces.event.SimpleToggleEvent - then use isIsOpen() method to get new state.