This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ruchira Ghosh
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ruchira Ghosh
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 477
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic