First we create a taskflow with two views and with two control flow cases
Now we can create a jsf template with the menubar where we add our menu items.
We create the menu bean and defined it as a request managed bean in the adfc-config.xml
private RichMenuBar initMenu;
public void createMenus(PhaseEvent phaseEvent) {
boolean addMenu = true;
for (Iterator iterator = initMenu.getChildren().iterator(); iterator.hasNext();) {
UIComponent component = (UIComponent) iterator.next();
if ( component.getId().equalsIgnoreCase("menuMain")){
addMenu = false;
}
}
if (addMenu) {
//Create Menu and set id and text
RichMenu menuMain = new RichMenu();
menuMain.setId("menuMain");
menuMain.setText("Main");
RichCommandMenuItem menuPage1 = new RichCommandMenuItem();
menuPage1.setId("page1");
menuPage1.setText("Page 1");
menuPage1.setActionExpression(getMethodExpression("page1"));
RichCommandMenuItem menuPage2 = new RichCommandMenuItem();
menuPage2.setId("page2");
menuPage2.setText("Page 2");
menuPage2.setActionExpression(getMethodExpression("page2"));
menuMain.getChildren().add(menuPage1);
menuMain.getChildren().add(menuPage2);
initMenu.getChildren().add(menuMain);
}
}
private MethodExpression getMethodExpression(String name) {
Class [] argtypes = new Class[1];
argtypes[0] = ActionEvent.class;
FacesContext facesCtx = FacesContext.getCurrentInstance();
Application app = facesCtx.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesCtx.getELContext();
return elFactory.createMethodExpression(elContext,name,null,argtypes);
}
private ValueExpression getValueExpression(String name) {
FacesContext facesCtx = FacesContext.getCurrentInstance();
Application app = facesCtx.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesCtx.getELContext();
return elFactory.createValueExpression(elContext, name, Object.class);
}
We are ready to create the two pages and we only have to add beforePhase attribute to f:view element.
And we are finished. Here is the 11g example project
Hi
ReplyDeleteI want to develop dynamic menu according to User Role. Display menu change according to login user. How can I implement this using Jdeveloper 11G
Hi, If I have the time I will make a new example based on the security Roles.
ReplyDeletethanks Edwin
Hi, I converted the application to 11g , and I get a error msg:
ReplyDeleteTarget Unreachable, identifier 'Menu' resolved to null
It seems the Menu bean haven't been instantiated yet.
Do you know what might have gone wrong?
Hi Please use the new menu example which works perfectly in jdev 11g production
ReplyDeletehttp://biemond.blogspot.com/2008/11/dynamic-menu-based-on-roles-database.html
Hi,
ReplyDeleteThank You for your blogs.
I create a menu bar and i added menu component in the pagetemplate,
is there a way to put some code in actionlistener or some place to call the page .
Thank you1
David Nahmias
Hi,
ReplyDeleteYou can call a managed bean with a method or add an action to a menu item.
or else explain me more what you did
Would really like to see an example of a dynamic menu based on a database table.
ReplyDeleteHi,
Deleteand here it is http://biemond.blogspot.com/2008/11/dynamic-menu-based-on-roles-database.html
hope you like it.
thanks
Hi,
ReplyDeleteThank you for you effort,
I create the menu , and its work fine.
but how i can highlight the link when it clicked?
Thnaks and regards,
Hi,
Deletemaybe add an EL expression in the styleclass attribute and read a managed bean what is the current menu item or page and then set or unset the selected css class
Thanks