You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Anthony Hong <an...@gmail.com> on 2006/04/28 11:25:50 UTC

Issues with refresh page in JSF

There is a big problem with me for using JSF when refresh current page.

That seams JSF always post latest action when clicking F5 in IE. What
I want is a new request instead of posting latest action to Backing
bean.

Can I achieve my goal? If can, how to deal with this problem.
Thanks

--

Anthony Hong

Re: Issues with refresh page in JSF

Posted by Andrew Robinson <an...@gmail.com>.
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 <an...@gmail.com> 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 <tr...@gmail.com> 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 <an...@gmail.com> 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 < anthony.bin.hong@gmail.com> 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 <ak...@oytek.com.tr> 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
>

Re: Issues with refresh page in JSF

Posted by Anthony Hong <an...@gmail.com>.
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 <tr...@gmail.com> 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 <an...@gmail.com> 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 < anthony.bin.hong@gmail.com> 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 <ak...@oytek.com.tr> 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

Re: Issues with refresh page in JSF

Posted by Travis Reeder <tr...@gmail.com>.
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 <an...@gmail.com> 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 <an...@gmail.com> 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 <ak...@oytek.com.tr> 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
> >
>

Re: Issues with refresh page in JSF

Posted by Andrew Robinson <an...@gmail.com>.
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 <an...@gmail.com> 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 <ak...@oytek.com.tr> 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
>

Re: Issues with refresh page in JSF

Posted by Anthony Hong <an...@gmail.com>.
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 <ak...@oytek.com.tr> 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

Re: Issues with refresh page in JSF

Posted by aliko <ak...@oytek.com.tr>.
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.