dev@jsftemplating.java.net

Re: JSFTemplating: question about 'if' handler

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Sun, 22 Oct 2006 18:38:07 -0700

Yes, I think this can be done, although perhaps not exactly as you wrote
it...

See comments and suggestions below.

Ken

Anissa Lam wrote:
> Hi Ken,
> I have a question regarding how much processing is done by the 'if'
> handler. I am not sure about the syntax, or whether this is
> possible at all. Here is what i would like to do. I want to test
> if a page session attribute exists or not, and use a default value if
> it doesn't. Its ok if this can't be done, i will use the
> alternative and go through a handler.
>
> <!command
> if (* #{useId} = #{null}*) {
#{userId} will look at all scopes and attempt to use all EL variable
resolvers to find "userId". When you "know" that it's a pageSession (or
any other scope), it's more efficient and safer to be more specific:
$pageSession{userId} for example, or #{pageSession.userId}.

I don't know if the "=#{null}" check will work as this attempt to do
String comparisons. With this in mind, I would suggest trying something
like:
    if ($pageSession{userId}=) {
    }

Or add some characters around the 2 values, quotes may be a problem b/c
in this case, however, because it may interpret that to be the value of
the if... I can change this (if you don't know what I'm talking about...
talk to me more tomorrow about it... this may be a bug).

Also, I think for null, you can simply do:

if (!$pageSession{userId}) {
    println("value is null");
}

or:

if ($pageSession{userId}) {
    println("value is not null");
}

Ken
> println(value=" useId is not set. will use default");
> }
> if ( *!( #{useId}=#{null})* ) {
> println(value="useId has been set, the value is #{useId}");
> }
> />
>
> alternative:
>
> <!commond
> testExists( target="#{useId}" defined=>$attribute{defined});
> if (! #{defined}){
> println(value="useId is not set. will use default ");
> }
> if (#{defined}){
> println(value="useId is set, the value is #{useId}");
> }
> />