FileDocCategorySizeDatePackage
ListUIBean.javaAPI DocExample5817Mon Jul 23 13:26:36 BST 2007org.apache.struts2.components

ListUIBean

public abstract class ListUIBean extends UIBean
DoubleListUIBean is the standard superclass of all Struts list handling components.

Note that the listkey and listvalue attribute will default to "key" and "value" respectively only when the list attribute is evaluated to a Map or its decendant. Other thing else, will result in listkey and listvalue to be null and not used.

Fields Summary
protected Object
list
protected String
listKey
protected String
listValue
protected boolean
throwExceptionOnNullValueAttribute
Constructors Summary
protected ListUIBean(com.opensymphony.xwork2.util.ValueStack stack, HttpServletRequest request, HttpServletResponse response)


           
        super(stack, request, response);
    
Methods Summary
public booleancontains(java.lang.Object obj1, java.lang.Object obj2)

        return ContainUtil.contains(obj1, obj2);
    
public voidevaluateExtraParams()

        Object value = null;

        if (list == null) {
            list = parameters.get("list");
        }

        if (list instanceof String) {
            value = findValue((String) list);
        } else if (list instanceof Collection) {
            value = list;
        } else if (MakeIterator.isIterable(list)) {
            value = MakeIterator.convert(list);
        }
        if (value == null) {
            if (throwExceptionOnNullValueAttribute) {
                // will throw an exception if not found
                value = findValue((list == null) ? (String) list : list.toString(), "list",
                    "The requested list key '" + list + "' could not be resolved as a collection/array/map/enumeration/iterator type. " +
                    "Example: people or people.{name}");
            }
            else {
                // ww-1010, allows value with null value to be compatible with ww
                // 2.1.7 behaviour
                value = findValue((list == null)?(String) list:list.toString());
            }
        }

        if (value instanceof Collection) {
            addParameter("list", value);
        } else {
            addParameter("list", MakeIterator.convert(value));
        }

        if (value instanceof Collection) {
            addParameter("listSize", new Integer(((Collection) value).size()));
        } else if (value instanceof Map) {
            addParameter("listSize", new Integer(((Map) value).size()));
        } else if (value != null && value.getClass().isArray()) {
            addParameter("listSize", new Integer(Array.getLength(value)));
        }

        if (listKey != null) {
            addParameter("listKey", listKey);
        } else if (value instanceof Map) {
            addParameter("listKey", "key");
        }

        if (listValue != null) {
            if (altSyntax()) {
                // the same logic as with findValue(String)
                // if value start with %{ and end with }, just cut it off!
                if (listValue.startsWith("%{") && listValue.endsWith("}")) {
                    listValue = listValue.substring(2, listValue.length() - 1);
                }
            }
            addParameter("listValue", listValue);
        } else if (value instanceof Map) {
            addParameter("listValue", "value");
        }
    
protected java.lang.ClassgetValueClassType()

        return null; // don't convert nameValue to anything, we need the raw value
    
public voidsetList(java.lang.Object list)

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

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

        this.listValue = listValue;
    
public voidsetThrowExceptionOnNullValueAttribute(boolean throwExceptionOnNullValueAttribute)

        this.throwExceptionOnNullValueAttribute = throwExceptionOnNullValueAttribute;