The book forum for "Struts in Action" appears to be down, so thought I'd
try here. Apologies if you don't have the book.
I am attempting to use a map in my form bean to pass data back and forth
from my business tier, as described on pp. 172-173 in "Struts in
Action". The code within the form bean is exactly as shown on p. 172,
excepting that I added a couple of lines to the setValue method so that
it reads:
public void setValue(String key, Object value) {
if (key != null && value != null) {
getMap().put(key,value);
}
}
When retrieving data from the database, the map comes in from the action
and populates the form widgets on my jsp page without difficulty.
However, when I try to submit the page to send the data back, I get a
NullPointerException from the setValue method:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.apache.commons.beanutils.PropertyUtils.setMappedProperty(PropertyUtils.java:1583)
... >< snip >< ...
Caused by: java.lang.NullPointerException
at
us.mn.state.dnr.fire.FireReportForm.setValue(FireReportForm.java:270)
... 44 more
The line referred to (FireReportForm.java:270) is the
"getMap().put(key,value)" statement.
I've tried another reader's suggestion of changing
private Map map = null;
to
private Map map = new HashMap();
which gets past the NullPointerException, but then triggers a validator
error for a simple "required" field, which actually shows data in the
form.
Can anyone clue me in as to what I might be doing wrong?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]