• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Logic iterate and vo

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
The situation is as follows:
1) Once the user logs on, he is displayed a list of reports along with the status.
2) This list is generated by firing a query to the oracle database.
3) The data returned from the query is stored in a bean called ReportBean
and a ArrayList consisting of a number of ReportBeans is returned.
4) This ArrayList is to be used in the logic iterate tag of struts.
The status is as follows:
1) Have been able to create the ArrayList in the Action class.
2) I also have a getter and setter method for the ArrayList.
3) However when I am using the logic iterate tag, its failing stating
No collection found.
1) How do I get around this problem ? ( Some example will definitely help)
2) Given that a form is also a bean, would it be a cardinal sin to create an
ArrayList of forms ?
Thanks in advance
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the ArrayList?
I've done something similiar with a bean named "Month" that contains an ArrayList of beans called "Orders." The iterate code in the .jsp looks like:
<logic:iterate id="info" name="month" property="orders" >
<bean:write name="info" property="property1" />
<bean:write name="info" property="property2" />
</logic:iterate>
 
Sheriff
Posts: 17648
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Show us the relevant portions of code from your ActionForm and JSP
 
bobby chaurasia
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the code:
In the JSP is as follows :
<logic:iterate id="reportList" name="reportRequestForm" property="reportList">



<TR align="left">
<TD class="table_cell">
<bean:write name="reportList" property="reportID" filter="true"/>
</TD>
<TD>
<bean:write name="reportList" property="reportRequestID" filter="true"/>
</TD>
<TD>
<bean:write name="reportList" property="submitDate" filter="true"/>
</TD>
<TD>
<bean:write name="reportList" property="statusCode" filter="true"/>
</TD>
<TD>
<bean:write name="reportList" property="criteria" filter="true"/>
</TD>
</TR>
</logic:iterate>


</TR>
</TABLE>
The Form class called RequestReportForm reads as follows:

ArrayList reportList = null;
public void setReportRequestID( int reportRequestID ){this.reportRequestID = reportRequestID; }
public void setReportID( String reportID){this.reportID = reportID; }
public void setStatusCode( String statusCode){this.statusCode = statusCode; }
public void setSumbitDate( String sumbitDate){this.sumbitDate = sumbitDate; }
public void setCriteria( String criteria){this.criteria = criteria; }
public void setReport( String report){this.report = report; }


public String getReportRequestID(){ return Integer.toString(reportRequestID); }
public String getReportID(){ return reportID; }
public String getStatusCode(){ return statusCode; }
public String getSumbitDate(){ return sumbitDate; }
public String getCriteria(){ return criteria; }
public String getReport(){ return report; }

public void setReportList( ArrayList reportList){
this.reportList = reportList;
}

public ArrayList getReportList(){
return reportList;
}
The Action reads as follows : It fires a sql query that returns a ArrayList
else if (request.getParameter("submit").equalsIgnoreCase("Refresh ")){
ReportStatusQuery q = new ReportStatusQuery();
ArrayList reportList = q.getReportStatus();
f.setReportList(reportList);
session.setAttribute("reportList",reportList);

}
The DAO code snippet is as follows:
public void handleResultSet( ResultSet r ) throws SQLException {
while( r.next() ) {
//rsb = new ReportStatusBean();
rsb = new ReportRequestForm();
rsb.setReportRequestID( r.getInt( 1 ) );
rsb.setReportID( r.getString(2));
rsb.setStatusCode(r.getString(3));
rsb.setSumbitDate(r.getDate(4).toString());
rsb.setCriteria(r.getString(5));
System.out.println(" Request id : " + rsb.getReportRequestID() );
al.add(rsb);
}
}
The stuts.config entry is
I'm getting the error : Servlet Error]-[No collection found]: javax.servlet.jsp.JspException: No collection found
 
Junilu Lacar
Sheriff
Posts: 17648
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few things in your that don't look right.
session.setAttribute("reportList",reportList);
There is usually no need to do this since you already called the ActionForm's setReportList with the same object. The above statement is redundant and just confuses the picture.
rsb = new ReportRequestForm();
Why are instantiating an ActionForm? You should leave this to the Struts framework. What you would instantiate are beans that you will put into your collection. Each of these beans would represent a set of data that would be displayed per iteration in your JSP. It seems to me that all your getters and setters for report ID, submit date (your spelling is "sumbit", BTW), etc. would go into this bean instead of your ActionForm.
Finally,
<logic:iterate id="reportList" name="reportRequestForm" property="reportList">
While there is nothing technically wrong with this, the name for id is a poor choice, IMO. It should reflect the type of bean that your collection holds. If it is a bean that holds information about a single report, a better choice might be "report" (go figure), as in
<logic:iterate id="report" name="reportRequestForm" property="reportList">
<bean:write name="report" property="id" />
...
</logic:iterate>
This roughly translates to:
Collection col = session.getAttribute("reportRequestForm").getReportList();
for (Iterator i = col.iterator(); i.hasNext(); ) {
Object report = i.next();
out.print(report.getId());
...
}
Note that the code above won't work as is but just tries to convey the essence of the code that the tag will generate.
[ August 28, 2003: Message edited by: Junilu Lacar ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic