Meaningless Drivel is fun!*
The moose likes Struts and the fly likes problem in logic:iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem in logic:iterate" Watch "problem in logic:iterate" New topic
Author

problem in logic:iterate

viji narasimhan
Greenhorn

Joined: Oct 23, 2008
Posts: 10
hi,

i am using structs 1.2.9 . i want to display a list of datas retrieved from database in jsp.

My action class looks like this

public class RegistrationAction extends org.apache.struts.action.Action {

/* forward name="success" path="" */
private final static String SUCCESS = "success";

/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

RegistrationForm regform = (RegistrationForm) form;
String paytype = regform.getPayType();
System.out.println(paytype);

HttpSession htsession = request.getSession() ;
registrationDAO regdao = new registrationDAO();
System.out.println(regdao);
List sponsorlists = regdao.getSponsorList();
System.out.println(sponsorlists);
regform.setSponsorList(sponsorlists);
//htsession.setAttribute("sponsorlists",sponsorlists);
//request.setAttribute("sponsorlists",sponsorlists);


return mapping.findForward(SUCCESS);
}
}


where registrationDAO contains a method called getSponsorList



public class registrationDAO {

List<RegistrationWrapper> sponsorList = new ArrayList();
Connection connection = null;
ConnectionDB con = new ConnectionDB();

public List getSponsorList() throws SQLException {

connection = con.getConnectionToDatabase();
String sql = "select * from patientsponsor";
Statement s = connection.createStatement();
s.executeQuery(sql);
ResultSet rs = s.getResultSet();
while (rs.next()) {
RegistrationWrapper regw = new RegistrationWrapper();
regw.setHms_spons_sponsId(rs.getInt("hms_spons_sponsId"));
regw.setHms_spons_cmpyNmae(rs.getString("hms_spons_cmpyName"));
regw.setHms_spons_cntPerson(rs.getString("hms_spons_cntperson"));
regw.setHms_spons_addr(rs.getString("hms_spons_addr"));
regw.setHms_spons_city(rs.getString("hms_spons_city"));
regw.setHms_spons_state(rs.getString("hms_spons_state"));
regw.setHms_spons_ctry(rs.getString("hms_spons_ctry"));
regw.setHms_spons_zip(rs.getString("hms_spons_zip"));
regw.setHms_spons_pNo(rs.getString("hms_spons_pNo"));
regw.setHms_spons_email(rs.getString("hms_spons_email"));
sponsorList.add(regw);
}
return sponsorList;
}
}


then i am having one list, in which i store the datas from sponsortable by using getSponsorList().



then i am creating a list in registrationform and settiing this list value in it.

public class RegistrationForm extends org.apache.struts.action.ActionForm {

private Integer regId;
private String regDate;
private String apptTime;
private String refDoctor;
private String consultDoctor;
private String ptname;
private String dob;
private String age;
private String fsName;
private String disease;
private String department;
private String ptType;
private String occupation;
private String fee;
private String addr1;
private String addr2;
private String city;
private String state;
private String ctry;
private Integer zipCode;
private Integer phoneNo;
private Integer mobileNo;
private Integer faxNo;
private String email;
private String grdName;
private String grdAddr;
private Integer grdCntNo;
private String relation;
private String gender = "Male";
private String payType = "Self";
private String maritalStatus;
private List sponsorList;
private Integer sponsorId;
private String sponsorcmpNmae;
private String cntPerson;
private Integer pNo;
private String emailId;
/**
* @return
*/

/**
*
*/
public RegistrationForm() {
super();
// TODO Auto-generated constructor stub
}

/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param request The HTTP Request we are processing.
* @return
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (getPtname() == null || getPtname().length() < 1) {
errors.add("name", new ActionMessage("error.name.required"));
// TODO: add 'error.name.required' key to your resources
}
return errors;
}

public String getDepartment() {
return department;
}

public void setDepartment(String department) {
this.department = department;
}



public String getAddr1() {
return addr1;
}

public void setAddr1(String addr1) {
this.addr1 = addr1;
}

public String getAddr2() {
return addr2;
}

public void setAddr2(String addr2) {
this.addr2 = addr2;
}

public String getAge() {
return age;
}

public void setAge(String age) {
this.age = age;
}

public String getApptTime() {
return apptTime;
}

public void setApptTime(String apptTime) {
this.apptTime = apptTime;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getConsultDoctor() {
return consultDoctor;
}

public void setConsultDoctor(String consultDoctor) {
this.consultDoctor = consultDoctor;
}

public String getCtry() {
return ctry;
}

public void setCtry(String ctry) {
this.ctry = ctry;
}

public String getDisease() {
return disease;
}

public void setDisease(String disease) {
this.disease = disease;
}

public String getDob() {
return dob;
}

public void setDob(String dob) {
this.dob = dob;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public Integer getFaxNo() {
return faxNo;
}

public void setFaxNo(Integer faxNo) {
this.faxNo = faxNo;
}

public String getFee() {
return fee;
}

public void setFee(String fee) {
this.fee = fee;
}

public String getFsName() {
return fsName;
}

public void setFsName(String fsName) {
this.fsName = fsName;
}

public String getGrdAddr() {
return grdAddr;
}

public void setGrdAddr(String grdAddr) {
this.grdAddr = grdAddr;
}

public Integer getGrdCntNo() {
return grdCntNo;
}

public void setGrdCntNo(Integer grdCntNo) {
this.grdCntNo = grdCntNo;
}

public String getGrdName() {
return grdName;
}

public void setGrdName(String grdName) {
this.grdName = grdName;
}

public Integer getMobileNo() {
return mobileNo;
}

public void setMobileNo(Integer mobileNo) {
this.mobileNo = mobileNo;
}

public String getOccupation() {
return occupation;
}

public void setOccupation(String occupation) {
this.occupation = occupation;
}

public Integer getPhoneNo() {
return phoneNo;
}

public void setPhoneNo(Integer phoneNo) {
this.phoneNo = phoneNo;
}

public String getPtType() {
return ptType;
}

public void setPtType(String ptType) {
this.ptType = ptType;
}

public String getPtname() {
return ptname;
}

public void setPtname(String ptname) {
this.ptname = ptname;
}

public String getRefDoctor() {
return refDoctor;
}

public void setRefDoctor(String refDoctor) {
this.refDoctor = refDoctor;
}

public String getRegDate() {
return regDate;
}

public void setRegDate(String regDate) {
this.regDate = regDate;
}

public Integer getRegId() {
return regId;
}

public void setRegId(Integer regId) {
this.regId = regId;
}

public String getRelation() {
return relation;
}

public void setRelation(String relation) {
this.relation = relation;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public Integer getZipCode() {
return zipCode;
}

public void setZipCode(Integer zipCode) {
this.zipCode = zipCode;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public String getPayType() {
return payType;
}

public void setPayType(String payType) {
this.payType = payType;
}

public String getMaritalStatus() {
return maritalStatus;
}

public void setMaritalStatus(String maritalStatus) {
this.maritalStatus = maritalStatus;
}

public List getSponsorList() {
return sponsorList;
}

public void setSponsorList(List sponsorList) {
this.sponsorList = sponsorList;
}

public String getCntPerson() {
return cntPerson;
}

public void setCntPerson(String cntPerson) {
this.cntPerson = cntPerson;
}

public String getEmailId() {
return emailId;
}

public void setEmailId(String emailId) {
this.emailId = emailId;
}

public Integer getPNo() {
return pNo;
}

public void setPNo(Integer pNo) {
this.pNo = pNo;
}

public Integer getSponsorId() {
return sponsorId;
}

public void setSponsorId(Integer sponsorId) {
this.sponsorId = sponsorId;
}

public String getSponsorcmpNmae() {
return sponsorcmpNmae;
}

public void setSponsorcmpNmae(String sponsorcmpNmae) {
this.sponsorcmpNmae = sponsorcmpNmae;
}


}

then i am trying to display this list in jsp using logic:iterate

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SponsorsList</title>
</head>
<body>
<center>Sponcer List Information</center>



<table Border="0" >
<tr>
<td >
<html:link styleClass="links" href="addSponsorship.jsp" target="contentframe">Add New Sponcer</html:link>
</td>
</tr>
</table>

<table border="1" >
<tr >
<th >Sl No.</th>
<th >Sponcer ID</th>
<th >Sponcer Name</th>
<th >Contact Person</th>
<th >Phone Number</th>
<th >Email Id</th>
</tr>
<logic:iterate id="sponslist" scope="session" name="RegistrationForm" property="sponsorList">
<tr>
<td>
<bean:write name="RegistrationForm" property="sponsorId"/>
</td>
<td>
<bean:write name="RegistrationForm" property="sponsorcmpNmae"/>
</td>
<td>
<bean:write name="RegistrationForm" property="cntPerson"/>
</td>
<td>
<bean:write name="RegistrationForm" property="pNo"/>
</td>
<td>
<bean:write name="RegistrationForm" property="emailId"/>
</td>
</tr>
</logic:iterate>


<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>
<tr><td >

 

</td></tr>
</table>

</body>
</html>

but i am getting error like this

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


root cause

javax.servlet.ServletException: java.lang.InstantiationException: bean RegistrationForm not found within scope
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.Reception.patientsponsor_jsp._jspService(patientsponsor_jsp.java:192)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


root cause

java.lang.InstantiationException: bean RegistrationForm not found within scope
org.apache.jsp.Reception.patientsponsor_jsp._jspService(patientsponsor_jsp.java:75)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.



please help me out . i have tried with session and request scope.



thanks in advance.

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi viji. http://faq.javaranch.com/java/UseCodeTags.

Coming to your question check your form-bean elements in struts-config.xml [whether you declare its fully qualified name(with package)] . and dont get panic while debugging.

by the way ,CarefullyChooseOneForum
Vallidevi Appana
Greenhorn

Joined: Jun 30, 2006
Posts: 25
Hi Viji,

Try the following piece of code. It will work only if "registrationForm" is in session scope.
The name attribute value, that you are referrring in logic:iterate tag should match with form-bean name.
I feel "RegistrionForm" is the class name.
you can get the form-bean name from struts-config.xml file.
You should see following kind of line in your struts-config.xml file.

<form-bean name="registrationForm" type="com.XXXX.XXXX.XXXX.RegistrationForm"/>

Now use the name attribute value(from form-bean definition) as logic:iterate name attribute value.

<logic:iterate id="sponsor" scope="session" name="registrationForm" property="sponsorList">
<tr>
<td>
<bean:write name="sponsor" property="sponsorId"/>
</td>
<td>
<bean:write name="sponsor" property="sponsorcmpNmae"/>
</td>
<td>
<bean:write name="sponsor" property="cntPerson"/>
</td>
<td>
<bean:write name="sponsor" property="pNo"/>
</td>
<td>
<bean:write name="sponsor" property="emailId"/>
</td>
</tr>
</logic:iterate>

Hope this works for you?

Regards
Valli
viji narasimhan
Greenhorn

Joined: Oct 23, 2008
Posts: 10
hey thanks a lot


in action class i should set the resultlist in session right or how i should do?
viji narasimhan
Greenhorn

Joined: Oct 23, 2008
Posts: 10
hey i tried but it is throwing no collection found exception .




i am using List . whether it supports or we have to use only collection?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in logic:iterate
 
Similar Threads
java.lang.IllegalStateException: Cannot forward after response has been committed
Getting the name of the requesting page
Cannot get new screen to work properly; similar screen was recently added successfully
iterate problem in struts2
Get the modified value from ArrayList of HashMap.