English 中文(简体)
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.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签