FileDocCategorySizeDatePackage
Select.javaAPI DocExample5245Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

Select

public class Select extends ListUIBean
Render an HTML input tag of type select.

Examples



<s:select label="Pets"
name="petIds"
list="petDao.pets"
listKey="id"
listValue="name"
multiple="true"
size="3"
required="true"
/>

<s:select label="Months"
name="months"
headerKey="-1" headerValue="Select Month"
list="#{'01':'Jan', '02':'Feb', [...]}"
value="selectedMonth"
required="true"
/>

// The month id (01, 02, ...) returned by the getSelectedMonth() call
// against the stack will be auto-selected


Note: For any of the tags that use lists (select probably being the most ubiquitous), which uses the OGNL list notation (see the "months" example above), it should be noted that the map key created (in the months example, the '01', '02', etc.) is typed. '1' is a char, '01' is a String, "1" is a String. This is important since if the value returned by your "value" attribute is NOT the same type as the key in the "list" attribute, they WILL NOT MATCH, even though their String values may be equivalent. If they don't match, nothing in your list will be auto-selected.

Fields Summary
public static final String
TEMPLATE
protected String
emptyOption
protected String
headerKey
protected String
headerValue
protected String
multiple
protected String
size
Constructors Summary
public Select(com.opensymphony.xwork2.util.ValueStack stack, HttpServletRequest request, HttpServletResponse response)


           
        super(stack, request, response);
    
Methods Summary
public voidevaluateExtraParams()

        super.evaluateExtraParams();

        if (emptyOption != null) {
            addParameter("emptyOption", findValue(emptyOption, Boolean.class));
        }

        if (multiple != null) {
            addParameter("multiple", findValue(multiple, Boolean.class));
        }

        if (size != null) {
            addParameter("size", findString(size));
        }

        if ((headerKey != null) && (headerValue != null)) {
            addParameter("headerKey", findString(headerKey));
            addParameter("headerValue", findString(headerValue));
        }
    
protected java.lang.StringgetDefaultTemplate()

        return TEMPLATE;
    
public voidsetEmptyOption(java.lang.String emptyOption)

        this.emptyOption = emptyOption;
    
public voidsetHeaderKey(java.lang.String headerKey)

        this.headerKey = headerKey;
    
public voidsetHeaderValue(java.lang.String headerValue)

        this.headerValue = headerValue;
    
public voidsetMultiple(java.lang.String multiple)

        this.multiple = multiple;
    
public voidsetSize(java.lang.String size)

        this.size = size;