You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Moons Manuel <Ma...@sydney-tristar.com> on 2001/07/09 14:43:02 UTC

iterate problem

Hello everyone.

I am currently having some problems with iterating over an array of objects.

In my action class I have put an array into the session object
(request.getSession().setAttribute("orderedsandwiches",...);)

I would like to loop over these objects in my jsp page.

I am trying to do this like this:

<bean:define id="orderedsandwiches" name="orderedsandwiches"/>

<table>
<logic:iterate id="element" name="orderedsandwiches">
	<tr>
	<td>
	<bean:write name="element" property="name"/>
	</td>
	</tr>
</logic:iterate>
</table>


But when I try to do this, I get an exception like the following:

<9-jul-01 14:21:07 GMT+02:00> <Error> <HTTP>
<[WebAppServletContext(5325170,sandwich)] Root cause of ServletException
javax.servlet.jsp.JspException: Cannot find bean element in scope null
        at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:493)
        at
org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:179)
        at jsp_servlet._viewall._jspService(_viewall.java:183)
        at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
        at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:213)
        at
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImp
l.java:157)
        at
org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.ja
va:1683)
        at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1520)
        at
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:485)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:213)
        at
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
ntext.java:12
65)
        at
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
:1622)
        at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
        at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
>


When I loop through the array using jsp snippets, I can print out the
contents of the array like this:


<table>
<%
  OrderBean []ob = (OrderBean[])orderedsandwiches;
  for(int i=0;i<ob.length;i++) {
	%><tr><td><%
	out.println(ob[i]);
	%><td><tr><%
  }
%>
</table>

The strange thing about all of this is that in another jsp page, I do almost
the same thing and there this works without any problems.

Does anyone have an idea to solve this problem????


Re: iterate problem

Posted by suhas <su...@techmas.hcltech.com>.
if u putting the orderedsandwiches in the session scope in action class ,
then no Need of having <bean:define> tag in the JSP .

Also instead of keeping that in the session scope in the action class. U can
very well populate the form bean with the contents of that array &
use following in JSP page . Here listOfSandwithces is the array attribute of
the actionForm bean which

 <logic:iterate id="element"     name="orderedsandwiches"
property="listOfSandwitches"  >
       <bean:write name="element"    property="element"  >
        <logic:iterate>



----- Original Message -----
From: Moons Manuel <Ma...@sydney-tristar.com>
To: <st...@jakarta.apache.org>
Sent: Monday, July 09, 2001 1:43 PM
Subject: iterate problem


> Hello everyone.
>
> I am currently having some problems with iterating over an array of
objects.
>
> In my action class I have put an array into the session object
> (request.getSession().setAttribute("orderedsandwiches",...);)
>
> I would like to loop over these objects in my jsp page.
>
> I am trying to do this like this:
>
> <bean:define id="orderedsandwiches" name="orderedsandwiches"/>
>
> <table>
> <logic:iterate id="element" name="orderedsandwiches">
> <tr>
> <td>
> <bean:write name="element" property="name"/>
> </td>
> </tr>
> </logic:iterate>
> </table>
>
>
> But when I try to do this, I get an exception like the following:
>
> <9-jul-01 14:21:07 GMT+02:00> <Error> <HTTP>
> <[WebAppServletContext(5325170,sandwich)] Root cause of ServletException
> javax.servlet.jsp.JspException: Cannot find bean element in scope null
>         at
org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:493)
>         at
> org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:179)
>         at jsp_servlet._viewall._jspService(_viewall.java:183)
>         at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
>         at
>
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
> :213)
>         at
>
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImp
> l.java:157)
>         at
>
org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.ja
> va:1683)
>         at
> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1520)
>         at
> org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:485)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
>
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
> :213)
>         at
>
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
> ntext.java:12
> 65)
>         at
>
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
> :1622)
>         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
>         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
> >
>
>
> When I loop through the array using jsp snippets, I can print out the
> contents of the array like this:
>
>
> <table>
> <%
>   OrderBean []ob = (OrderBean[])orderedsandwiches;
>   for(int i=0;i<ob.length;i++) {
> %><tr><td><%
> out.println(ob[i]);
> %><td><tr><%
>   }
> %>
> </table>
>
> The strange thing about all of this is that in another jsp page, I do
almost
> the same thing and there this works without any problems.
>
> Does anyone have an idea to solve this problem????


RE: iterate problem

Posted by Niall Pemberton <ni...@btInternet.com>.
Have you defined the struts-logic.tld at the top of your jsp?

> -----Original Message-----
> From: Moons Manuel [mailto:Manuel.Moons@sydney-tristar.com]
> Sent: 09 July 2001 13:43
> To: 'struts-user@jakarta.apache.org'
> Subject: iterate problem
> 
> 
> Hello everyone.
> 
> I am currently having some problems with iterating over an array 
> of objects.
> 
> In my action class I have put an array into the session object
> (request.getSession().setAttribute("orderedsandwiches",...);)
> 
> I would like to loop over these objects in my jsp page.
> 
> I am trying to do this like this:
> 
> <bean:define id="orderedsandwiches" name="orderedsandwiches"/>
> 
> <table>
> <logic:iterate id="element" name="orderedsandwiches">
> 	<tr>
> 	<td>
> 	<bean:write name="element" property="name"/>
> 	</td>
> 	</tr>
> </logic:iterate>
> </table>
> 
> 
> But when I try to do this, I get an exception like the following:
> 
> <9-jul-01 14:21:07 GMT+02:00> <Error> <HTTP>
> <[WebAppServletContext(5325170,sandwich)] Root cause of ServletException
> javax.servlet.jsp.JspException: Cannot find bean element in scope null
>         at 
> org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:493)
>         at
> org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:179)
>         at jsp_servlet._viewall._jspService(_viewall.java:183)
>         at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
>         at
> weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStu
> bImpl.java
> :213)
>         at
> weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDis
> patcherImp
> l.java:157)
>         at
> org.apache.struts.action.ActionServlet.processActionForward(Action
> Servlet.ja
> va:1683)
>         at
> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1520)
>         at
> org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:485)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStu
> bImpl.java
> :213)
>         at
> weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAp
> pServletCo
> ntext.java:12
> 65)
>         at
> weblogic.servlet.internal.ServletRequestImpl.execute(ServletReques
> tImpl.java
> :1622)
>         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:137)
>         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
> >
> 
> 
> When I loop through the array using jsp snippets, I can print out the
> contents of the array like this:
> 
> 
> <table>
> <%
>   OrderBean []ob = (OrderBean[])orderedsandwiches;
>   for(int i=0;i<ob.length;i++) {
> 	%><tr><td><%
> 	out.println(ob[i]);
> 	%><td><tr><%
>   }
> %>
> </table>
> 
> The strange thing about all of this is that in another jsp page, 
> I do almost
> the same thing and there this works without any problems.
> 
> Does anyone have an idea to solve this problem????
>