You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by kiuma <ki...@usa.net> on 2002/09/16 13:52:48 UTC

[STRUTS] help with tag lib

Can someone explain how to use the tag form of the following code?

<%
   
    if ( (request.getSession().getAttribute("user.list") != null) )
    {
        UserData uData = new UserData( 
0,"name1","name2","cf","piva","address",
            "zip","city","state","country","tel","mail","web" );
        Collection cUsers = 
(Collection)request.getSession().getAttribute("user.list");
        Iterator iter;
        String style;
        boolean  pink=false;
        iter = cUsers.iterator();
        String rowparity = "";
%>


I use the following but it's a wrong solution

<c:forEach items="${user.list}" var="userData">
    <B>NOME</B>
    <b><c:out value="${userData.name1}"/></b><br/>
</c:forEach>

Can You help me please ?


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [STRUTS] help with tag lib

Posted by Patrick Refondini <pa...@jpnet.ch>.
kiuma wrote:
> Can someone explain how to use the tag form of the following code?
> 
> <%
>      if ( (request.getSession().getAttribute("user.list") != null) )
>    {
>        UserData uData = new UserData( 
> 0,"name1","name2","cf","piva","address",
>            "zip","city","state","country","tel","mail","web" );
>        Collection cUsers = 
> (Collection)request.getSession().getAttribute("user.list");
>        Iterator iter;
>        String style;
>        boolean  pink=false;
>        iter = cUsers.iterator();
>        String rowparity = "";
> %>
> 
> 
> I use the following but it's a wrong solution
> 
> <c:forEach items="${user.list}" var="userData">
>    <B>NOME</B>
>    <b><c:out value="${userData.name1}"/></b><br/>
> </c:forEach>
> 
> Can You help me please ?
> 
> 
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
> 
> 

Just a few ideas as far as I understand what you are trying to do:

<table>
<thead>
   <tr>
         <th>name1</th>
         <th>name2</th>
   </tr>
<thead>
<tbody>
  <logic:present name="user.list" scope="session">
     <logic:iterate id="currentUser" name="user.list">
       <tr>
         <td><bean:write name="currentUser" property="name1" /></td>
         <td><bean:write name="currentUser" property="name2" /></td>
       </tr>
     </logic:iterate>
  </logic:present>
</tbody>
</table>

You need to declare the following taglibs:

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

Also something like :

         <th><bean:message key="user.name1.display"/></th>
         <th><bean:message key="user.name2.display"/></th>

would be better than hardcoding the headers.


Patrick


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [STRUTS] help with tag lib

Posted by Eddie Bush <ek...@swbell.net>.
I'm not 100% sure what your problem is.  I'm guessing that you think the 
JSTL isn't finding your bean.  Based off that assumption, I'd get rid of 
your scriplet (very very bad!) and do the following:

<c:forEach items="${sessionScope['user.list']}" var="userData">
    <B>NOME</B>
    <b><c:out value="${userData.name1}"/></b><br/>
</c:forEach>

I'm not sure you can reference "user.list" though, so you might wind up 
having to do something along the lines of:

<c:forEach items="${sessionScope['user'].list}" var="userData">
...
</c:forEach>

or

<c:set var="theUser" value="sessionScope['user']"/>

<c:forEach items="${theUser.list}" var="userData">
...
</c:forEach>

I haven't played with things like you're doing yet (though I will later 
on today), so I could be wrong ... but I think I'm pretty close.

Regards,

Eddie

kiuma wrote:

> Can someone explain how to use the tag form of the following code?
>
> <%
>      if ( (request.getSession().getAttribute("user.list") != null) )
>    {
>        UserData uData = new UserData( 
> 0,"name1","name2","cf","piva","address",
>            "zip","city","state","country","tel","mail","web" );
>        Collection cUsers = 
> (Collection)request.getSession().getAttribute("user.list");
>        Iterator iter;
>        String style;
>        boolean  pink=false;
>        iter = cUsers.iterator();
>        String rowparity = "";
> %>
>
>
> I use the following but it's a wrong solution
>
> <c:forEach items="${user.list}" var="userData">
>    <B>NOME</B>
>    <b><c:out value="${userData.name1}"/></b><br/>
> </c:forEach>
>
> Can You help me please ?
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>