I have to disagree with you on this point. 

Consider for example a Customer Bean with two addresses: mailingAddress and
deliveryAddress. The deliveryAddress is optional, so can be null. Next, I
try to display (read only) the Customer properties in a JSP Page. In the
current situation, before displaying the JSP page, the deliveryAddress
object must exist. That is, I have to create a deliveryAddress with empty
fields if a deliveryAddress is null, only for letting the Struts tag
(property or write) do it's work. Why not display all requested properties
of the deliveryAddress as a zero lenght string if the deliveryAddress is
null. I do not like to change a model bean (model as Model in the MVC
pattern) only for getting it displayed correctly on a JSP page.

I agree that when trying to update or create Customer properties, an
initialized deliveryAddress should be there, but then in the Form Bean.

Arjan Kok

> -----Original Message-----
> From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, January 11, 2001 6:49 PM
> To: [EMAIL PROTECTED]
> Subject: Re: cvs commit: jakarta-struts/web/test html-multibox.jsp
> html-setters.jsp
> 
> 
> "Kok, Arjan" wrote:
> 
> > Hello Craig,
> >
> > What happens if in the code snippet <html:text
> > property="mailingAddress.street"/> mailingAddress is null? 
> I would expect
> > Struts not to raise an exception for initial display when 
> mailingAddress is
> > null, because Struts will also not raise an exception when 
> street is null.
> > If Struts raises an exception in the former, I would like 
> an opportunity in
> > Struts to check if there is a nested bean (e.g. by extending the
> > logic:present tag).
> >
> 
> Right now, Struts would throw an IllegalArgumentException 
> ("Null property value
> for 'mailingAddress'") if the mailingAddress property is null.
> 
> If mailingAddress is not null, but mailingAddress.street is 
> null, a null will be
> returned from PropertyUtils.getProperty(), which will 
> ultimately display as a
> zero length string in an <html:text> tag.
> 
> IMHO this is appropriate behavior.  It is up to the 
> application designer to
> ensure that all of the property values before the last one in a nested
> expression are valid and non-null.  In Java terms, that means 
> the tags expect
> you to have initialized an Address with empty fields, and called
> setMailingAddress() on your underlying bean, as part of the 
> initial setup of the
> "outer" bean.
> 
> 
> >
> > Arjan Kok.
> 
> Craig
> 
> 

Reply via email to