tilesstruts-1

Struts 1 - Tiles put boolean attribute


Is possible to put a primitive type, like a boolean as attribute?

pageContext.setAttribute("boolValue", boolValue);

and then

<tiles:put name="boolValue" beanName="boolValue" type="boolean" />

in the other Jsp I use:

<tiles:useAttribute name="boolValue" id="boolValue" classname="boolean" />

I get this error:

PWC6199: Generated servlet error:
string:///BaseBudgetLayout_jsp.java:124: incompatible types
found   : <nulltype>
required: boolean
PWC6199: Generated servlet error:
string:///BaseBudgetLayout_jsp.java:125: inconvertible types
found   : java.lang.Object
required: boolean

Solution

  • The attribute map can't hold primitives as values. Given that it takes java.lang.Object, Java 5 autoboxing would silently have turned the boolean primitive into a java.lang.Boolean instance. This is technically not a boolean at all, so the type/classname in your Tiles tags would not match.

    Instead, use

    <tiles:put name="boolValue" beanName="boolValue" type="java.lang.Boolean" />
    

    and

    <tiles:useAttribute name="boolValue" id="boolValue" classname="java.lang.Boolean" />