You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Christian Grobmeier <gr...@gmail.com> on 2011/04/15 13:57:54 UTC
Creating menu bar based on session information
Hi all,
this is probably a trivial question, but I am unsure how to solve it best.
I have an object User user. It has the properties name, password and
List<Roles> roles.
Now I would like to create a navigation bar in my struts 2.2.1 jsp pages.
I wanted to avoid huge chunks of logic in my code. Therefore java code
in my templates should be avoided.
I have thought if the if/else struts tag would help me. But can I
access a list and look if a specific role is there?
How do others do that?
Thanks in advance,
Christian
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Creating menu bar based on session information
Posted by Christian Grobmeier <gr...@gmail.com>.
>> <s:if test="hasPrivileg('user') == true">Yeah</s:if>
>
> Actually, you added a spelling mistake (+e on Privileg). However, the
> previous example would work fine. So a hybrid of the two:
Actually I had the spelling typo before, but now saw that in english
it is with +e
> <s:if test="hasPrivilege('user')">Yeah</s:if>
You are right, this works.
After all I am not sure why I have lost so much time today on this.
Thanks
Christian
>
> is sufficient.
>
> Beez
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
http://www.grobmeier.de
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Creating menu bar based on session information
Posted by "Biesbrock, Kevin" <Bi...@aoins.com>.
> <s:if test="hasPrivileg('user') == true">Yeah</s:if>
Actually, you added a spelling mistake (+e on Privileg). However, the
previous example would work fine. So a hybrid of the two:
<s:if test="hasPrivilege('user')">Yeah</s:if>
is sufficient.
Beez
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Creating menu bar based on session information
Posted by Christian Grobmeier <gr...@gmail.com>.
> <s:if test="hasPrivilege(\"user\")">Login</s:if>
The correct syntax is:
<s:if test="hasPrivileg('user') == true">Yeah</s:if>
I really would enjoy some more debugging help in this area
Cheers
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Creating menu bar based on session information
Posted by Christian Grobmeier <gr...@gmail.com>.
> you could do something like this:
> <s:if test="hasPrivilege(#user.roles)">...</s:if> where (bool)
> hasPrivilege(List<Roles>,...) is a function in your action.
sounds good.
I actually have now that signature in an AbstractAction from which all
the other extend:
public boolean hasPrivileg(String role) { ... }
In my JSP:
<s:if test="hasPrivilege(\"user\")">Login</s:if>
I did not understand why you putted #user.roles in your example.
However, my debugger is never going int the hasPrivileg method. What
am I missing?
Cheers
Christian
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Creating menu bar based on session information
Posted by Markus Demetz <ma...@demetz.eu>.
you could do something like this:
<s:if test="hasPrivilege(#user.roles)">...</s:if> where (bool)
hasPrivilege(List<Roles>,...) is a function in your action.
Markus
Am 15.04.2011 13:57, schrieb Christian Grobmeier:
> Hi all,
>
> this is probably a trivial question, but I am unsure how to solve it best.
>
> I have an object User user. It has the properties name, password and
> List<Roles> roles.
>
> Now I would like to create a navigation bar in my struts 2.2.1 jsp pages.
>
> I wanted to avoid huge chunks of logic in my code. Therefore java code
> in my templates should be avoided.
>
> I have thought if the if/else struts tag would help me. But can I
> access a list and look if a specific role is there?
>
> How do others do that?
>
> Thanks in advance,
> Christian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org