开发者

Setting the default value in Struts2

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


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


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

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


Just assign it in the constructor of the action class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜