Title: Does anyone have a example to generate a drop down list?
Your form should have a way to initialize the Form.  Some people call an initialize method in the Form class from the Action class like this:
 
myPageAction?do
 
where myPageAction.do calls a method from myPageForm.java like this:
 
myForm.initializeVariables();
return mapping.findForward("refresh");
 
This would essentially load up the arraylist and any variables you want from the DB and then return control to the JSP in the refresh.
 
Alternately, you could have a method in your JSP that calls the initializeVariables(); function.  That way, you could just call the JSP (hyperlink to it) and it would call the initializeVariables() method to load up the arraylist.
 
Either way, you would put the code listed below in a method in your Form (ie. initializeVariables(); )
 
Hope this helps :-)
 
 
 
 
----- Original Message -----
From: Joyce Tang
Sent: Saturday, May 19, 2001 8:46 PM
Subject: RE: Does anyone have a example to generate a drop down list?

Thank you very much, Spencer,
 
I tried it out, it is working.
 
I don't know where to put the code in the FORM, so I put it in the action class.  And I had to add this line of code in my

request.setAttribute("org.apache.struts.taglib.html.BEAN", form)

to make it working.

So where should I put the code to create the arrays?  Why did I have to put the line in?

 THanks a lot,

Joyce

 -----Original Message-----
From: Spencer Smith [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 18, 2001 11:41 AM
To: [EMAIL PROTECTED]
Subject: Re: Does anyone have a example to generate a drop down list?

 
IN FORM:
 
   // Get all xxx Values for DropDown.
   xxxDropDown[] results = profileSession.getxxxValues();   
   
   // Create the arrays for the labels and values.
   xxxLabels = new ArrayList();
   xxxValues = new ArrayList();
   
   // For each value returned...
   for (int i = 0; i < results.length; i ++)
   {
    // Add a label and a value to the corresponding list.
    xxxLabels.add(new String(results[i].getLabel()));
    xxxValues.add(new String(results[i].getValue()));
   }
 
 
IN JSP:
 
  <html:select property="selectedValue">
       <html:options property="xxxValues" labelProperty="xxxLabels"/>
  </html:select>
 
Make sure to define the xxxLabels and xxxValues as type ArrayList and import the class.
 
Hope this helps!  :-)
----- Original Message -----
From: Joyce Tang
Sent: Friday, May 18, 2001 10:28 AM
Subject: Does anyone have a example to generate a drop down list?

Assuming I have a object method returning a list of values.  Does anyone have a example to generate a drop down list?

Reply via email to