You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ben <ne...@gmail.com> on 2004/10/18 15:13:31 UTC

Equivalent to pageContext

In Velocity, which instance I can use that has the same functionality
as the pageContext?

I am trying to convert Struts-Menu Taglibs to Velocity Toolbox and
everything seems to be working fine except the permissions.

The scenario:

The 'admin' has full menu, the 'user' has restricted menu.

1) Startup Tomcat.
2) Login as admin and see full menu and logout
3) Login as user and see restricted menu and logout
4) Login as admin and NOT see the full menu but see the restricted menu instead
5) Continuously switching user but I can only see the restricted menu.

The only way I can see the full menu is to restart Tomcat and login as admin.

I am currently using viewContext but I believe this instance gets
initialize once when Tomcat starts up. Whereas with pageContext it
gets initialize with each JSP page.

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Equivalent to pageContext

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Ben,

> > I think the ViewContext itself is somewhat like PageContext.
> I am using ViewContext.
Then I guess you already know about the #getRequest(), #getResponse(),
and so on methods.

> > By "initialize", what do you mean?
> I mean the instance gets created on each request.
Ah, then you should put your tool in request scope.  See
  http://jakarta.apache.org/velocity/tools/view/index.html#Toolbox%20Configuration
about tool scopes.

> In one session, I login as admin and see the full menu. In another
> session I login as normal user and see the restricted menu. I refresh
> the page in the admin user session and see the restricited menu (not
> the full menu).
Could it be that your browser is using the authentication information
for the restricted user?  But you were saying that it doesn't show the
full menu even if you re-login as admin...  Weird.

> The permission works for the menu but doens't work for the menu item.
> If I define three seperate menus for each role then the users see the
> correct menus. If I define one menu and each menu item has different
> role then the problem occurs.
The menu items might be stored in the session?  I don't know.  I guess
the rest is up to the Struts-Menu folks to figure out.

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Equivalent to pageContext

Posted by Ben <ne...@gmail.com>.
Thank you for your reply Shinobu.

> I think the ViewContext itself is somewhat like PageContext.
I am using ViewContext.

> I don't know how the Struts-Menu Taglibs works, but where(how) are you
> putting your login info?
I am using Container Managed Security with Tomcat. Struts-Menu has a
role adapter where it hides/unhides a menu/item based on the role.

> By "initialize", what do you mean?
I mean the instance gets created on each request.

> Let's say you are talking about tools.  If your tool implements the
> ViewTool interface, you will receive the Context in the init(Object)
> method on each request (so long as you put the tool in request scope).
I am implementing the ViewTool interface and do initialize stuff in
the init() method.

In one session, I login as admin and see the full menu. In another
session I login as normal user and see the restricted menu. I refresh
the page in the admin user session and see the restricited menu (not
the full menu).

The permission works for the menu but doens't work for the menu item.
If I define three seperate menus for each role then the users see the
correct menus. If I define one menu and each menu item has different
role then the problem occurs.

Thanks,
Ben

On Mon, 18 Oct 2004 23:19:01 +0900, Shinobu Kawai
<sh...@gmail.com> wrote:
> Hi Ben,
> 
> > In Velocity, which instance I can use that has the same functionality
> > as the pageContext?
> I think the ViewContext itself is somewhat like PageContext.
> 
> > I am trying to convert Struts-Menu Taglibs to Velocity Toolbox and
> > everything seems to be working fine except the permissions.
> >
> > The scenario:
> >
> > The 'admin' has full menu, the 'user' has restricted menu.
> >
> > 1) Startup Tomcat.
> > 2) Login as admin and see full menu and logout
> > 3) Login as user and see restricted menu and logout
> > 4) Login as admin and NOT see the full menu but see the restricted menu instead
> > 5) Continuously switching user but I can only see the restricted menu.
> >
> > The only way I can see the full menu is to restart Tomcat and login as admin.
> I don't know how the Struts-Menu Taglibs works, but where(how) are you
> putting your login info?
> 
> > I am currently using viewContext but I believe this instance gets
> > initialize once when Tomcat starts up. Whereas with pageContext it
> > gets initialize with each JSP page.
> By "initialize", what do you mean?  At least instances of
> (View)Context get created on each request.  Velocity itself and the
> toolbox gets initialized on (Servlet) context initialization.
> (Assuming that you are using VelocityViewServlet, of course.)
> 
> Let's say you are talking about tools.  If your tool implements the
> ViewTool interface, you will receive the Context in the init(Object)
> method on each request (so long as you put the tool in request scope).
>      http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/view/tools/ViewTool.html#init(java.lang.Object)
> 
> Best regards,
> -- Shinobu Kawai
> 
> --
> Shinobu Kawai <sh...@gmail.com>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Equivalent to pageContext

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Ben,

> In Velocity, which instance I can use that has the same functionality
> as the pageContext?
I think the ViewContext itself is somewhat like PageContext.

> I am trying to convert Struts-Menu Taglibs to Velocity Toolbox and
> everything seems to be working fine except the permissions.
> 
> The scenario:
> 
> The 'admin' has full menu, the 'user' has restricted menu.
> 
> 1) Startup Tomcat.
> 2) Login as admin and see full menu and logout
> 3) Login as user and see restricted menu and logout
> 4) Login as admin and NOT see the full menu but see the restricted menu instead
> 5) Continuously switching user but I can only see the restricted menu.
> 
> The only way I can see the full menu is to restart Tomcat and login as admin.
I don't know how the Struts-Menu Taglibs works, but where(how) are you
putting your login info?

> I am currently using viewContext but I believe this instance gets
> initialize once when Tomcat starts up. Whereas with pageContext it
> gets initialize with each JSP page.
By "initialize", what do you mean?  At least instances of
(View)Context get created on each request.  Velocity itself and the
toolbox gets initialized on (Servlet) context initialization. 
(Assuming that you are using VelocityViewServlet, of course.)

Let's say you are talking about tools.  If your tool implements the
ViewTool interface, you will receive the Context in the init(Object)
method on each request (so long as you put the tool in request scope).
     http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/view/tools/ViewTool.html#init(java.lang.Object)

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <sh...@gmail.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org