Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Prepopulating a jsp form before submitting - using Struts?

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
Im trying to create a form in jsp (using struts framework).
I'm trying to add some data to the database.
But one of the form elements is a select box which I need to be prepopulated from the database when the form loads.

I am able to submit the form using the Form bean and Action bean but I dont understand how can I pre-populate the select box when the page loads.

Can anyone give me any hint? I think I might have to create another action bean but I'm just not sure. I'd appreciate if someone can point out the steps for prepopulating.

Thanks once again
[ April 21, 2005: Message edited by: Amit Saini ]
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I think I might have to create another action bean but I'm just not sure.



Exactly...It's a best practice to access a JSP via a Action. So that the data for JSP can be constructed by the action file.

Seshu
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
say your select box form-property is defined as 'hasAccess'. your form output will be <input type="checkbox" name="hasAccess" value="Y"/> (you can rewrite this in html:checkbox yourself).

"Y" is the true/false value that comes from the database.

to pre-populate this, in your Action class, you need to call form.set("hasAccess", myValue); where "form." is your action form and where 'myValue' is the variable that stores the information that comes from the database.
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!