You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by dian ruzda <di...@gmail.com> on 2009/06/13 02:03:06 UTC

menu

Hello all, I try to make menu control in my page, I see on example must
define on menu.xml
can I make menu control programatically on java. so I don't need to write
menu.xml again coz
I wanna make dinamic menu and relate with my dbase ?


thx

Re: menu

Posted by Bob Schellink <sa...@gmail.com>.
Cool. So you basically just install the CAS server, configure 
Spring+CAS support and away you go? No hiccups getting CAS to work?

kind regards

bob


aurmam wrote:
> i have an example how to create a menu by java
> 
> public class MenuPage {
> 	
>     private static GrantedAuthority[] UserAuthorities;
> 	
>     private static class MenuHolder {
>         private static Menu INSTANCE = createMenus();
>     }
> 
>     public static void setUserAuthorities(GrantedAuthority[]
> userAuthorities) {
> 		UserAuthorities = userAuthorities;
> 	}
> 
> 	public static Menu getMenus() {
> 		return MenuHolder.INSTANCE;
>     }
> 
>     @SuppressWarnings("unchecked")
> 	private static Menu createMenus() {
>     	
> 		Menu rootMenu = new Menu("rootMenu");
> 		Menu menu;
> 		Menu subMenu;
> 
> 		menu = createMenu("Home", "home.htm","/assets/images/home.png");
> 	    rootMenu.getChildren().add(menu);
> 
>         menu = createMenu("Task Manager","#","/assets/icons/book_open.png");
>         rootMenu.getChildren().add(menu);
>         	
> 	        subMenu = createMenu("List tasks", "taskmanager/list-tasks.htm");
> 	        menu.getChildren().add(subMenu);
> 	        
> 	        subMenu = createMenu("Add new Task",
> "taskmanager/add-new-task.htm");
> 	        menu.getChildren().add(subMenu);
> 	        
> 	        subMenu = createMenu("Phone Book", "phonebook/phonebook.htm");
> 	        menu.getChildren().add(subMenu);
> 
> 	        subMenu = createMenu("Add New Phone",
> "phonebook/add-new-phone.htm");
> 	        menu.getChildren().add(subMenu);	        
> 	        
> 	    menu = createMenu("Administration","#","/assets/icons/book_open.png");
> 	    rootMenu.getChildren().add(menu);
> 	    	
> 	    	subMenu = createMenu("Create new
> User","administration/create-user.htm");
> 	    	menu.getChildren().add(subMenu);	
> 	    	subMenu = createMenu("Create new Role","user/user.htm");
> 	    	menu.getChildren().add(subMenu);
> 	    	
> 	    	if (userHasAuthority(Permission.TEST)) {
> 	    		subMenu = createMenu("Asign Roles","user/user.htm");
> 	    		menu.getChildren().add(subMenu);
> 	    	}
> 	    
> 		return rootMenu;
> 
> 	}
> 	
>     @SuppressWarnings("unused")
> 	private static Menu createMenu(String label) {
>         Menu menu = new Menu();
>         menu.setLabel(label);
>         menu.setTitle(label);
>         return menu;
>     }
> 
>     private static Menu createMenu(String label, String path) {
>         Menu menu = new Menu();
>         menu.setLabel(label);
>         menu.setPath(path);
>         menu.setTitle(label);
>         return menu;
>     }
> 
>     private static Menu createMenu(String label, String path, String
> IconPath) {
>         Menu menu = new Menu();
>         menu.setLabel(label);
>         menu.setPath(path);
>         menu.setTitle(label);
>         menu.setImageSrc(IconPath);
>         return menu;
>     }
>     
>     public static boolean userHasAuthority(String authority) {
>         for (int i = 0; i < UserAuthorities.length; i++) {
>             if (authority.equals(UserAuthorities[i].getAuthority())) {
>                 return true;
>             }
>         }
> 
>         return false;
>     }
>     
> }
> 
> and from BorderPage you can call
> 
> 	public void onInit() {
> 		super.onInit();
> 		if (hasPermission(Permission.LOGIN)) {
> 			MenuPage.setUserAuthorities(getAuthorities());
> 			rootMenu = MenuPage.getMenus();
> 		}
>         }
> 
> i am using spring security + CAS all authorities are being read from mysql
> database
> 
> 


Re: menu

Posted by Bob Schellink <sa...@gmail.com>.
On 2/02/2010 06:00 PM, WarnerJan Veldhuis wrote:
> The menu is indeed cached, but only if your "mode" element in click.xml
> is set to "production" or "profile".


Indeed, the menu is cached if it is read from the menu.xml file. It sounded though as if the menu is 
constructed from the database? In that case I would expect the menu's to be build up in Java code. 
My guess is that the menus are cached in a static variable perhaps?

kind regards

bob


>
>
>
> On 02-Feb-10 07:36, aurmam wrote:
>> i have this example and just now i have a problem
>>
>> when i deploy application everything is ok.
>> i get the menu
>>
>> but when i change the value in database...
>> and assign another authority, i relogin to the application but i get
>> the old
>> menu.
>>
>> when i rediploy it the menu changes...
>>
>> can anybody say where the problem could appear?
>>
>> it seems the menu is being cached
>


Re: menu

Posted by aurmam <au...@gmail.com>.
my click.xml file is

<?xml version="1.0" encoding="UTF-8"?> 
<click-app> 
    <pages package="lt.seb.portfolio">
        <page classname="HomePage" path="home.htm"/>
        <page classname="Logout" path="secure/logout.htm" />
        <page classname="CasFailed" path="casfailed.jsp"/>
        <page classname="BorderPage" path="border-template.htm"/>
    </pages>
    <mode value="debug"/>
</click-app>

-- 
View this message in context: http://n2.nabble.com/menu-tp3070583p4499372.html
Sent from the click-user mailing list archive at Nabble.com.

Re: menu

Posted by WarnerJan Veldhuis <wa...@qprcostcontrol.com>.
The menu is indeed cached, but only if your "mode" element in click.xml 
is set to "production" or "profile".



On 02-Feb-10 07:36, aurmam wrote:
> i have this example and just now i have a problem
>
> when i deploy application everything is ok.
> i get the menu
>
> but when i change the value in database...
> and assign another authority, i relogin to the application but i get the old
> menu.
>
> when i rediploy it the menu changes...
>
> can anybody say where the problem could appear?
>
> it seems the menu is being cached
>    

Re: menu

Posted by aurmam <au...@gmail.com>.
i have this example and just now i have a problem

when i deploy application everything is ok.
i get the menu

but when i change the value in database...
and assign another authority, i relogin to the application but i get the old
menu.

when i rediploy it the menu changes...

can anybody say where the problem could appear?

it seems the menu is being cached 
-- 
View this message in context: http://n2.nabble.com/menu-tp3070583p4499285.html
Sent from the click-user mailing list archive at Nabble.com.

Re: menu

Posted by aurmam <au...@gmail.com>.
i have an example how to create a menu by java

public class MenuPage {
	
    private static GrantedAuthority[] UserAuthorities;
	
    private static class MenuHolder {
        private static Menu INSTANCE = createMenus();
    }

    public static void setUserAuthorities(GrantedAuthority[]
userAuthorities) {
		UserAuthorities = userAuthorities;
	}

	public static Menu getMenus() {
		return MenuHolder.INSTANCE;
    }

    @SuppressWarnings("unchecked")
	private static Menu createMenus() {
    	
		Menu rootMenu = new Menu("rootMenu");
		Menu menu;
		Menu subMenu;

		menu = createMenu("Home", "home.htm","/assets/images/home.png");
	    rootMenu.getChildren().add(menu);

        menu = createMenu("Task Manager","#","/assets/icons/book_open.png");
        rootMenu.getChildren().add(menu);
        	
	        subMenu = createMenu("List tasks", "taskmanager/list-tasks.htm");
	        menu.getChildren().add(subMenu);
	        
	        subMenu = createMenu("Add new Task",
"taskmanager/add-new-task.htm");
	        menu.getChildren().add(subMenu);
	        
	        subMenu = createMenu("Phone Book", "phonebook/phonebook.htm");
	        menu.getChildren().add(subMenu);

	        subMenu = createMenu("Add New Phone",
"phonebook/add-new-phone.htm");
	        menu.getChildren().add(subMenu);	        
	        
	    menu = createMenu("Administration","#","/assets/icons/book_open.png");
	    rootMenu.getChildren().add(menu);
	    	
	    	subMenu = createMenu("Create new
User","administration/create-user.htm");
	    	menu.getChildren().add(subMenu);	
	    	subMenu = createMenu("Create new Role","user/user.htm");
	    	menu.getChildren().add(subMenu);
	    	
	    	if (userHasAuthority(Permission.TEST)) {
	    		subMenu = createMenu("Asign Roles","user/user.htm");
	    		menu.getChildren().add(subMenu);
	    	}
	    
		return rootMenu;

	}
	
    @SuppressWarnings("unused")
	private static Menu createMenu(String label) {
        Menu menu = new Menu();
        menu.setLabel(label);
        menu.setTitle(label);
        return menu;
    }

    private static Menu createMenu(String label, String path) {
        Menu menu = new Menu();
        menu.setLabel(label);
        menu.setPath(path);
        menu.setTitle(label);
        return menu;
    }

    private static Menu createMenu(String label, String path, String
IconPath) {
        Menu menu = new Menu();
        menu.setLabel(label);
        menu.setPath(path);
        menu.setTitle(label);
        menu.setImageSrc(IconPath);
        return menu;
    }
    
    public static boolean userHasAuthority(String authority) {
        for (int i = 0; i < UserAuthorities.length; i++) {
            if (authority.equals(UserAuthorities[i].getAuthority())) {
                return true;
            }
        }

        return false;
    }
    
}

and from BorderPage you can call

	public void onInit() {
		super.onInit();
		if (hasPermission(Permission.LOGIN)) {
			MenuPage.setUserAuthorities(getAuthorities());
			rootMenu = MenuPage.getMenus();
		}
        }

i am using spring security + CAS all authorities are being read from mysql
database


-- 
View this message in context: http://n2.nabble.com/menu-tp3070583p3085855.html
Sent from the click-user mailing list archive at Nabble.com.


Re: menu

Posted by Malcolm Edgar <ma...@gmail.com>.
Your requirements are very similar to a pattern I use with Click. A
logged in user has a series of roles. Each menu item defines the roles
in which the menu is displayed. The rendering of the menu is performed
by a velocity macro, if the user is in one of the roles of the menu it
is rendered.  This is described below in:

http://incubator.apache.org/click/docs/extras-api/org/apache/click/extras/control/Menu.html

The quick start application builder provides a demo of this. If you
are using ACEGI Security you can write an ACEGI AccessController to
control this display of the menu item, using permissions instead of
roles.

regards Malcolm Edgar

On Sat, Jun 13, 2009 at 3:48 PM, dian<di...@gmail.com> wrote:
>
> Yes, it might be a nice,
>
> menu can create dinamically depent on user roles that was login.
> so when page is open, it can find user from session and find roles_user in
> dbase
> what menu must display for that role.
>
> more modular menu, like on Dotnetnuke CMS / mojoPortal CMS
>
>
>
>
> Malcolm Edgar-2 wrote:
>>
>> Hi Dian,
>>
>> what you will need to do is create the menu dynamically using the
>> no-args constructor and setting the properties programatically. You
>> may want to store each users menu in their session.
>>
>> This might be a nice example to include in Click Examples or FAQ.
>>
>> regards Malcolm Edgar
>>
>> On Sat, Jun 13, 2009 at 10:03 AM, dian ruzda<di...@gmail.com> wrote:
>>> Hello all, I try to make menu control in my page, I see on example must
>>> define on menu.xml
>>> can I make menu control programatically on java. so I don't need to write
>>> menu.xml again coz
>>> I wanna make dinamic menu and relate with my dbase ?
>>>
>>>
>>> thx
>>>
>>
>>
>
> --
> View this message in context: http://n2.nabble.com/menu-tp3070583p3071425.html
> Sent from the click-user mailing list archive at Nabble.com.
>
>

Re: menu

Posted by dian <di...@gmail.com>.
Yes, it might be a nice,

menu can create dinamically depent on user roles that was login.
so when page is open, it can find user from session and find roles_user in
dbase
what menu must display for that role. 

more modular menu, like on Dotnetnuke CMS / mojoPortal CMS




Malcolm Edgar-2 wrote:
> 
> Hi Dian,
> 
> what you will need to do is create the menu dynamically using the
> no-args constructor and setting the properties programatically. You
> may want to store each users menu in their session.
> 
> This might be a nice example to include in Click Examples or FAQ.
> 
> regards Malcolm Edgar
> 
> On Sat, Jun 13, 2009 at 10:03 AM, dian ruzda<di...@gmail.com> wrote:
>> Hello all, I try to make menu control in my page, I see on example must
>> define on menu.xml
>> can I make menu control programatically on java. so I don't need to write
>> menu.xml again coz
>> I wanna make dinamic menu and relate with my dbase ?
>>
>>
>> thx
>>
> 
> 

-- 
View this message in context: http://n2.nabble.com/menu-tp3070583p3071425.html
Sent from the click-user mailing list archive at Nabble.com.


Re: menu

Posted by Malcolm Edgar <ma...@gmail.com>.
Hi Dian,

what you will need to do is create the menu dynamically using the
no-args constructor and setting the properties programatically. You
may want to store each users menu in their session.

This might be a nice example to include in Click Examples or FAQ.

regards Malcolm Edgar

On Sat, Jun 13, 2009 at 10:03 AM, dian ruzda<di...@gmail.com> wrote:
> Hello all, I try to make menu control in my page, I see on example must
> define on menu.xml
> can I make menu control programatically on java. so I don't need to write
> menu.xml again coz
> I wanna make dinamic menu and relate with my dbase ?
>
>
> thx
>