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:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to