FileDocCategorySizeDatePackage
ComboBox.javaAPI DocExample7463Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

ComboBox

public class ComboBox extends TextField
The combo box is basically an HTML INPUT of type text and HTML SELECT grouped together to give you a combo box functionality. You can place text in the INPUT control by using the SELECT control or type it in directly in the text field.

In this example, the SELECT will be populated from id=year attribute. Counter is itself an Iterator. It will span from first to last. The population is done via javascript, and requires that this tag be surrounded by a <form>.

Note that unlike the <s:select/> tag, there is no ability to define the individual <option> tags' id attribute or content separately. Each of these is simply populated from the toString() method of the list item. Presumably this is because the select box isn't intended to actually submit useful data, but to assist the user in filling out the text field.

Examples


JSP:
<-- Example One -->
<s:bean name="struts.util.Counter" id="year">
<s:param name="first" value="text('firstBirthYear')"/>
<s:param name="last" value="2000"/>

<s:combobox label="Birth year" size="6" maxlength="4" name="birthYear" list="#year"/>
</s:bean>

<-- Example Two -->


<-- Example Two -->


Velocity:
#tag( ComboBox "label=Birth year" "size=6" "maxlength=4" "name=birthYear" "list=#year" )

Fields Summary
public static final String
TEMPLATE
protected String
list
protected String
listKey
protected String
listValue
protected String
headerKey
protected String
headerValue
protected String
emptyOption
Constructors Summary
public ComboBox(com.opensymphony.xwork2.util.ValueStack stack, HttpServletRequest request, HttpServletResponse response)



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

        super.evaluateExtraParams();

        Object value = findListValue();

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

        if (value != null) {
            if (value instanceof Collection) {
                Collection tmp = (Collection) value;
                addParameter("list", tmp);
                if (listKey != null) {
                    addParameter("listKey", listKey);
                }
                if (listValue != null) {
                    addParameter("listValue", listValue);
                }
            } else if (value instanceof Map) {
                Map tmp = (Map) value;
                addParameter("list", MakeIterator.convert(tmp));
                addParameter("listKey", "key");
                addParameter("listValue", "value");
            } else if (value.getClass().isArray()) {
                Iterator i = MakeIterator.convert(value);
                addParameter("list", i);
                if (listKey != null) {
                    addParameter("listKey", listKey);
                }
                if (listValue != null) {
                    addParameter("listValue", listValue);
                }
            } else {
                Iterator i = MakeIterator.convert(value);
                addParameter("list", i);
                if (listKey != null) {
                    addParameter("listKey", listKey);
                }
                if (listValue != null) {
                    addParameter("listValue", listValue);
                }
            }
        }
    
protected java.lang.ObjectfindListValue()

        return findValue(list, "list",
                "You must specify a collection/array/map/enumeration/iterator. " +
                "Example: people or people.{name}");
    
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 voidsetList(java.lang.String list)

        this.list = list;
    
public voidsetListKey(java.lang.String listKey)

        this.listKey = listKey;
    
public voidsetListValue(java.lang.String listValue)

        this.listValue = listValue;