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 problem getting list in jsp page in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "problem getting list in jsp page in struts2" Watch "problem getting list in jsp page in struts2" New topic
Author

problem getting list in jsp page in struts2

dhaval tamboli
Greenhorn

Joined: Aug 02, 2010
Posts: 25
Hi, I am new to struts2.
I am trying to fetch data in jsp page but can not see anything.

In my action class, I am fetching user_id and passwd from jsp page then from that I am fetching person's personal information and agency's information in which that person is admin.

my action class is

package com.dhaval.view;

import java.util.Iterator;
import java.util.List;

import com.dhaval.controller.AgencyManager;
import com.dhaval.controller.LoginManager;
import com.dhaval.model.LoginModel;
import com.dhaval.controller.PersonManager;
import com.dhaval.model.PersonModel;
import com.dhaval.model.AgencyModel;

import com.opensymphony.xwork2.ActionSupport;

public class PersonAction extends ActionSupport {

private static final long serialVersionUID = 9149826260758390091L;
private PersonModel person;
private List<PersonModel> personList;
private AgencyModel agency;
private List<AgencyModel> agencyList;
private String Person_Name;
private String Person_Passwd;

private PersonManager linkController;
private LoginManager loginController;
private AgencyManager agencyController;

public PersonAction() {
linkController = new PersonManager();
loginController = new LoginManager();
agencyController = new AgencyManager();
}
public String execute() {

String name = getPerson_Name();
String passwd = getPerson_Passwd();
int ID = loginController.list(name,passwd);
personList = linkController.list(ID);
Iterator iter = personList.iterator();
while (iter.hasNext()) {
person = (PersonModel) iter.next();

System.out.println("Hope: "+person.getPerson_Name());
System.out.println(person.getPerson_Role());
}

agencyList = agencyController.list(ID);
Iterator iter1 = agencyList.iterator();
while (iter1.hasNext()) {
agency = (AgencyModel) iter1.next();
System.out.println(agency.getAgency_ID());
System.out.println("Hope: "+agency.getAgency_Name());
System.out.println("Hope: "+agency.getAgency_Description());
System.out.println("Hope: "+agency.getAgency_Address1());
System.out.println("Hope: "+agency.getAgency_Address2());
System.out.println("Hope: "+agency.getAgency_City());
System.out.println("Hope: "+agency.getAgency_State());

System.out.println(agency.getAgency_Zipcode());
System.out.println("Hope: "+agency.getAgency_Email());
System.out.println("Hope: "+agency.getAgency_Phone());
}
return SUCCESS;
}

private String getPerson_Passwd() {
// TODO Auto-generated method stub
return Person_Passwd;
}
public PersonModel getperson() {
return person;
}
public List<PersonModel> getpersonList() {
return personList;
}
public void setperson(PersonModel person) {
this.person = person;
}
public void setpersonList(List<PersonModel> personList) {
this.personList = personList;
}

public AgencyModel getagency() {
return agency;
}
public List<AgencyModel> getagencyList() {
return agencyList;
}
public void setagency(AgencyModel agency) {
this.agency = agency;
}
public void setagencyList(List<AgencyModel> agencyList) {
this.agencyList = agencyList;
}


public String getPerson_Name() {
return Person_Name;
}

public void setPerson_Name(String Person_Name) {
this.Person_Name = Person_Name;
}

public void setPerson_Passwd(String Person_Passwd) {
this.Person_Passwd = Person_Passwd;
}
}



In this class, I am able to see information through iterator in console. but i dont know, its not coming in jsp page as such I do have get and set methods of list
my jsp page is

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Struts 2 - Login Application | By Dhaval Tamboli</title>
</head>

<body>
<h2>Howdy, <s:property value="Person_Name" />...!you are awesome</h2>



<table>
<tr>your information</tr>
<tr>
<th>ID</th>
<th>Role</th>

</tr>
<s:iterator value="agencyList" status="rowstatus">

<tr>
<td><s:property value="Agency_Name" /></td>
<td><s:property value="Agency_City"/></td>

</tr>
</s:iterator>
</table>

</body>
</html>

here, AgencyList is list of AgencyModel , which has fields of Agency_Name, etc. and there also I put get and set methods.

here's my struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/">

<action name="getLogin" class="com.dhaval.view.LoginAction">
<result name="success">Welcome.jsp</result>
</action>
<action name="getPerson" class="com.dhaval.view.PersonAction">
<result name="success">dhaval.jsp</result>
</action>
</package>
</struts>

in index.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Struts 2 - Login Application | By Dhaval Tamboli</title>
</head>

<body>
<h2>Struts 2 - Login Application</h2>
<s:actionerror />
<s:form action="getPerson" method="post">
<s:textfield name="Person_Name" key="label.username" size="20" />
<s:textfield name="Person_Passwd" key="label.password" size="20" />
<s:submit method="execute" key="label.login" align="center" />
</s:form>
</body>
</html>


Let me know, if I am not clear. I can see value of person_name but not value of that list.

Thanks in advance,
dhaval
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9280
    
  17

Hi dhaval, welcome to javaranch.

Dhaval please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

Your getter should be getAgencyList(), not getagencyList()
dhaval tamboli
Greenhorn

Joined: Aug 02, 2010
Posts: 25
Thanks to both of you but I just figured it out , my problem was with access. I just need to give public access to Agencylist instead of private..now its working fine.
again thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

No, you should change the list getter method to be the proper name, not just expose your internal properties.

Also, your variable naming conventions are quite un-Java-like: there's no *technical* reason to follow Java conventions, but if you want people to be able to read your code most efficiently, it's a good idea to follow the guidelines.
dhaval tamboli
Greenhorn

Joined: Aug 02, 2010
Posts: 25
hey thanks.. You were right.. i should not use public.. with getAgencyList() its working fine.. and next time I will keep in mind regarding coding standards ..

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem getting list in jsp page in struts2
 
Similar Threads
problem in servlet to jsp
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "org.apache.struts
how the values added from two different browsers can be seen in either of the browsers?
MyFaces Data Table didn't work
A issue in Struts1.x