You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Roland Oertig <ro...@dplanet.ch> on 2005/11/04 14:09:21 UTC

help needed regarding dynamic use of NavigationMenuItem

Hi all

Can one be so kind and explain me what I'm doing wrong. I must not have
understood something!

Need help.

 

What I would like is to recognize the menu node which has been pressed by a
user in my backing bean.

In the backing bean I construct the menu dynamically as shown in the example
and get it displayed correctly in the .jsp.

When I press a menu node the action function get called. So far OK.

 

But in that function I cannot identify the menu node which has been pressed,
must say that all menu nodes call the same action function.

The idea is to either grab the instance of the pressed menu node or to find
it in the value parameter, but no way .. neither I can identify and get the
node instance or have a value set in the value slot.

 

I would appreciate if one could tell me how to identify the selected node.

Many thanks in advance.

Roland

 

Here a code snippet of the backing bean to show how I do it.

 

private SelectItem selectedNode;

public SelectItem getSelectedNode() {

                        return selectedNode;

            }

 

            public void setSelectedNode(SelectItem sNode) {

                        selectedNode = sNode;

            }

 

for (List<String> menuItems : navMenuList) {

                    String menuIndex = (String)menuItems.get(0);

.

menuNode = new NavigationMenuItem((String)menuItems.get(1),
"#{navTreeBean.actionSelectedNode}", null, false);

menuNode.setDescription(menuIndex); // misuse ID

menuNode.setValue("#{navTreeBean.selectedNode}");

mainMenuNode.add(childHeader);

.

Return menu;

 

public String actionSelectedNode() {

               ValueBinding xx = menuNode.getValueBinding("value");

               System.out.println("the UIComponent found: " + xx); // OK
found the UIComponent  #{navTreeBean.menu}

               ArrayList<NavigationMenuItem> updateBinding =
(ArrayList<NavigationMenuItem>) xx.getValue(context);

               for (NavigationMenuItem ni : updateBinding){

                           System.out.println("the NavigationMenuItem value:
" + ni.getValue());

                           NavigationMenuItem node[] =
ni.getNavigationMenuItems();

                           for (NavigationMenuItem nd : node)

                                      System.out.println("the node:" +
nd.getValue() + " id: " + nd.getDescription());

               }

               return "page selected";

            }

 

Out put of above iteration:

the NavigationMenuItem value: Users Maintenance

the node:#{navTreeBean.selectedNode} id: 2

the node:#{navTreeBean.selectedNode} id: 3

the node:#{navTreeBean.selectedNode} id: 4

the node:#{navTreeBean.selectedNode} id: 5

the NavigationMenuItem value: Resources Maintenance

the node:#{navTreeBean.selectedNode} id: 11

the node:#{navTreeBean.selectedNode} id: 12

the node:#{navTreeBean.selectedNode} id: 13

the node:#{navTreeBean.selectedNode} id: 14

the NavigationMenuItem value: Process controls

the node:#{navTreeBean.selectedNode} id: 21

the node:#{navTreeBean.selectedNode} id: 22

the node:#{navTreeBean.selectedNode} id: 23

the NavigationMenuItem value: Inspection tools

the node:#{navTreeBean.selectedNode} id: 31

the node:#{navTreeBean.selectedNode} id: 32

 

Roland Oertig

IT architect, developer and consultant

Klotenerstrasse 10

CH-8303 Bassersdorf

 


Tel. Business

+41 44 836 9061


Tel. Private

+41 44 836 8892


Mobile

+41 79 303 5759


Skype

rolandoertig


E-Mail

 <ma...@dplanet.ch> roertig@dplanet.ch