aspose file tools*
The moose likes Struts and the fly likes Struts to iterate stored session object 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 "Struts to iterate stored session object" Watch "Struts to iterate stored session object" New topic
Author

Struts to iterate stored session object

smitha rai
Ranch Hand

Joined: Aug 15, 2001
Posts: 33
Hi,

I am trying to iterate the object stored in session using struts nested tag. I am getting an exception javax.servlet.jsp.JspException: Cannot find bean: "" in any scope. What am I missing in the following code. I do not want to have the Action class and action form bean. I have a need to access the session object and display the results. Here is my code and appreciate if some one helps me out.

Regards,

Smitha

JSP

<%@ taglib uri='/tags/struts-bean' prefix='bean' %>
<%@ taglib uri='/tags/struts-html' prefix='html' %>
<%@ taglib uri='/tags/struts-logic' prefix='logic' %>
<%@ taglib uri='/tags/struts-nested' prefix='nested' %>

<%
List<SubjectInfo> data = DataUtil.getData();
request.getSession().setAttribute("subjectInfo", data);
%>

<html>
<head>
<title>TabMenu Demo home</title>
</head>
<body>
<nested:iterate property="subjectInfo">
Subject: <nested:write property="name"/>

<nested:iterate property="topicInfo" >
Topic: <nested:write property="name"/>

Data: <nested:write property="data"/>
</nested:iterate>
</nested:iterate>
</body>
</html>

Helper Classes

public class SubjectInfo {
private String name;
private List<TopicInfo> topicInfo;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<TopicInfo> getTopicInfo() {
return topicInfo;
}
public void setTopicInfo(List<TopicInfo> topicInfo) {
this.topicInfo = topicInfo;
}
}

public class TopicInfo {

private String name;
private String data;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}

public class DataUtil {

public List<SubjectInfo> getTestData() {
List<SubjectInfo> subjects = new ArrayList<SubjectInfo>();

//First Subject
SubjectInfo subject = new SubjectInfo();
subject.setName("Maths");
List<TipocInfo> topics = new ArrayList<TopicInfo>();
TopicInfo topic = new TopicInfo();
topic.setName("Addition");
topic.setData("Data for addition");
topics.add(topic);
//Second topic
topic = new TopicInfo();
topic.setName("Subtraction");
topic.setData("Data for subtraction");
topics.add(topic);
subject.setTopicInfo(topics);
subjects.add(subject);

//Second Subject
subject = new SubjectInfo();
subject.setName("English");
topics = new ArrayList<TopicInfo>();
topic = new TopicInfo();
topic.setName("Adjectives");
topic.setData("Data for adjectives");
topics.add(topic);
subject.setTopicInfo(topics);
subjects.add(subject);

return subjects;
}
Sriram Ture
Greenhorn

Joined: Aug 20, 2010
Posts: 23
HI,



You need to specify scope="session" in your nested iterate tag.




Thanks,
Sriram
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts to iterate stored session object