struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Nocera" <rnoc...@neosllc.com>
Subject RE: null value for a nested property
Date Thu, 07 Mar 2002 17:46:48 GMT
David,

I find it's best to use a form bean that is different from your data
object, so that your get methods on your form object can return an empty
string if null instead of actually returning a null value.

Robert Nocera
New England Open Solutions
www.neosllc.com
"You supply the vision, we'll do the rest."
 

-----Original Message-----
From: David Boardman [mailto:dboardman@wagpaw.com] 
Sent: Thursday, March 07, 2002 12:49 PM
To: Struts Users Mailing List
Subject: null value for a nested property

I currently am using an <html:text> tag on a form to display the name of
a
state.  The tags looks like:

	<html:text name="address" property="state.name"/>


The problem is that ocassionally the state field on the address bean is
null.  When this occurs the PropertyUtils.getNestedProperty() method
throws
an IllegalArgumentException which causes my jsp to break.  To circumvent
this problem I have written my own tag that extends BaseFieldTag and
overrides the doStartTag() method.  I basically perform the same
functions
as the BaseFieldTag.doStartTag() method, except that instead of the
following call:

	Object value = RequestUtils.lookup(pageContext, name, property,
null);

to get the value I catch the IllegalArgumentException and set the return
value to an empty string:

	  try{
            valueObject = RequestUtils.lookup(pageContext, name,
                                            property, null);
        }catch(IllegalArgumentException e){
            //This exception indicates that one of the nested properties
returned null
            //we want to set the value to null and not throw the
exception
out
            //to the jsp
            valueObject = "";
        }

I am wondering if there is a better way of dealing with this problem.  I
don't like the solution I am using, but I can't think of anything else.
How
about adding an attribute to the form tags that specify how null
property
values should be handled?

Thanks for your help,

Dave


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


--
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