File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Fields in JSP Page is containing the value from the previous load of the page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Fields in JSP Page is containing the value from the previous load of the page" Watch "Fields in JSP Page is containing the value from the previous load of the page" New topic
Author

Fields in JSP Page is containing the value from the previous load of the page

Ruchira Ghosh
Greenhorn

Joined: Nov 25, 2010
Posts: 13
I am facing a strange issue of fields in a jsp page retaining old values.

I have a jsp page with a field Type Name and two buttons to Add and Edit.
On click of the buttons the request submitted to the controller which adds appropriate request/session attribute for Add/Edit and forward the request to the same jsp which has 3 fields, TypeName,Description and Associated Id and a button to search the id and one OK and one Cancel button. In the page the fields are populated from request and session attributes using scriptlets by setting the value in the field declaration
The cancel button clears all the field values and submits the request to a controller method which removes session attributes set.
The button to search for the id has a validation code to verify the Name is entered.

Now the problem is once I open the jsp for Add and cancel it and immediately after I opens the page for Edit, the fields retains the old value that is '' , though the session and request parameter that sets the value contains proper value. Only when the value is accessed using document.getElementById('fldId').value it is returning the value from the last load of the page. It is happening for every consecutive load of the page.

The field value is being shown properly in UI, but the validation code that checkes if the field has value is getting failed.

Can any one point out what is the problem?
The page has HTTP tags for no-cache.

Thanks,
ruchiraghosh
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

If you are using beans , are they set to session attribute ? If they are , then the previous values will be maintained , you could try setting the scope to request.


Learning and Learning!-- Java all the way!
Ruchira Ghosh
Greenhorn

Joined: Nov 25, 2010
Posts: 13

I am not using beans.
The values are being set just as follows. The other field uses a session attribute if request parameter is null.

I checked putting alerts in java script.
The expression <%=typename%> is showing proper value while document.getElementById(myField).value is showing the old value.

Thanks for any help.
Ruchira
Ruchira Ghosh
Greenhorn

Joined: Nov 25, 2010
Posts: 13
A header page included was copying each field with same id and keeping them as hidden.
The problem was due to the hidden fields.

Thanks,
Ruchira
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Great!
 
GeeCON Prague 2014
 
subject: Fields in JSP Page is containing the value from the previous load of the page