struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject Re: Using the "key" of a HashMap in an html:option tag ?
Date Wed, 11 Dec 2002 16:39:12 GMT
The problem is that the type of the property that the tag handler exposes as an
attribute has to be assignable from the type of the expression. Taking the
current example:

<html:select styleClass="field" property="assignedTo">
  <logic:iterate id="element" name="employees">
    <html:option value="<%= ((java.util.Map.Entry)element).getKey() %>">
      <bean:write name="element" property="value.firstName"/>
      <bean:write name="element" property="value.lastName"/>
    </html:option>
  </logic:iterate>
</html:select>

The type of the expression is Object and the type of the tag handler's
(OptionTag) value property is String. So you'll end up with a compilation error
like:

setValue(java.lang.String) in org.apache.struts.taglib.html.OptionTag cannot be
applied to (java.lang.Object)

In which case, either of these should work:

<%= ((java.util.Map.Entry)element).getKey().toString() %>
<%= String.valueOf(((java.util.Map.Entry)element).getKey()) %>

If you know that the key really is a String, you could also cast:

<%= (String)((java.util.Map.Entry)element).getKey() %>

Quoting Rick Reumann <maillist@reumann.net>:

> On Tuesday, December 10, 2002, 5:06:26 PM, Kris wrote:
> 
> KS> Glad it's working, but I don't understand why you'd have a problem with
> the JSP
> KS> expression. IIRC, it's equivalent to the following code getting generated
> within
> KS> the page's _jspService method:
> 
>     Trust me I don't know either. I'm using Tomcat 4.0.6 if that
>     matters. It only causes me this problem when inside of a tag
>     trying to use <%= . I don't get it. Has anyone else ever ran into
>     this situation?
> 
>     
> -- 
> 
> Rick
> mailto:maillist@reumann.net
> 
> 
> --
> To unsubscribe, e-mail:  
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>

-- 
Kris Schneider <mailto:kris@dotech.com>
D.O.Tech       <http://www.dotech.com/>

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message