views:

532

answers:

3

Hi all,

I am setting the value(kind of default value) for a drop down select value from action class in a page(given below). When the page loads the value is beig displayed but the other elements of the dropdown list is not displayed. here is the code.

Inside the action class
if(getTypeId() == null){
     String typeId = request.getParameter("typeId");
     setTypeId(typeId);
     }

Inside the jsp page

 <tr>
        <s:select label="To" headerKey="-1" headerValue="--Please Select--" name="typeId" list="typesofteam"  />
    </tr>

What I am trying to do is create a single page for sending as well as saving the mail as draft. The code works fine for composing the message ie I am able to access the selected item from the action class. But I don't know how to set the drop down element from the action class. The above method just sets the value but the other elements in the list is not displayed.

I will be very grateful for any help on this.

Thanks, Aditya

A: 

Make getTypeId function inside your action / helper class to populate typesofteam list. Struts2 automatically invokes getters for name using ognl.

Nrj
Will try that. Thanks a lot.
Aditya R
A: 

To populate the list, define a method in your action class:

public List<String> getTypesofteam() {
    // return types here
}
Toper
A: 

Just assign it in the constructor of the action class.

BalusC