aspose file tools*
The moose likes Struts and the fly likes logic :iterator problem can anyone please solve this.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic :iterator problem can anyone please solve this...." Watch "logic :iterator problem can anyone please solve this...." New topic
Author

logic :iterator problem can anyone please solve this....

padma jenifer
Greenhorn

Joined: Jul 24, 2006
Posts: 6
hi to everyone.i am oking in struts i want iterate the details of users by giving search criteria like userid or firstname(first letter) but i am getting error willanyone can help me???
Action class :-

public class WelcomeAction extends Action {
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String param=mapping.getParameter();
if(param.equalsIgnoreCase("searchbutton"))
{
System.out.println("i'm here at welcome action");
WelcomeForm welcomeform=(WelcomeForm)form;
String firstname=null;
firstname=welcomeform.getFirstName();
String userid=null;
userid=welcomeform.getUserID();
System.out.println("firstname in WelcomeAction = "+firstname);
System.out.println("userid in Welcome Action = "+userid);
List memberList=welcomeform.getMem(userid,firstname);
request.setAttribute("memberList",memberList);
if(memberList.size()>0)
{
welcomeform.setCheckValue("yes");


//welform.setForm((Form[])list.toArray(new Form[list.size()]));

for(int i=0;i<memberList.size();i++)
{
Form memForm = (Form)memberList.get(i);
System.out.println(memForm.getFirstName());
System.out.println(memForm.getLastName());
System.out.println(memForm.getUserID());
System.out.println(memForm.getBranchName());
System.out.println(memForm.getCollegeName());
System.out.println(memForm.getEmailID());
}
}

}
return (mapping.findForward("success"));
}
}


formbean:-
public final class WelcomeForm extends ActionForm {

//private WelcomeVO[] welcomeVO={new WelcomeVO()};
//private WelcomeVO welcomeVO=new WelcomeVO();

private String userID=null;
private String firstName=null;
private String checkValue ="No";

//here getter and setters for userId fname &checkvalue...

public List getMem(String userID,String firstName) {
System.out.println("i am in WelcomeForm");
return Form.getMem(userID,firstName);
}
}

bean:-


public class Form implements Serializable{

private String firstName=null;
private String lastName=null;
private String branchName=null;
private String collegeName=null;
private String emailID=null;
private String userID=null;

//hre getters and setters


public static List getMem(String userID,String firstName) {
System.out.println("i am in form bean");
return DBConnect.detailsDAO(userID,firstName);
}
}

DBconnect:-

public static List detailsDAO(String userid,String fname){
DBConnect dc = new DBConnect();

List list=new ArrayList();
Connection conn = null;

try
{

conn=dc.createConnection();


if(userid.equals("null")){
System.out.println("userid is null");
PreparedStatement pstmt=conn.prepareStatement("select * from details where FirstName like '"+fname+"%'");
ResultSet rs = pstmt.executeQuery();
Form form=null;
while(rs.next())
{
form=new Form();
form.setBranchName(rs.getString("Branch"));
System.out.println(form.getBranchName());
form.setCollegeName(rs.getString("College"));
System.out.println(form.getCollegeName());
form.setEmailID(rs.getString("EmailID"));
System.out.println(form.getEmailID());
form.setFirstName(rs.getString("FirstName"));
System.out.println(form.getFirstName());
form.setLastName(rs.getString("LastName"));
System.out.println(form.getLastName());
form.setUserID(rs.getString("UserID"));
System.out.println(form.getUserID());
list.add(form);
}
rs.close();
conn.close();
}
else{
PreparedStatement pstmt=conn.prepareStatement("select * from details where UserID='"+userid+"'");// OR FirstName like '"+fname+"%'");
ResultSet rs = pstmt.executeQuery();
Form form=null;
while(rs.next())
{
form=new Form();
form.setBranchName(rs.getString("Branch"));
System.out.println(form.getBranchName());
form.setCollegeName(rs.getString("College"));
System.out.println(form.getCollegeName());
form.setEmailID(rs.getString("EmailID"));
System.out.println(form.getEmailID());
form.setFirstName(rs.getString("FirstName"));
System.out.println(form.getFirstName());
form.setLastName(rs.getString("LastName"));
System.out.println(form.getLastName());
form.setUserID(rs.getString("UserID"));
System.out.println(form.getUserID());
list.add(form);
}
rs.close();
conn.close();
}
}
catch (Exception e)
{
e.printStackTrace();
}
return list;
}



Struts config:-

<action path="/welcome"
type="com.cognizant.teamprofile.action.WelcomeAction"
name="WelcomeForm"
parameter="searchButton"
input="/welcome.jsp"
scope="session">
<forward name="success" path="/welcome.jsp"/>
</action>



jsp;-

<logic:iterate id="memForm" name="memberList" scope="request">

<tr class="height20" bgcolor="#FFFFFF">
<td align="center" class="tdBorderRightBottom"><input type="radio" name="a133484"></td>
<td align="left" class="tdBorderRightBottom"><bean:write name="memForm" property="userID"/></td>

<td align="left" class="tdBorderRightBottom"><bean:write name="memForm" property="firstName"/></td>
<td align="left" class="tdBorderRightBottom"><bean:write name="memForm" property="lastName"/></td>
<td align="left" class="tdBorderRightBottom"><bean:write name="memForm" property="branch"/></td>
<td align="left" class="tdBorderRightBottom"><bean:write name="memForm" property="collegeName"/></td>
<td align="left" class="tdBorderRightBottom"><bean:write name="memForm" property="emailID"/></td>
</tr>

</logic:iterate>




gives error:-



javax.servlet.jsp.JspException: Cannot find bean memberList in scope request
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:493)
at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:302)
at org.apache.jsp.welcome_jsp._jspService(welcome_jsp.java:271)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:703)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1759)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
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:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:72)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:275)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)
Alana Sparx
Ranch Hand

Joined: Feb 14, 2006
Posts: 121
Hi Padma

I think you need to re-read the Struts documentation as there are a number of errors here, but I'll see what I can do to help.

Firstly, the error message


Is prompted by this line in your jsp:



From what I can make out, memberList is a locally declared list inside your WelcomeAction class. This is not going to work. You need to declare the list you want to access inside the ActionForm, not the Action Class and populate that list within the bounds of your ActionClass.

So
Create the list and the getters/setters inside your WelcomeForm
Populate this list from the Action Class
Access the list via the appropriate form and proprty inside the iterate block of your jsp.
Return if you have further issues!

As!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: logic :iterator problem can anyone please solve this....