This is far better than my *traditional* method. I wrote a listener
which will intervene at the render response step to determine whether a
component should be rendered or not.

Regards,

--Doug
-----Original Message-----
From: Craig McClanahan [mailto:[EMAIL PROTECTED] 
Sent: Thursday, June 09, 2005 10:19 PM
To: MyFaces Discussion; Eric Knapp
Subject: Re: Selective Component Display

On 6/9/05, Eric Knapp <[EMAIL PROTECTED]> wrote:
> Hi all,
> 
> I am learning JSF and MyFaces this summer. I am looking for a
> best-practice or even just good ideas about something. I have a
> question about selectively displaying components. Here is an example
> of what I mean. I would like to have one page that shows a different
> dataTable depending on the authentication role of a user. A normal
> user would see a general HTML table while an admin user would see more
> columns and maybe an edit button.
> 
> Without JSF I would do this with lots of JSTL. What's the best JSF
> way? I have been looking at Tiles too but that doesn't seem to point
> to the future of JSF.
> 

A very common approach for selective display of JSF components is to
use a value binding on the "rendered" property (which all components
should be implementing), binding it to a method returning a boolean
that can determine whether this component, and all its children,
should be rendered or not.

Assume you have a session-scoped "user" bean representing the current
user, with an isManager() method that returns boolean.  You can
restrict display of salary information in an HR application with
something like this:

  <h:outputText value="#{employee.salary}" ...
rendered="#{user.manager}" .../>

Craig

Reply via email to