-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I want to show different homepages to differetn groups of user. How can I achieve that?
As a guest user I want to see different screen but as admin I want to see different. How can I do that? Can cokkies be used or is there any way I can do that?
If you want to use Cookies, you can use little helpers as the following:
public static void setCookie(String name, String value) { ((HttpServletResponse) Executions.getCurrent().getNativeResponse()).addCookie(new Cookie( name, value)); } public static String getCookie(String name) { Cookie[] cookies = ((HttpServletRequest) Executions.getCurrent().getNativeRequest()) .getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().equals(name)) { return cookie.getValue(); } } } return null; }
HTH, Maik
They just static method, you can put them in a class such as "CookieUtil.java"
You can use composer, and set the cookie value when user login
getCookie in doAfterCompose method and to decision what is user's view, like this
if ( CookieUtil.getCookie( userBean.getName() ) == "A") { mainPanel.appendChild(Executions.createComponents("A.zul", null, null)); } else { mainPanel.appendChild(Executions.createComponents("B.zul", null, null)); }
I need another help.
The problem I am facing is, the cookie is becoming the browser’s instance specific.
For example, if I open a browser and hit the application the cookie get set and on refreshing the same window the expected behaviour comes but if I close the browser window and open another browser window and hit the application I find that cookie value is lost.
Please let me know if I am using the cookie APIs correctly within the framework or if I need to use it some other way.
Have you set the age of cookie?
if you were correctly set the cookie in any response, than you could get cookies by HttpServletRequest.getCookies , and you can get the request by Exectuions.getCurrent().getNativeRequest()/
Asked: 2010-02-05 03:33:32 +0800
Seen: 2,528 times
Last updated: Aug 11 '11