You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chetan Pandey <cp...@bluesingapore.com> on 2007/01/09 03:30:45 UTC

Browser Back Button

Hi All:

 

I have a Web App in which I can add/edit/delete and list events using an
eventForm Object which is stored in session in the struts-config action
declaration.

 

Addition/Deletion/Editing works perfectly but if I click on an Event for
Editing and later try to add an Event, the previous Events details will
populate my Add Event Form as "eventForm" is shared by both and also share
the same jsp.

 

To avoid this problem I introduced the following
request.getSession().setAttribute("eventForm", new EventForm()).

 

This solved the problem. However now I have another problem

 

I go to the form page and then click add. It goes to the Preview page.
Everything shows perfectly. Now I click on the Back Button. Lo and Behold
!!!!! The Add Fields are all empty.

 

Pls can someone tell me how to get rid of this problem.

 

Thanks.

 

Chetan

_____________________________________________________________________
CHETAN PANDEY  Executive - Technology Services
BLUE, 1 Maritime Square, #13-02 Harbourfront Centre, Singapore 099253 
DID +65-6212-0863 main line +65-6333-3336 fax +65 6336-6334
email  <ma...@BLUEsingapore.com> cpandey@BLUEsingapore.com website
<http://www.bluesingapore.com/> www.BLUEsingapore.com
_____________________________________________________________________
BEIJING      SHANGHAI       LONDON     TOKYO      PALO ALTO      SINGAPORE

CONFIDENTIALITY STATEMENT: This email and its attachment(s) contain
Privileged/Confidential information. If you are not the intended recipient,
the distribution, use or replication of the information in this email is
strictly prohibited. If you have received this email in error, please notify
the sender immediately by return email, then delete this email and any
attached documents. Any opinions, conclusions or views expressed in this
email are those of the individual sender, except where he/she -- expressly
and with authority  -- states them to be the views of BLUE.

 


RE: Browser Back Button

Posted by Chetan Pandey <cp...@bluesingapore.com>.
Hi Chris:

> What browser are you using? Is your setup action being executed again,
> or is the browser serving the page from the cache? If the browser is not
> contacting the server, there's nothing you can do.

I am using IE 7.0.

Regarding contacting the server, something very weird is happening.

If my execute method has the following line:

request.getSession().setAttribute("eventForm", new EventForm() );

It will contact the Server - as all debug statements are printed.

However, if I remove this one line, then it doesn't contact the server and
fetches everything from cache - since no debug statement is printed.

I have checked other places also. Clicking back button doesn't go to the
server. Since no debug statement is printed.

Only the presence of the above line makes a weird difference.



Chetan Pandey wrote:
> To avoid this problem I introduced the following
> request.getSession().setAttribute("eventForm", new EventForm()).

>If you are using Struts form beans, it might be better to blank the
>existing bean instead of creating a new one. Something like this:

>EventForm ef = (EventForm)form;

>ef.setFoo(null);
>ef.setBar(null);
>// etc.

It didn't help. Still went to the Server.

> I go to the form page and then click add. It goes to the Preview page.
> Everything shows perfectly. Now I click on the Back Button. Lo and Behold
> !!!!! The Add Fields are all empty.

>What browser are you using? Is your setup action being executed again,
>or is the browser serving the page from the cache? If the browser is not
>contacting the server, there's nothing you can do.

> (Actually, that's not true... if you are using javascript to do some
>funny things with the form, submission, etc., then you are likely
>causing your own problems. If, however, your form is standard then the
>browser /should/ be keeping the form data there if you do a SUBMIT
>followed by a BACK).

>If the browser /is/ contacting the server, then you need to look at what
>is happening in your action. For instance, if the above code is running,
>then /of course/ you are ending up with a blank bean.

>One way around this would be to put an action /in front/ of the editing
>action that blanks any existing form bean and then redirects (not
>forwards) to the editing action (which does /not/ blank the bean). In
>this case, you'll get a fresh bean for editing, but pressing BACK will
>result in the user returning to the "edit" action instead of the
>"blank-and-then-edit" action. Of course, if the user presses BACK twice,
>then you'll get a blank bean again. ;)

>Hope that helps,
>- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFo8Iu9CaO5/Lv0PARAtAHAJ9RkZfhNyjOdMttiFmuaO9m7TW74ACeLKxB
jStpytMzn+2l6dPLELV//lo=
=qP9A
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Thanks. 

Chetan




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Browser Back Button

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chetan,

Chetan Pandey wrote:
> To avoid this problem I introduced the following
> request.getSession().setAttribute("eventForm", new EventForm()).

If you are using Struts form beans, it might be better to blank the
existing bean instead of creating a new one. Something like this:

EventForm ef = (EventForm)form;

ef.setFoo(null);
ef.setBar(null);
// etc.

> I go to the form page and then click add. It goes to the Preview page.
> Everything shows perfectly. Now I click on the Back Button. Lo and Behold
> !!!!! The Add Fields are all empty.

What browser are you using? Is your setup action being executed again,
or is the browser serving the page from the cache? If the browser is not
contacting the server, there's nothing you can do.

(Actually, that's not true... if you are using javascript to do some
funny things with the form, submission, etc., then you are likely
causing your own problems. If, however, your form is standard then the
browser /should/ be keeping the form data there if you do a SUBMIT
followed by a BACK).

If the browser /is/ contacting the server, then you need to look at what
is happening in your action. For instance, if the above code is running,
then /of course/ you are ending up with a blank bean.

One way around this would be to put an action /in front/ of the editing
action that blanks any existing form bean and then redirects (not
forwards) to the editing action (which does /not/ blank the bean). In
this case, you'll get a fresh bean for editing, but pressing BACK will
result in the user returning to the "edit" action instead of the
"blank-and-then-edit" action. Of course, if the user presses BACK twice,
then you'll get a blank bean again. ;)

Hope that helps,
- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFo8Iu9CaO5/Lv0PARAtAHAJ9RkZfhNyjOdMttiFmuaO9m7TW74ACeLKxB
jStpytMzn+2l6dPLELV//lo=
=qP9A
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org