dev@jsftemplating.java.net

Re: JSFTemplating: Some questions on passing variables

From: Ken Paulsen <Ken.Paulsen_at_Sun.COM>
Date: Mon, 22 Jan 2007 11:40:02 -0800

Karam Singh Badesha wrote:
> Hi,
>
>
> #1:
>
> When I have to pass some variables to the next page from an hyperlink,
> how do I use them in the next page?
>
> e.g.
>
> page2.jsf?var1=This&var2=is&var3=a&var4=test
>
> Do I just use them like the following:
>
> #{requestScope.var1}
> ...
>
No, JSF's EL does not support this by default. #{requestScope....} looks
in the ServletRequest attribute map, which is a read/write map for
arbitrary values that live during the request. This is different than
the request "parameter" map.

JSFTemplating provides a way to access these though, but not via the
standard EL syntax (it could be enhanced to do this, perhaps an RFE). To
access requestParameters with JSFTemplating, you can do this:

$requestParameter{var1}

You can that pass this as input to handlers, or component properties.
For example:

<staticText value="You submitted: $requestParameter{var1}." />

Or:

<!beforeCreate
println("Writing to stdout that you submitted $requestParameter{var1}
and $requestParameter{var2}.");
/>

> #2:
>
> PageSession variables don't get passed to different pages, correct?
>
Yes, that is correct. You have to manually move them if you want them to
live longer. Gavin King (created of JBoss Seam) has suggested the
concept of a "conversation scope" that would last longer than pageScope
but still shorter than Session scope. This would be useful in many
cases. In the future, we may integrate with his stuff (I haven't
evaluted this yet) or offer a similar concept. JSF may even offer a
similar concept in the future.
> #3:
>
> When I have session variables, what is the process of defining them and
> using them?
>
You can set them via code:

facesContext.getExternalContext().getSessionMap().put("abc", "123");
....getSessionMap().get("abc");

Or via handlers:

setSessionAttribute(key="abc", value="123");
println("Session key 'abc' = $session{abc}");

Via EL:

$session{abc}
#{sessionScope.abc}

NOTE: the 2nd EL expression above can be used as a read/write property
value. So if you bind an input field value like this, it will set the
value on submit.

Via the faces-config.xml file when you declare managed beans, you can
set their scope... including session scope.
> Here is my understanding, please let me know something is not correct:
>
> page1: declare session variables
> page1: use session variables
>
> page2: accept session variables
>
Not sure what you mean by "accept". Session variables (which are
different from pageSession) will last until the user's "session"
expires. So it is available to every page after it is set.
> page2: use session variables
>
> Now, if I am passing some variables with hyperlink (#1 above), session
> variables will still work the way they are supopsed to, correct?
>
Yes if I understand your question correctly.
> Thats it for now.
>
> thanks
> Karam
>