Hi,

I sent this email a few days ago ...

I implemented the actionListener for JSCookMenu. Get the latest
version from SVN or use nightly build to get the new feature.
Attached you will find an example.

1) Example 1  Static
<t:navigationMenuItem id="nav_2"
    actionListener="#{navigationMenu.actionListener}"
    itemLabel="#{example_messages[
'nav_Home']}"
    itemValue="go_home"
    action="go_home"/>
The actionListener JSCookMenuBean.actionListener(ActionEvent event)
will be executed. HtmlCommandJSCookMenu is now holding the itemValue
of the clicked menu entry. Additionaly the action attribute may be
given to trigger a page navigation.

2) Example 2 Dynamic
Shows how to generate menu items 'dynamically' by using
NavigationMenuItem(s) + how to define an ActionListener per item (see
JSCookMenuBean.getJSCookMenuNavigationItems())
The actionListener JSCookMenuBean.actionListener(ActionEvent event)
will be executed. HtmlCommandJSCookMenu is now holding the value that
was set for the NavigationMenuItem (see
JSCookMenuBean.getMenuNaviagtionItem(...))

Cheers
Thomas

On 12/23/05, Martin Marinschek <[EMAIL PROTECTED]> wrote:
> I think that Thomas Spiegl has worked on this and that it should be
> available in the current codebase.
>
> regards,
>
> Martin
>
> On 12/23/05, Saumil Mehta <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > Hello,
> >
> >
> >
> > I asked about this earlier, and was told that you cannot attach
> > actionListener methods to NavigationMenuItem objects nested within a
> > JSCookMenu (whereas you *can* do this with controls like tree2 and
> > PanelNavigation2).
> >
> >
> >
> > Any idea if there is going to be any work towards this in the near future?
> > If not, does anybody have any off-the-cuff of how much work it would be to
> > extend JSCookMenu to accommodate actionListener?
> >
> >
> >
> > Thanks so much for your time, and happy holidays to all.
> >
> >
> >
> > -Saumil
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>


--
http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Attachment: jscookmenu.jsp
Description: Binary data

/*
 * Copyright 2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.myfaces.examples.misc;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.custom.navmenu.NavigationMenuItem;
import org.apache.myfaces.custom.navmenu.jscookmenu.HtmlCommandJSCookMenu;

import javax.faces.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Thomas Spiegl
 */
public class JSCookMenuBean {
    private static final Log log = LogFactory.getLog(JSCookMenuBean.class);
    
    public List getJSCookMenuNavigationItems()
    {
        List menu = new ArrayList();
        menu.add(getMenuNaviagtionItem("Home", "go_home"));
        return menu;
    }
    
    private static NavigationMenuItem getMenuNaviagtionItem(String label, String action)
    {
        NavigationMenuItem item = new NavigationMenuItem(label, action);
        item.setActionListener("#{navigationMenu.actionListener}");
        item.setValue(label);
        return item;
    }
    
    public String actionListener(ActionEvent event)
    {
        String outcome = (String)((HtmlCommandJSCookMenu) event.getComponent()).getValue();
        log.info("ActionListener: " + outcome);
        return outcome;
    }
}



Reply via email to