struts-user mailing list archives

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

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
"You supply the vision, we'll do the rest."

-----Original Message-----
From: David Boardman [] 
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
state.  The tags looks like:

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

The problem is that ocassionally the state field on the address bean is
null.  When this occurs the PropertyUtils.getNestedProperty() method
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
as the BaseFieldTag.doStartTag() method, except that instead of the
following call:

	Object value = RequestUtils.lookup(pageContext, name, property,

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

            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
            //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.
about adding an attribute to the form tags that specify how null
values should be handled?

Thanks for your help,


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message