public class PropertyEditForm extends ActionForm {
//bla bla}
public class PropertyListForm extends ActionForm {
private ArrayList propertyList;
public PropertyListForm() {
this.propertyList = new ArrayList();
} public PropertyEditForm getProperty(int i) {
return (PropertyEditForm) propertyList.get(i);
} public void setProperties(Object[] properties) {
..
}
public void setProperty(int i, PropertyEditForm property) {
propertyList.add(i, property);
}}
On 14 Jan 2004, at 14:38, Nathan Ewing wrote:
Basically all I have is 1 form bean that includes 2 arrays of itself in it.
When the app runs it gets 2 lists of the different categories of
SoldProperty and makes a jsp form that allows you to change certain details
of the beans all at once, and then if you click on one of the beans you can
edit them individually.
There are actually two actions, one is PropertyList, which only loads and
manages those two arrays of beans, and then there is PropertyEdit, which
works on an individual bean, and ignores the two lists.
I hope this makes sense.
The code I posted below is a shortcut I put in all my beans. I overrode
ActionForm and put a couple extra functions in. One of them automatically
resets all the variables in the bean for me without having to manually write
a reset function for every bean to do the same thing.
The other changes the way validate works. Instead of 1 function that does
all the validating, I write individual validateAttributeName() functions and
the code below just calls all of them for me. Of course none of the
validate code matters, cause I didn't call it here (which makes me wonder
why I bothered to post it).
Somehow I doubt you are stupid :)
I hope I didn't make all this sounds more complicated than it is. All I
really wanna do is allow the users of my site to check a bunch of checkboxes
all at once for multiple records instead of opening them all individually.
Thanks, Nathan
-----Original Message----- From: Mark Lowe [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 14, 2004 9:17 AM To: Struts Users Mailing List Subject: Re: BeanUtils.populate Invocation Error
Looks complicated what are you trying to do? Sorry I'm pretty stupid and so i try and keep things simpler.
On 14 Jan 2004, at 13:55, Nathan Ewing wrote:
I posted much of the form bean code at the bottom. Aside for the two arrays of SoldProperty, there are a bunch of getString and setString. This is part of the bean SoldProperty (aka there are two arrays of SoldProperty in the SoldProperty bean).
I altered the validate code and reset code so that it does the validating and resetting for me, as follows:
If there is anything else you need please let me know.
Nathan --------------------------------------------------------------------
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request, String[] propertyList) { //Reset errors errors = new ActionErrors(); ClassManager manager = new ClassManager (this); for (int a = 0; a < propertyList.length; a++){ try { String methodName = "validate" + propertyList[a]; manager.runNoArgMethod(methodName); } catch (NoSuchMethodException e){ //Method Doesn't exist, Don't worry about it } catch (IllegalAccessException e){ } catch (java.lang.reflect.InvocationTargetException e){}
} return errors; }
public void reset(ActionMapping mapping, HttpServletRequest request) { ClassManager manager = new ClassManager (this); for (int a = 0; a < DataMembers.length; a++){ try { String methodName = "set" + DataMembers[a]; Class[] argTypes = {String.class}; Object[] args = {null}; manager.runMethod(methodName, argTypes, args); } catch (NoSuchMethodException e){ //Method Doesn't exist, Don't worry about it } catch (IllegalAccessException e){ } catch (java.lang.reflect.InvocationTargetException e){}
} }
-----Original Message----- From: Mark Lowe [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 14, 2004 4:12 AM To: Struts Users Mailing List Subject: Re: BeanUtils.populate Invocation Error
I had a similar problem yesterday with multiple selected select menus. What does your form bean look like and then your nested beans.
On 14 Jan 2004, at 03:57, Nathan Ewing wrote:
I have a jsp page with a form on it using indexed properties. I have a bean with an array of beans that I use to connect with the jsp page. The page displays fine, but when I try to save it, I get the following error:
javax.servlet.ServletException: BeanUtils.populate
at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254)
at
org.apache.struts.action.RequestProcessor.processPopulate(RequestProc e
s
sor.j
ava:821)
at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja v
a
:254)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:
1482)
at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.StandardWrapperValve.invokeServletService(St a
n
dardW
rapperValve.java:720)
at
org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrap p
e
rValv
e.java:118)
at
org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperVa l
v
e.jav
a:278)
at java.security.AccessController.doPrivileged(Native Method)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV a
l
ve.ja
va:274)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a
:
505)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV a
l
ve.ja
va:212)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a
:
505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j a
v
a:203
)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a
:
505)
at
com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProce s
s
or.ja
va:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
Root Cause
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. j
a
va:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces s
o
rImpl
.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(Propert y
U
tils.
java:493)
at
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(Propert y
U
tils.
java:428)
at
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(Property U
t
ils.j
ava:770)
at
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils. j
a
va:80
1)
at
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java: 881)
at
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
at
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
at
org.apache.struts.action.RequestProcessor.processPopulate(RequestProc e
s
sor.j
ava:821)
at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.ja v
a
:254)
at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:
1482)
at
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.StandardWrapperValve.invokeServletService(St a
n
dardW
rapperValve.java:720)
at
org.apache.catalina.core.StandardWrapperValve.access$000(StandardWrap p
e
rValv
e.java:118)
at
org.apache.catalina.core.StandardWrapperValve$1.run(StandardWrapperVa l
v
e.jav
a:278)
at java.security.AccessController.doPrivileged(Native Method)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV a
l
ve.ja
va:274)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a
:
505)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextV a
l
ve.ja
va:212)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a
:
505)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j a
v
a:203
)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav a
:
505)
at
com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProce s
s
or.ja
va:157)
at com.iplanet.ias.web.WebContainer.service(WebContainer.java:598)
Caused by: java.lang.NullPointerException
at
com.mysite.bean.SoldProperty.getExclusiveSold(SoldProperty.java:573)
Here is the relevant code:
protected SoldProperty[] ExclusiveSold; protected SoldProperty[] BuyerSold;
/** Set the Value of ExclusiveSold to ExclusiveSoldValue @param ExclusiveSoldValue The value of the variable ExclusiveSold in the Object */ public void setExclusiveSold (SoldProperty[] ExclusiveSoldValue) { ExclusiveSold = ExclusiveSoldValue; } /** Get the Value of ExclusiveSold @return The Value of ExclusiveSold */ public SoldProperty[] getExclusiveSold (){ return ExclusiveSold; } /** Set the Value of ExclusiveSold to ExclusiveSoldValue @param ExclusiveSoldValue The value of the variable ExclusiveSold in the Object */ public void setExclusiveSold (int index, SoldProperty ExclusiveSoldValue) { ExclusiveSold[index] = ExclusiveSoldValue; } /** Get the Value of ExclusiveSold @return The Value of ExclusiveSold */ public SoldProperty getExclusiveSold (int index){ return ExclusiveSold[index]; }
/** Set the Value of BuyerSold to BuyerSoldValue @param BuyerSoldValue The value of the variable BuyerSold in the Object */ public void setBuyerSold (SoldProperty[] BuyerSoldValue) { BuyerSold = BuyerSoldValue; } /** Get the Value of BuyerSold @return The Value of BuyerSold */ public SoldProperty[] getBuyerSold (){ return BuyerSold; } /** Set the Value of BuyerSold to BuyerSoldValue @param BuyerSoldValue The value of the variable BuyerSold in the Object */ public void setBuyerSold (int index, SoldProperty BuyerSoldValue) { BuyerSold[index] = BuyerSoldValue; } /** Get the Value of BuyerSold @return The Value of BuyerSold */ public SoldProperty getBuyerSold (int index){ return BuyerSold[index]; }
And the jsp code:
<c:forEach var="exclusive" items="${SoldProperty.exclusiveSold}" varStatus="status"> <tr> <td bgcolor="#E0E8F5" align="center"><c:out value="${exclusive.soldDate}"/></td> <td bgcolor="#E0E8F5"><html-el:hidden property="exclusiveSold[${status.index}].soldId"/><a href="Marketing.app?action=edit&id=<c:out value="${exclusive.mlsNumber}"/>"><c:out value="${exclusive.streetNumber}"/> <c:out value="${exclusive.street}"/> <c:out value="${exclusive.aptNumber}"/></a></td> <td bgcolor="#E0E8F5" align="center"><c:out value="${exclusive.price}"/></td> <td bgcolor="#E0E8F5" align="center"><html-el:checkbox property="exclusiveSold[${status.index}].showListing" /></td> <td bgcolor="#E0E8F5" align="center"><html-el:checkbox property="exclusiveSold[${status.index}].showPrice" /></td> <td bgcolor="#E0E8F5" align="center"><html-el:checkbox property="exclusiveSold[${status.index}].showAptNumber" /></td> <td bgcolor="#E0E8F5" align="center"><html-el:text property="exclusiveSold[${status.index}].displayPrice" size="8" /></td> </tr> </c:forEach>
<c:forEach var="buyer" items="${SoldProperty.buyerSold}"
varStatus="status">
<tr>
<td bgcolor="#E0E8F5" align="center"><c:out
value="${buyer.soldDate}"/></td>
<td bgcolor="#E0E8F5"><html-el:hidden
property="buyerSold[${status.index}].soldId"/><a
href="soldProperty.app?action=edit&id=<c:out
value="${buyer.soldId}"/>"><c:out value="${buyer.streetNumber}"/>
<c:out
value="${buyer.street}"/> <c:out value="${buyer.aptNumber}"/></a></td>
<td bgcolor="#E0E8F5" align="center"><c:out
value="${buyer.price}"/></td>
<td bgcolor="#E0E8F5"
align="center"><html-el:checkbox
property="buyerSold[${status.index}].showListing" /></td>
<td bgcolor="#E0E8F5"
align="center"><html-el:checkbox
property="buyerSold[${status.index}].showPrice" /></td>
<td bgcolor="#E0E8F5"
align="center"><html-el:checkbox
property="buyerSold[${status.index}].showAptNumber" /></td>
<td bgcolor="#E0E8F5" align="center"><html-el:text
property="buyerSold[${status.index}].displayPrice" size="8" /></td>
</tr>
</c:forEach>
Any ideas why I'm getting this error? And how to fix it?
Thanks, Nathan Ewing
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

