This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSP and the fly likes session.getattribute question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "session.getattribute question" Watch "session.getattribute question" New topic
Author

session.getattribute question

Randall Stewart
Greenhorn

Joined: Aug 19, 2004
Posts: 2
Hi,

I'm kind of new to the jsp world and have a question related to restoring html form fields dynamically using session.getattribute and javascript looping through the document.form.elements. Is there a way to do this. I am using WebSphere Development Studio Client as my development bench accessing an IBM Iseries DB2 data base through WAS 5.0. I am able to do it for each form element by name but there are many pages and many elements.

Thanks,
Randall
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Randal,

If what you mean to do is to have a client submit a form, and then if you need to display it again, populate it with the data sent by the client, then you can do it with a combination of JSP-JavaBeans.

Create a JavaBean with instance member names matching the input element names in the form. When the user submits the form, use <jsp:setProperty> tag to store all the data submitted in the JavaBean. If you need to display the form again, use that bean to populate it with the values sent by client earlier.

HTH


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Sonny's point is that you do not need to use client-side Javascript to accomplish this. In fact, that's a mechanism I would not recommend.

Use server-side JSP mechanims to set the value attribute of the form controls to the desired values.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Randall Stewart
Greenhorn

Joined: Aug 19, 2004
Posts: 2
Thanks for the reply.

So this would reload all of the html form fields defined in the bean class from the session?

<jsp:setProperty name="xyz" property="*" />

and this would do just one of the elements?

<jsp:setProperty name="xyz" property="field" value="value"/>

How would I clear out the old data the next visit to the page from a prompt page?

Also where in the HTML form would I place the code? I have an onLoad function and onUnload already built.

I don't mean to be stupid with this but IBM has been NO help on this.

Thanks again for you patience.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session.getattribute question