struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin HaleBoyes <kzbo...@yahoo.com>
Subject RE: repeating input fields
Date Mon, 14 Oct 2002 17:53:41 GMT
> instead of:
>   property="id"
>   property="description"
> 
> use:
>   property="purposes[1].id"
>   property="purposes[1].description"

That makes sense!  I made the changes to the JSP file and also
added indexed getter/setter to the form bean.

  public class LoansForm extends ActionForm {
    private LoansPurpose[] purposes = null;
    public LoanPurpose[] getPurposes()
                               {return purposes;}
    public void setPurposes( LoanPurpose[] v )
                               {purposes = v;}
    public LoanPurpose getPurposes( int idx )
                               {return purposes[idx];}
    public void setPurposes( int idx, LoanPurpose v )
                               {purposes[idx] = v;}
    public void reset(ActionMapping mapping,
               HttpServletRequest request) {purposes = null;}
  }

But now when I submit the "Save" I'm getting an exception

javax.servlet.ServletException: BeanUtils.populate
...
----- Root Cause -----
java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown
Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:475)
        at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:410)
        at
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:749)
        at
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:780)
        at
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:793)
        at
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:726)
        at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:978)


Caused by: java.lang.NullPointerException
        at
com.illuminat.cml.LoansForm.getPurposes(LoansForm.java:1420)
        ... 49 more

(obviously, I've trimmed the exception report)

Line 1420 of LoansForm.java is the indexed getter.  So my purposes
array is null and I'm trying to get the value at a particular index
(idx=3 in this test run).
The array is null because I set it to that in the reset() method.
That's what I'm supposed to do though, isn't it?

How can I "know" to allocate the array and what size it should be?
I'm missing something here!  For instance, I'm executing a "Save"
so why is the indexed getter being called and not the indexed
setter?

> This should get you started...

It did indeed, and I thank you for that.  Unfortunately, it has
raised more questions and I'm at a loss as to how to proceed!

Thanks again,
Kevin

__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com

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