cc'ing dev email alias as other may be interested.
See below...
Ken Paulsen wrote:
>
> Yeah... I forgot to checkin my change that ensures the '/' in front
> (it's a JSF requirement that I wasn't going to expose). I've since
> made several changes to that file that I'm not ready to checkin... so
> it'll have to wait. Adding the '/' is the right thing to do, though.
>
> Good work!
>
> Ken
>
> Ana Caballero wrote:
>> I got an error when I tried navigating from a.jsf to b.jsf. I had to
>> put a "/" in front of the file name to get it to work. i.e.
>> navigate(page="/b.jsf"); This works!
>>
>> Ken Paulsen wrote:
>>>
>>> Yep, that should work. You will probably want to have a hidden
>>> field on the next page that stores the value.
>>> *There is another way in JSF, but it's not very easy to use... I
>>> might make this more accessible, if I do I'll let you know.*
Ok, I made it easy to do the "other" way. But first let me explain what
the "other" way is. In JATO we had "page" session. JSF only has 3
formal scopes: request, session, and application. But it also contains
state that is saved w/ the page... which is the same as "page" session
in JATO terms. The only problem w/ JSF is that it doesn't provide as
easy of a way to access this type of "scope"...
Why should you use page session? Because it lives as long as the page,
not just as long as the request. This frees you from having to worry
about passing the data back and forth to / from the server and also from
managing session scoped variables. See example pages attached.
So what I did was add a Handler that allows you to set a page session
variable on a UIViewRoot (the root of a page). I also added a Handler
to get a UIViewRoot. I modified the navigate() handler to accept a
UIViewRoot (so you can use one that has the page session variables).
Finally, I added a VariableResolver (JSF's way of interpreting
#{expressions}) to recognize page scoped variables.
Here's how you use it:
<!command
// Get the UIViewRoot of the Next Page:
getUIViewRoot(id="nextPage.jsf", viewRoot=>$attribute{viewRoot});
// Set a Page Session Attribute:
setPageSessionAttribute(key="someKey", value="someValue",
page="$attribute{viewRoot}");
// Goto the next page:
navigate(page="$attribute{viewRoot}");
/>
Note this can be simplied by doing the navigation first b/c of the way
JSF does its navigation (it just changes the UIViewRoot). However, this
is less explicit and may lead to confusion. But in case you're curious
the following should also work the same as above:
<!command
navigate(page="nextPage.jsf");
setPageSessionAttribute(key="someKey", value="someValue");
/>
In this case you don't need to get the UIViewRoot as it is set as the
default in the first line. And as such you don't need to pass it in to
the setPageSessionAttribute handler either (it defaults to the current
UIViewRoot). Use whichever makes more sense to you. :)
See attached files for a real example on how to use this.
Ken
>>>
>>> Ken
>>>
>>> Ana Caballero wrote:
>>>> Thanks Ken. If I want to store the data(page name) entered in the
>>>> textfield so that page 2 can use that information do I call
>>>> getUIComponentProperty and store it in $attribute{name}?
>>>>
>>>> Thanks.
>>>>
>>>> Ken Paulsen wrote:
>>>>> Ok, here's what I have for a navigation handler:
>>>>>
>>>>> navigate(page="b.jsf");
>>>>>
>>>>> "b.jsf" is a path relative to the doc root to the next page.
>>>>>
>>>>> Here's a example button that uses this:
>>>>>
>>>>> <rave:button value="Guess">
>>>>> <!command
>>>>> getUIComponent(clientId="form:field",
>>>>> component=>$attribute{field});
>>>>> getUIComponentProperty(component="$attribute{field}",
>>>>> name="value", value=>$attribute{guess});
>>>>> navigate(page="b.jsf");
>>>>> />
>>>>> </rave:button>
>>>>>
>>>>> Attached are to pages (a.jsf and b.jsf) which demonstrate this. You
>>>>> will need to checkout (and build) the latest jsftemplating files to see
>>>>> this work.
>>>>>
>>>>> Ana, this should help you get the navigation between the first 2 pages
>>>>> working...
>>>>>
>>>>> Ken
<rave:page>
<rave:html>
<rave:head title="Guess My Number" />
<rave:body>
<rave:form id="form">
" <h2> Page A </h2>
<rave:textField label="Guess My Number" id="field" />
<rave:button value="Guess">
<!command
getUIComponent(clientId="form:field", component=>$attribute{field});
getUIComponentProperty(component="$attribute{field}", name="value", value=>$attribute{attGuess});
// Get the UIViewRoot for b.jsf
getUIViewRoot(id="b.jsf", viewRoot=>$attribute{viewRoot});
// Set a Page Session attribute named "pageGuess"
setPageSessionAttribute(key="pageGuess", value="$attribute{attGuess}", page="$attribute{viewRoot}");
navigate(page="$attribute{viewRoot}");
/>
</rave:button>
</rave:form>
</rave:body>
</rave:html>
</rave:page>
<rave:page>
<rave:html>
<rave:head title="Guess My Number" />
<rave:body>
<rave:form id="form">
" <h2> Page B </h2>
" You guessed (passed via an attribute): <b>#{attGuess}</b><br />\n
" You guessed (passed via page session): <b>#{pageGuess}</b><br /><br />\n
"<b> Since request attributes last only during 1 request, they will not span multiple requests... to see this click "Refresh".</b><br /><br />
<rave:button value="Refresh" />
</rave:form>
</rave:body>
</rave:html>
</rave:page>