Well kind of. A GET method and a page request are basically the same
thing. A get is simply a request for a page with no request body. All
information must be on the query string. All commandLink and
commandButton controls submit forms (POST). This triggers JSF action,
actionListener, valueChangeListener, validation and model updates.
If you don't need any of that, then outputLink is lighter and may be
nicer. When a user hits refresh, the behavior is different depending
on if the current page was loaded via GET or POST. If a POST, the user
is asked, usually, if they want to re-submit their data to the server.
If a get, the browser simply re-asks for the page re-using the current
URL.
A "gotcha" with refreshing and JSF is that if you are using commands
and JSF navigation, the page is always one behind:
-URL- -VIEW-
page1.jsf, page1.xhtml
page1.jsf, page2.xhtml
page2.jsf, page3.xhtml
This is because JSF will submit back to the current page, then using
navigation rules, include (not redirect unless specified) the next
page. According to the browser, the last page was re-loaded.
So in the above example, if I hit F5 while page2.xhtml is the view and
page1.jsf is the URL, I am actually sending a GET request to the
server for page1.jsf.
Now with all this said, I am not sure of the best way to allow F5
refreshing. As a side effect of AJAX and server side state , it seems
to work well at my day job (although not by design).
I think there are still some large issues with JSF and bookmarking,
back/next buttons and page refreshing (not to mention AJAX which is an
entirely different discussion). I think that JSF needs to design
around these items. One possibility may be to merge POST and GET. I
have done this in the past. Where, onsubmit of a form, a query string
is added to the requested URL and the rest of the information is
posted. That query string acts as a bookmark-able URL. Then in the
code, you could check for that query string and if it is there, do the
necessary thing. I don't think there is any easy solution though. It
would be nice if a programmer could tell the browser what to bookmark
and refresh for a given page, unfortunately functionality like that
would be abused probably (bookmark a nice page and have it end up
going to a porn site later for example).
Don't think I helped solve the problem, but that is some of what you
are probably dealing with.
-Andrew
On 4/29/06, Anthony Hong <[EMAIL PROTECTED]> wrote:
Is that means all JSF request are post method, and if user click
refresh button or F5 a get method is sent?
On 4/29/06, Travis Reeder <[EMAIL PROTECTED]> wrote:
> I usually try to use h:outputLink's wherever possible instead of
> commandLink's so it will use GETs and you won't have to worry as much about
> this refresh problem. I know the JSF purists might say to use commands
> everywhere, but in reality, you're app will be much more usable if you use
> outputLink.
>
> Rule of thumb: commandLink or commandButton when you want an action to
> happen (aka, posting a form), and outputLink when it's just a navigation
> link.
>
> Travis
>
>
> On 4/28/06, Andrew Robinson <[EMAIL PROTECTED]> wrote:
> > Could you create a phase listener to check if the request is a POST or
> > GET, and if a GET, create a new view root? With server-side state
> > saving, views seem to be reused if the URL doesn't change. I haven't
> > looked at the code, but I see the same behavior (the same view tree is
> > used).
> >
> > Another alternative is to use client side state, that way the browser
> > will not post the component state back on refresh.
> >
> > On 4/28/06, Anthony Hong < [EMAIL PROTECTED]> wrote:
> > > You mean as javascript you wrote can prevent form submit?
> > > I don't want to prevent refresh, but I just want refresh in request a
> > > new page same as jsf page first requested, its lifecycle create a new
> > > jsf view component tree and render response.
> > >
> > >
> > > On 4/28/06, aliko <[EMAIL PROTECTED]> wrote:
> > > >
> > > > You can trap F5 key and call form.submit with a little javascript. But
> that
> > > > does not help when user clicks the refresh button.
> > > >
> > > > <script>
> > > >
> > > > function ui_onkeydown_handler() {
> > > > switch ( event.keyCode) {
> > > > case 116 : // F5
> > > > event.keyCode = 0;
> > > > event.returnValue = false;
> > > > document.forms ['form1'].submit();
> > > > }
> > > > }
> > > >
> > > > document.attachEvent("onkeydown", ui_onkeydown_handler);
> > > > </script>
> > > >
> > > >
> > > > --
> > > > View this message in context:
> http://www.nabble.com/Issues-with-refresh-page-in-JSF-t1523452.html#a4140628
> > > > Sent from the MyFaces - Users forum at Nabble.com.
> > > >
> > > >
> > >
> > >
> > > --
> > >
> > > Anthony Hong
> > >
> >
>
>
--
Anthony Hong