1

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
Vargan
  • 1,277
  • 1
  • 11
  • 35
  • 1
    I don't do Tiles, so I have no utter idea about its internals, but first thing I would try is to use `java.lang.Boolean` as type/classname instead. The attribute map can't hold primitives as values. From Java code on, Java 5 autoboxing will silently convert it to `Boolean`, which is not a `boolean` at all. Usually, JSP tags don't do that. At least, that's the theory :) Give it a try in practice. – BalusC Dec 21 '12 at 17:04
  • Many thanks!! :) it working now! if you give this comment as a response I take your responce as preferred :) – Vargan Dec 21 '12 at 17:18

1 Answers1

2

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" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555