• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts to iterate stored session object

 
smitha rai
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,



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




Thanks,
Sriram
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic