Hi,

I'm trying to implement a pretty simple menu structure that supposed to update 
the menu tree when a given link is clicked and also update the content of the 
page. I've got it working but only for the first click...
First time I click on one of the given links the tree expands to show the sub 
menu and the content div (main_content) updates to display the name of the link 
that the user has selected. Problem is when I then click on another link 
nothing happens. If I refresh the page then I can click on another link again.

Any ideas as to what I'm doing wrong?

Also for the EventListeners is there a neater way of working out which link has 
been clicked rather than adding in all the elements to the EventListener 
annotation? It's not really a sustainable solution once the menu structure gets 
bigger. Ideally I'd want to pass through a parameter link you do with a regular 
listener (e.g. the parameters definition on a DirectLink) but I can't see where 
I could define this.

Relevant parts of html, page and java files are attached. I'm using the 4.1.1 
snapshot on Tomcat 5.0.1.9 with Firefox.

Thanks,

Dom

Home.html

<div jwcid="[EMAIL PROTECTED]" element="literal:div">
<ul jwcid="menuItems">
  <li>
    <a jwcid="@Any"
       id="ognl:currentMenuItem.id"
       element="literal:a">
      <span jwcid="@Insert" value="ognl:currentMenuItem.name"/>
    </a>
    <span jwcid="@If"
          condition="ognl:currentMenuItem.expanded">
      <ul jwcid="subMenuItems">
        <li>
          <a jwcid="@Any"
             id="ognl:currentSubMenuItem.id"
             element="literal:a">
            <span jwcid="@Insert" value="ognl:currentSubMenuItem.name"/>
          </a>
        </li>
      </ul>
    </span>
  </li>
</ul>
</div>

<div jwcid="[EMAIL PROTECTED]" element="literal:div">
<div jwcid="@Insert" value="ognl:selectedPage"></div>
</div>

Home.page

    <property name="currentMenuItem"/>
    <component id="menuItems" type="For">
      <binding name="source"  value="menuItems"/>
      <binding name="element" value="literal:ul"/>
      <binding name="value"   value="currentMenuItem"/>
    </component>
    <property name="currentSubMenuItem"/>
    <component id="subMenuItems" type="For">
      <binding name="source"  value="currentMenuItem.subMenus"/>
      <binding name="element" value="literal:ul"/>
      <binding name="value"   value="currentSubMenuItem"/>
    </component>

Home.java

    @Persist("session")
    public abstract List<MenuItem> getMenuItems();
    public abstract void setMenuItems(List<MenuItem> items);

    @Persist("session")
    public abstract String getSelectedPage();
    public abstract void setSelectedPage(String page);

    @EventListener(events="onclick",
                   elements={"introduction", "research", "biographies"},
                   async=true)
    public void menuSelect(BrowserEvent event){
        String menu = (String)event.getTarget().get("id");
        setSelectedPage(menu);

        List<MenuItem> items = getMenuItems();
        for (Iterator iter = items.iterator(); iter.hasNext();) {

            MenuItem element = (MenuItem) iter.next();
            if(element.getId().equals(menu)){
                element.setExpanded(true);
            } else {
                element.setExpanded(false);
            }
        }
        getRequestCycle().getResponseBuilder().updateComponent("main_menu");
        getRequestCycle().getResponseBuilder().updateComponent("main_content");
    }

    @EventListener(events="onclick",
                   targets = "article_1, article_2, article_3",
                   async=true)
    public void subMenuSelect(BrowserEvent event){
        setSelectedPage((String)event.getTarget().get("id"));

        getRequestCycle().getResponseBuilder().updateComponent("main_content");
    }

--
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error) please 
notify the sender immediately and destroy this e-mail. Any unauthorized 
copying, disclosure or distribution of the material in this e-mail is strictly 
forbidden.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to