• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts iterate tag

 
li xiaohua
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,All
I set the 'loginForm' Object which contains the array of 'userForm' objects (userList) in request
when i want to use the Struts iterator tag to loop the list and print out property 'name',
i am getting following error.
<Error> <HTTP> <101017> <[ServletContext(id=5981 name=DefaultWebApp,context-path=)]
Root cause of ServletException
javax.servlet.jsp.JspException: Cannot find bean userForm in scope null
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:493)

Here is the code:
<logic:iterate id="loginForm" name="loginForm" scope="request" property="userList">
<tr >
<td>
<bean:write name="userForm" property="name" />
</td>

</tr>
</logic:iterate>
Can you explain me what went wrong?
Is it required for all of the'userForm' to be set in request/session too?
Any comments will be highly appreciated
thanks
 
Art choz
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I think that your error is in the "name" property of the write tag, it must be the name of the "id" tag of the iterate.
gool luck.
bye
 
li xiaohua
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
problem fixed
thanks ,you are right
 
Tim Eyre
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have exactly the same problem, but my bean:write name attribute is pointing to my logic:iterate id attribute:
<logic:iterate id="rep" name="user" property="reports">
<tr>
<td align="left">
<bean:write name="rep" property="name" filter="true"/> </td>
<td align="left">
<bean:write name="rep" property="description" filter="true"/> </td>
</tr>
</logic:iterate>
My report bean is defined as follows:
public class Report {
String name = "REPBEAN";
String description = "Empty report bean";
Report(String name, String description) {
this.name = name;
this.description = description;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return this.description;
}
public String toString() {
return "Report: " + name + ", Description: " + description;
}
}
And my User bean is:
public class User implements Serializable {
private String username = null;
private Report[] reports = null;
User (String username) {
this.username = username;
}
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
public void setReports(Report[] reports) {
this.reports = reports;
}
public Report[] getReports() {
return this.reports;
}
}
And they get populated by the following code:
User u = new User("timmy");
Report r1 = new Report("this", "works");
Report r2 = new Report("this", "works too");
Report reps[] = new Report[2];
reps[0] = r1;
reps[1] = r2;
u.setReports(reps);
HttpSession session = request.getSession();
session.setAttribute("user", u);
Any ideas? I've tried every combination of the scope attribute, but I still get:
"Cannot find bean rep in scope ???"
Thanks for any help you can give.
Tim
[ November 26, 2002: Message edited by: Tim Eyre ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic