-
1. Re: How to build rich:dropDownMenu dynamically
sergeysmirnov Jun 14, 2007 9:39 AM (in response to tomarenz)You can create any components hierarchy using JSF API. rich:dropDownMenu and rich:menuItem are both standard JSF components. So, the common approach is acceptable.
-
2. Re: How to build rich:dropDownMenu dynamically
tomarenz Jun 14, 2007 10:53 AM (in response to tomarenz)Sergey, I need to create rich:dropDownMenu the normal way, e.g. included into an .xhtml component (I use Facelets).
Only item contents should be create dynamically. I guess I can use the binding attribute from rich:dropDownMenu, then attach java-created items to it from inside the bean.
Is that correct or is there another approach ? -
3. Re: How to build rich:dropDownMenu dynamically
tomarenz Jun 14, 2007 2:10 PM (in response to tomarenz)As a further hint, the component HtmlDropDownMenu has no method/attribute to deal with item contents, even if I can create it from bean binding.
Value get/set manage the text label, according to docs.
I don't see any way to deal with menu contents from java. -
4. Re: How to build rich:dropDownMenu dynamically
byarger Jun 14, 2007 5:43 PM (in response to tomarenz)I think you should be able to create new HtmlMenuItems and add them to the children collection of the HtmlDropDownMenu using a standard JSF component approach. Something like:
// assuming you have a dropDownMenu variable already Application app = FacesContext.getCurrentInstance().getApplication(); HtmlMenuItem item= (HtmlMenuItem) app.createComponentHtmlMenuItem.COMPONENT_TYPE); item.setId("..."); item.setValue(".."); dropDownMenu.getChildren().add(item);
Is that what you're looking for? -
5. Re: How to build rich:dropDownMenu dynamically
tomarenz Jun 15, 2007 3:20 AM (in response to tomarenz)Yes, exactly, thanks. But why not just:
HtmlMenuItem item = new HtmlMenuItem(); item.set .... dropDownMenu.getChildren().add(item);
Moreover, when should I perform this filling ? I guess during the setter call associated to the binding attribute, not sure though.
-- Renzo -
6. Re: How to build rich:dropDownMenu dynamically
byarger Jun 15, 2007 2:09 PM (in response to tomarenz)I'm not sure what the createComponent method does, if anything, that just newing up your own object won't do, that's just how I've always seen it done.
In the setter of the binding is a good place to dynamically add them, although depending on the scope of your bean you might only need to do it if you haven't already. -
7. Re: How to build rich:dropDownMenu dynamically
tomarenz Jun 18, 2007 3:54 AM (in response to tomarenz)Thanks, I will investigate further.
Funny enough, I already have a similar solution based on Tomahawk jscookmenu, where I add menu items on the fly, using simply:item = new NavigationMenuItem(label, null); item.setValue(topic); subMenu.add(item); ...
and so on, building up the menu item tree. Unfortunately, that component doesn't support disabled (grayed) items, that's why I'm looking at rich:dropDownMenu. -
8. Re: How to build rich:dropDownMenu dynamically
consuelofranky Jul 19, 2007 5:16 PM (in response to tomarenz)Hello:
I have successfully followed your indications for building a dropDownMenu dynamically, but I have problems assigning an action to a HtmlMenuItem.
Here is the page code:<rich:dropDownMenu binding="#{menuBean.myMenu}" > </rich:dropDownMenu>
Here is the Java code in the menuBean:private HtmlDropDownMenu getMyMenu() { HtmlDropDownMenu menu = new HtmlDropDownMenu(); menu.setStyle("border:1px solid #BCD1FF"); menu.setValue("Security Actions"); HtmlMenuItem menuItem = new HtmlMenuItem(); String subOption = "Sec. Change Passsword"; menuItem.setValue(subOption); Application app = FacesContext.getCurrentInstance().getApplication(); MethodBinding mb = app.createMethodBinding ("#{otherBean.action}", null); menuItem.setAction (mb); menu.getChildren().add(menuItem); return menu; }
The problem is that the class MethodBinding and the method setAction of HtmlMenuItem class are deprecated.
Do you know another way for assigning an action to a HtmlMenuItem ?
Thanks in advance
Maria Consuelo Franky -
9. Re: How to build rich:dropDownMenu dynamically
alexsmirnov Jul 19, 2007 5:34 PM (in response to tomarenz)JSF 1.2 deprecate MethodBinding/ValueBinding classes.
For a JSF UICommand - subclasses ( DropDownMenu is extend UICommand, too ) should be used MethodExpression / setActionExpression : -
10. Re: How to build rich:dropDownMenu dynamically
sergeysmirnov Jul 19, 2007 5:38 PM (in response to tomarenz)In this context, "deprecated" means JSF 1.2 uses another way for the same thing. However, RichFaces does support both JSF 1.1 and JSF 1.2. To reach this compatibility we have to use the methods that will work in both cases (i.e the ones that marked as "deprecated").
When RichFaces starts to declare support JSF 1.2 only, it will stops to use the old methods. Currently, it is just does not make sense. -
11. Re: How to build rich:dropDownMenu dynamically
ishabalov Jul 19, 2007 5:41 PM (in response to tomarenz)you may use setActionExpression() instead.
-
12. Re: How to build rich:dropDownMenu dynamically
ishabalov Jul 19, 2007 5:43 PM (in response to tomarenz)Wow, I love the situation when all 3 of us answered!
-
13. Re: How to build rich:dropDownMenu dynamically
emsa Jul 23, 2007 4:22 AM (in response to tomarenz)I have also had some trouble doing this in a gui-designer friendly way.
Why not add a repeating-menuItem?<rich:repeatingMenuItem var="v" value="#{backing.items}"> <rich:menuItem value="#{v.label}" action="#{home.select(v.id)}" /> </rich:repeatingMenuItem>
or similar? -
14. Re: How to build rich:dropDownMenu dynamically
garypinkham Jul 25, 2007 1:20 PM (in response to tomarenz)Is there a working sample on how to do this? I was reading the Dev Guide and they show this example that just doesn't seem to be enough. :-)
... org.richfaces.component.html.HtmlMenuItem myItem = new org.richfaces.component.html.HtmlMenuItem (); ...