• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Logic:iterate + Indexed property issue

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mike Mack
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic