struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Oathout <aa...@codejunkies.org>
Subject Re: How to user logic:iterate
Date Tue, 10 Sep 2002 02:29:09 GMT
Hi Michael,

I'm not sure if you're using 1.1 or 1.0, but if you're using 1.1, why not 
create a DynaActionForm to hold the "users" collection? I currently do the 
same kind of task as you and the logic:iterate tag works great(tested 
with just about every nightly build from 1.1b2 till today). Here is my 
following configuration:

struts-config.xml

my form bean is defined as follows:

<form-bean name="users" 
           type="org.apache.struts.action.DynaActionForm">
    <form-property name="count"     type="java.lang.String" />
    <form-property name="users"     type="java.util.List" />
</form-bean>

My action is defined as follows:
<action path="/showUsers" 
        type="org.ifmc.struts.action.AdminAction" 
        name="users"
        scope="request"
        parameter="method" 
        validate="false">
    <forward name="continue" path="template.users.layout"  />
</action>

The snip of jsp that does the iteration is as follows:
<logic:iterate id="user" indexId="count" name="users" property="users">
    <row:row evenStyleClass="evenrow" oddStyleClass="oddrow">
        <td>
            <%=count.intValue()+1%>.&nbsp;
            <bean:write name="user" property="username" />
        </td>
        <td>
            <bean:write name="user" property="email"/>
        </td>
    </row:row>
</logic:iterate>


As long as every request maps to an Action so no jsp's are exposed without 
being processed through an Action first then all your form beans are populated before 
the jsp get rendered. Why not try this approach instead of putting the 
collection directly in request scope? Since every Action can have an 
ActionForm tied to it if specified, you are guaranteed to have your 
collection as long as you populate it. Just my .02


Aaron



On Mon, 9 Sep 2002, Michael Lee wrote:

> Thanks but this still isnt working!
> Nothing I try works!
> WTF! AAAAAAAAAAA
> Help anyone? This can not be so uncommon as no one here knows how to do
> this?
> 
> **ERROR**
> <Sep 9, 2002 8:48:10 PM EDT> <Error> <HTTP>
> <[WebAppServletContext(4298512,recei
> ptsplus,/receiptsplus)] Root cause of ServletException
> javax.servlet.jsp.JspException: Cannot find bean aUser 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.__advanced_user_search._jspService(__advanced_user_search
> .java:1534)
> 
> 
> Here's one of the many errors.
> Users object contains getUsers() that returns an ArrayList of User value
> objects.
> 
> I've tried many combinations of these lines
>       <logic:iterate collection="<%= users.getUsers() %>" id="aUser"
> name="users" scope="request">
>       <logic:iterate id="aUser" name="users" scope="request">
>       <logic:iterate id="aUser" name="users" property="users"
> scope="request">
> 
> with these combinations of bean writers
>             <td><bean:write name="aUser" property="users.userID"/></td>
>             <td><bean:write name="aUser" property="userID"/></td>
>             <td><bean:write name="aUser" property="users.userID"
> scope="request"/></td>
>             <td><bean:write name="aUser" property="userID"
> scope="request"/></td>
> 
> But if I explicitly go through the object I can iterate through it. It seems
> as though this tag needs better documentation and real world examples.
> This works
>     <% Users users =
> 
> (Users)request.getAttribute("users");
>        if(users != null)
>        {
>            Iterator iterator = users.getUsers().iterator();
>            while(iterator.hasNext())
>            {%><tr><%
>                User user = (User)iterator.next();
>                out.print("<td>"+user.getUserID()+"</td>");
>                out.print("<td>"+user.getUserType()+"</td>");
>                out.print("<td>"+user.getFirstName()+"</td>");
>                out.print("<td>"+user.getMiddleName()+"</td>");
>                out.print("<td>"+user.getLastName()+"</td>");
> 
> 
> out.print("<td>"+user.getAccountDisabled()+"</td>");
>                out.print("<td>"+user.getEmail()+"</td></tr>");
>            }
>     %>
>        <%}%>
> 
> Code is attached.
> Help! I'm doing everything I can see/think of in the docs/examples/etc and
> nothing is working.
> Mike
> 
> 
> ----- Original Message -----
> From: "Todd Pierce" <Todd.Pierce@hubbub.com.au>
> To: "Struts Users Mailing List" <struts-user@jakarta.apache.org>
> Sent: Monday, September 09, 2002 7:41 PM
> Subject: RE: How to user logic:iterate
> 
> 
> > Your arraylist isn't in the page context. Try this:
> >
> >  <%
> >     ArrayList users = (ArrayList) request.getAttribute("users");
> >     pageContext.setAttribute("userList", users);
> >  %>
> >
> >     <logic:iterate name="userList" id="aUser" scope="request">
> >     <tr>
> >       <td><bean:write name="aUser" property="user.userID"/></td>
> > ...
> >
> > or use the collection attribute instead of the name attribute in the
> iterate
> > tag, ike this:
> >
> >  <%
> >     ArrayList users = (ArrayList) request.getAttribute("users");
> >  %>
> >
> >     <logic:iterate collection="<%= users %>" id="aUser" scope="request">
> >     <tr>
> >       <td><bean:write name="aUser" property="user.userID"/></td>
> > ...
> >
> > -----Original Message-----
> > From: Michael Lee [mailto:mleejr@hotmail.com]
> > Sent: Tuesday, 10 September 2002 6:56 AM
> > To: Struts Users Mailing List
> > Subject: How to user logic:iterate
> >
> >
> > Im having a helluva time getting logic:iterate to work..
> > I have a Users object that contains an array list of
> > User objects.
> > you call Users.getUsers() and it returns an arrayList
> > I stick that in the request object in the perform() method using
> > request.setAttribute("users", users.getUsers());
> > In the JSP the code I have is;
> >
> >  <% ArrayList users = (ArrayList) request.getAttribute("users");
> >        if(users != null)
> >        {%>
> >     <logic:iterate name="users" id="aUser" scope="request">
> >     <tr>
> >       <td><bean:write name="aUser" property="user.userID"/></td>
> >       <td><bean:write name="aUser" property="user.userType"/></td>
> >       <td><bean:write name="aUser" property="user.fName"/></td>
> >       <td><bean:write name="aUser" property="user.mName"/></td>
> >       <td><bean:write name="aUser" property="user.lName"/></td>
> >       <td><bean:write name="aUser" property="user.accoundDisabled"/></td>
> >       <td><bean:write name="aUser" property="user.email"/></td>
> >     </tr>
> >     </logic:iterate>
> >         <%}%>
> >
> > The error I'm getting is;
> >
> > <Sep 9, 2002 4:52:00 PM EDT> <Error> <HTTP>
> > <[WebAppServletContext(4398493,recei
> > ptsplus,/receiptsplus)] Root cause of ServletException
> > javax.servlet.jsp.JspException: Cannot find bean aUser 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.__advanced_user_search._jspService(__advanced_user_search
> > .java:1541)
> >         at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
> >         at
> > weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
> > pl.java:265)
> >
> > what am I doing wrong?
> > help!
> > thanks,
> > Mike
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
> >
> 


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message