struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Schneider <k...@dotech.com>
Subject Re: <bean:write> not writing?
Date Sat, 27 Dec 2003 20:12:43 GMT
I doubt JSTL will be any happier with a class that's trying to be both a 
Map and a JavaBean:

<%@ page contentType="text/plain" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<jsp:useBean id="map" class="java.util.HashMap"/>
<jsp:useBean id="obj" class="java.lang.Object"/>
map.class: <c:out value="${map.class}"/>
obj.class: <c:out value="${obj.class}"/>
<c:set target="${map}" property="class" value="Employee"/>
map.class: <c:out value="${map.class}"/>

Produces:

map.class:
obj.class: class java.lang.Object

map.class: Employee

Jason Lea wrote:

> I have read about people having problems getting or setting a bean which 
> does not fit the bean specification.  In that case the Cart object would 
> also need a setSubTotal(double dbl) method, even if it is not used eg
> 
> public class Cart extends HashMap {
>    private double subTotal = 400.00;
>    public double getSubTotal(){return subTotal;}
>    public void setSubTotal(double dbl){subTotal=dbl;}
> }
> 
> 
> This could be the problem because the bean:write would expect a bean, 
> but the <%...%> is just accessing an object's method.
> 
> Also the way to access maps in struts is object(value) eg <bean:write 
> name="cart(abc)"/>
> 
> Which is roughly the same as <c:out value="${cart.abc}" />
> 
> These should perform the following:   cart.get("abc")
> 
> 
> 
> Michael Marrotte wrote:
> 
>> Here's the bean:
>>
>> public class Cart extends HashMap {
>>    private double subTotal = 400.00;
>>    public double getSubTotal(){return subTotal;}
>> }
>>
>>
>> Here's the Java:
>>
>> session.setAttribute("cart", new Cart());
>>
>>
>> Here's the JSP
>>
>> <bean:write name="cart" property="subTotal"/> // no output?
>> <%= ((csp.Cart)session.getAttribute("cart")).getSubTotal() %> // works,
>> writes 400.0
>>
>>
>> Here's the problem
>>
>> <bean:write> isn't producing any output, but
>>
>> <%= ... %> is...
>>
>> Any ideas are greatly appreciated.
>>
>> Thanks,
>>
>> --Mike M.

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



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


Mime
View raw message