Making a SELECT box in Struts, usually write a message bean yourself to store the values and display content in the Option box. This bean should have two properties by default: Label and Value.Label are used to display, Value is the value corresponding to Lable. A Collection is then made to store each instance of this information bean. It can be displayed by using the Struts tag.
The problem I encountered when I was doing:
1. How to set the default value for Options.
By studying the Struts documentation, it is found that in the SELECT label, such as the Name and the Value property can achieve the purpose. Suppose your information in your information bean is: Label and Value. Then you can write name = "value" value = "1" means that the instance of the value attribute = 1 in the bean is used as the default. This is optimistic about the icon, we only need to set the required variables in value = '
2, how the default value is determined
Because you cannot use the Struts tag to give the Value to the default value. I tested, this is not, if you use constants, it is ok. I think it may be that the value value in the Struts parsing tag may be parsed after the entire SELECT box is determined. So you can't use the Struts tag to give the default value. Later I got the default value directly in the action, and then assigned the value with request.settribute, and then use Request.GetaTribute on the page to get the value. This is feasible, but it is not very elegant, I don't know if there is a more elegant approach?