Suppose you declare list of companies as:
private List<Company> companies = new ArrayList<Company>();

Now you got to have getter for this property as:

public List<Company> getCompanies(){
   return companies;
}

You can prepopulate your companies list implementing Preparable interface in
your action. Upon implementing you will have to override prepare method as:
public void prepare() throws Exception {
       companies =//use data access methods or whatever you have to fetch
the companies
    }

you can use following tag to display the dropdown box:
<s:select label="Select Company"
        name="company" list="companies" listKey="companyId"
        listValue="companyName"/>

you can fetch the selected company as id declaring a property as the name of
the dropdown box as:
private Long company;
you got to have setter for this property as:
private void setCompany(Long id){
   company = id;
}

so the submitted value will be set in that property.

On 2/14/08, Jack Haynes <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
>
> I have a list of objects in my action.  Each object in the list represents
> a Company.  I want to populate
> my dropdown box, in my jsp, with company names.  When a companyName is
> selected in the dropdown
> box, the companyID (which corresponds to the companyName) will be sent
> upon form submit.  For
> example, if the user selects "companyA", in the combo box, "1" will be
> submitted.
>
> companyName-------->companyID
> companyA-------------->1
> companyB-------------->2
>
> Any hints or sample code would be appreciated.
>
> Thanks,
> Jack
> _________________________________________________________________
>
>


-- 
Thanks,
Prashant Khanal

Reply via email to