views:

389

answers:

2

Hi!

I understand, how to set action to rich:menuItem component, but can i somehow set action on rich:dropDownMenu? Parameter action cannot be set in rich:dropDownMenu component, only in dropDownMenus child rich:menuItem. Maybe there is another approach?

Action setting to rich:menuItem:

<rich:menuItem submitMode="server" value="#{msg.someValue}" action="#{billdoc.list}">

I need to execute some action #{billdoc.someAction}, when user clicks on dropDownMenu.

+1  A: 

If you are really sure you need this (it's rather strange), you can use <rich:dropDownMenu onexpand="myFunction()", and define myFunction as:

<a4j:jsFunction name="myFunction" action="#{billdoc.someAction}" />
Bozho
Dropdownmenu hasn't onClick method?
Yurish
it seems it doesn't have. But why not use onexpand?
Bozho
I have menu which can be represented as:Documents -> Bills, Contracts. When user clicks on Bills, he gets list with bill documents, when contracts, then contract documents. But when he clicks on Documents itself, he gets list with bills and contracts. Now i have Bills and Contracts as menuItems, but Documents as dropDownMenu.
Yurish
Get it this way, if user clicks on Bills, then Bills got selected, and a `onchange` event got fired, isn't it? Then on `onchange` event you can call a function, which would get the selected item, and based on that show the appropriate thing. i.e. if selected item is Bills, show Bill documents, etc.. Hope this made the thing clear.
Adeel Ansari
Not exactly. dropDownMenu doesn't have onchange property.
Yurish
A: 

As far as I understand, its a HTML side limitation. We don't have onclick kinda events on menu item of a selet item list. The response from Bozho, might work, but what if you want different actions on different items, I am afraid. And its something like onclick, its just that it would occur half of the time of onclick event, typically.

What you can do is, invoke a method on onchange event, and check the selected value there, and based on that do whatever you would like to.

Well get it this way, if user clicks on Bills, then Bills got selected, and a onchange event got fired, isn't it? Then on onchange event you can call a function, which would get the selected item, and based on that show the appropriate thing. i.e. if selected item is Bills, show Bill documents, etc.. Hope this made the thing clear.

Cheers.

Adeel Ansari
Maybe you can recommend another approach, how can i make something like this?
Yurish
See my addendum.
Adeel Ansari