File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Logic:iterate + Indexed property issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Logic:iterate + Indexed property issue" Watch "Logic:iterate + Indexed property issue" New topic
Author

Logic:iterate + Indexed property issue

Mike Mack
Greenhorn

Joined: Apr 09, 2006
Posts: 3
Hi All,

I have an issue with <logic:iterate> tag when iteration over a List object.

Here is what i have.

##############################
Action Form:
public class ABCForm extends ActionForm{

public List priceBeanList;

public List getPriceBeanList() {
return priceBeanList;
}

public void setPriceBeanList(List priceBeanList1) {
this.priceBeanList = priceBeanList;
}

}
##############################
JSP:
<logic:iterate id="priceBeanList1" name="createAddonUIForm" property="priceBeanList1" type="rezadmin.bean.PackagePriceBean" indexId="i1">
<td>
<table>
<tr>
<td height="10" valign="top"> <bean:write name="priceBeanList1" property="day1"/></td></tr>
<tr>
<td height="10" valign="top"> <bean:write name="priceBeanList1" property="date1" /></td></tr>
<tr>
<td height="10" valign="top"> <bean:write name="priceBeanList1" property="adultRate" /></td></tr>
<tr>
<td height="10" valign="top"> <bean:write name="priceBeanList1" property="childRate" /></td></tr>
<tr>
<td height="20" valign="top"> 
<html:select name="priceBeanList1" property="numberOfAdults" indexed="true" >
<html ption value="">-</html ption>
<html ption value="1">1</html ption>
<html ption value="2">2</html ption>
<html ption value="3">3</html ption>
</html:select></td></tr>
<tr>
<td height="20" valign="top"> 
<html:select name="priceBeanList1" property="numberOfChildren" indexed="true">
<html ption value="">-</html ption>
<html ption value="1">1</html ption>
<html ption value="2">2</html ption>
<html ption value="3">3</html ption>
</html:select></td></tr>
</table>
</td>
</logic:iterate>

##############################
When i try to save the page i get this exception:

10:26:53,258 ERROR [[action]] Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:515)
at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
at org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
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(RequestProcessor.java:821)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java: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:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:534)



Thanks in advance.

Regards,

Mike M.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
First of all, the code you're showing us would throw an exception even while displaying the page. In order for the code to work, you would have to specify property="priceBeanList" in your <logic:iterate> tag.

In order to make this work, I'd recommend doing the following:

1. Indexed properties only work if you have an indexed getter and setter on your ActionForm Bean. Add two new indexed methods to your ABCForm class:
public PackagePriceBean getPriceBean(int index)
and
public void setPriceBean(int index, PackagePriceBean)

2. When you use indexed="true" in <html:xxx> tags, the "id" property of the <logic:iterate> tag has to match the name of your indexed getter, so change your <logic:iterate> tag to:
<logic:iterate id="priceBean" name="createAddonUIForm" property="priceBeanList" >

3. When you use indexed="true" in <html:xxx> tags, the "name" property of the tag must match the name of your indexed getter, so change your <html:select> tags to:
<html:select name="priceBean" property="numberOfAdults" indexed="true" >
and
<html:select name="priceBean" property="numberOfChildren" indexed="true" >

4. You must either put the ActionForm in session scope or provide "lazy initialization" for your indexed properties. This link explains how to do lazy initialization with indexed properties.


Merrill
Consultant, Sima Solutions
Mike Mack
Greenhorn

Joined: Apr 09, 2006
Posts: 3
Thank Merrill,

I works like mgic. I understoon the concepts behind the fix to my show stopper.

Thanks once again for the guidance.

Regards,

Mike, Mack.
 
GeeCON Prague 2014
 
subject: Logic:iterate + Indexed property issue