• 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

problem getting list in jsp page in struts2

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 213
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your getter should be getAgencyList(), not getagencyList()
 
dhaval tamboli
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic