Your instincts are right. This is not really the ideal way to do
this. You are mixing your business logic with your presentation
logic. Your presentation logic (JSP/JSF tags) shouldn't care what
role you are.
Instead you should delegate that kind of responsibility to your
backing bean. Only the backing bean should know these kinds of rules.
(Besides separation concerns, it clutters up your JSP if you leave
this kind of thing in there.)
Use something like:
<h:graphicImage id="foo"... rendered="#{authentication.displayFoo}"/>
<h:graphicImage id="bar"... rendered="#{authentication.displayBar}"/>
This requires the authentication bean know whom you are but this is
easily done by setting a user property based on a session variable,
etc.
IMO you don't want the URL to be determined by the bean. Its better
to present them both in JSP and leave the URL and image stuff outside
of your backing beans (and away from your business logic.)
sean
ps. Your quotation marks do not match up which is probably why your EL
expression was failing.
On 8/22/05, Patrick Hubers <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to put an image into a page based on the outcome of an
> expression. I've tried the following:
>
> <h:graphicImage url="#{(authentication.role == "admin' ? 'image1.gif' :
> 'image2.gif'}" />
>
> but unfortunately, this doesn't work (the whole expression is passed
> verbatim to the rendered html), so now I'm resorting to
>
> <h:graphicImage url="image1.gif" rendered="#{authentication.role ==
> 'admin'}" />
> <h:graphicImage url="image2.gif" rendered="#{authentication.role !=
> 'admin'}" />
>
> However, the above feels clumsy. Is this the right way to do it, or
> should the first option work and did I encounter a bug? Any hints
> appreciated!
>
> (Using stock MyFaces 1.0.9 with JBoss 4.0.2 on Win2k)
>
> --
> Patrick Hubers
>