You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by John <jo...@quivinco.com> on 2012/11/19 18:46:44 UTC

smart menu links

I've got my superfish menu going, but I'd like menu items to not show if the user isn't permitted to use the page because of their role.

The menu code is of the form

   <ul t:type="jquery/superfish" t:clientId="menu1"  t:classe="ep-menu" t:supersubs="true" t:supersubsParams="supersubsParams">
    <li class="current">
     <a href="#">Users</a>
     <ul>
      <li>
       <a t:type="pageLink" t:page="Users">Manage Users</a>
      </li>
      <li>
       <a t:type="pageLink" t:page="Organsiations">Manage Organisations</a>
      </li>...

The page classes use the javax security @RolesAllowed annotation.

I'd like to be able to make it so the <li> blocks are conditional upon the @RoleAnnotation state. Then when I change page permissions using the annotations the menu will adjust accordingly. How can this be achieved?

 I'm thinking my Layout could have a Page type property or boolean property that I set according to logged in role matching what is in the Page classes annotation. This seems unduley clunky though!

      <li t:type="if" t:test="Users">
       <a t:type="pageLink" t:page="Users">Manage Users</a>
      </li>

John

Re: smart menu links

Posted by Ivan Khalopik <ik...@gmail.com>.
You can extract li items with content to separate component, e.g MenuItem
with parameter 'page'. Inside this component you can get this parameter
value, check whether this page is allowed for current user and if yes then
render li with inner PageLink component. If no then render nothing. So it
will look like this:
...
<ul>
<t:menuitem page="users">Manage Users</t:menuitem>
<t:menuitem page="organisations">Manage Organisations</t:menuitem>
...
</ul>

MenuItem.java:

@Property
@Parameter(required=true, allowNull=false,
defaultPrefix=BindingConstants.LITERAL)
private String page;

@BeforeRenderTemplate
boolean beforeRenderTemplate() {
  return isAllowed(page);
}

private boolean isAllowed(String page) {
   // some security logic
}

MenuItem.tml:

<li>
  <t:pagelink page="prop:page"><t:body></t:pagelink>
</li>


On Mon, Nov 19, 2012 at 8:46 PM, John <jo...@quivinco.com> wrote:

> I've got my superfish menu going, but I'd like menu items to not show if
> the user isn't permitted to use the page because of their role.
>
> The menu code is of the form
>
>    <ul t:type="jquery/superfish" t:clientId="menu1"  t:classe="ep-menu"
> t:supersubs="true" t:supersubsParams="supersubsParams">
>     <li class="current">
>      <a href="#">Users</a>
>      <ul>
>       <li>
>        <a t:type="pageLink" t:page="Users">Manage Users</a>
>       </li>
>       <li>
>        <a t:type="pageLink" t:page="Organsiations">Manage Organisations</a>
>       </li>...
>
> The page classes use the javax security @RolesAllowed annotation.
>
> I'd like to be able to make it so the <li> blocks are conditional upon the
> @RoleAnnotation state. Then when I change page permissions using the
> annotations the menu will adjust accordingly. How can this be achieved?
>
>  I'm thinking my Layout could have a Page type property or boolean
> property that I set according to logged in role matching what is in the
> Page classes annotation. This seems unduley clunky though!
>
>       <li t:type="if" t:test="Users">
>        <a t:type="pageLink" t:page="Users">Manage Users</a>
>       </li>
>
> John




-- 
BR
Ivan