Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session.getattribute question

 
Randall Stewart
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64712
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Randall Stewart
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic