Two Laptop Bag*
The moose likes Struts and the fly likes Prepopulating a jsp form before submitting - using Struts? 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 » Frameworks » Struts
Bookmark "Prepopulating a jsp form before submitting - using Struts?" Watch "Prepopulating a jsp form before submitting - using Struts?" New topic
Author

Prepopulating a jsp form before submitting - using Struts?

Amit Saini
Ranch Hand

Joined: Oct 20, 2004
Posts: 280
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 ]
Sree Jag
Ranch Hand

Joined: Oct 14, 2003
Posts: 77
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


Sree Jag<br />SCJP 1.4
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
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.


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prepopulating a jsp form before submitting - using Struts?