You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Caroline Jen <ji...@yahoo.com> on 2006/06/22 02:03:04 UTC

Why My JSTL Tag Cannot Do What Struts Tag Does?

I am able to display a List of object returned from
the database using the Struts tags:
[code]
.....
<%@ page import=".....common.pojo.user.User" %>
....
....
<% 
        List user =
(List)request.getAttribute("Users");
        pageContext.setAttribute("Users", user);
%>
.....
.....
<logic:iterate id="users" name="Users" type=".....
commom.pojo.user.User" scope="request">
        <tr>
              <td><bean:write name="users"
property="createdByUserID"/></td>
             <td><bean:write name="users"
property="firstName"/></td>
             <td><bean:write name="users"
property="lastName"/></td>
        </tr>
</logic:iterate>
......
[/code]

But, when I use JSTL tags to do the same thing, I
cannot display my data.  I mean, I do "not" get any
JSP error.  I can see each row in a table, but it is
complete blank in every single column for every single
row.  I "did" import the JSTL tag library.  And the
JSTL tag library exists and works in other JSPs. 
Please help me to see what went wrong.  Here is my
JSTL code (I am typing my code and there may be typos.
 Anyway, no error is given in the browser.):

[code]
.....
<%@ taglib uri="/tags/core" prefix="c" %>
<%@ page import=".....common.pojo.user.User" %>
....
...
<c:set var="userRows" value="${requestScope.Users}" />
.....
     <c:forEach var="User" items="${userRows } "
varStatus="idx">
     <% User user = (User)pageContext.getAttribute(
"user" ); %>
     <c:choose>
           <c:when test="${( idx.count+1)%2 ==0}">
                 <tr class="contentCell1">
           </c:when>
           <c:otherwise>
                 <tr class="contentCell2">
           </c:otherwise>
     </c:choose>
                        <td><c:out
value="${user.createdByUserID} "  /></td>
                        <td><c:out
value="${user.firstName} "  /></td>
                        <td><c:out
value="${user.lastName} "  /></td>
                  </tr>
     </c:forEach>
......
[/code]

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Pop up menu ??

Posted by Kavita Mehta <ka...@hsc.com>.
Hi,
My requirement for a piece of code is that onmouseover on a piece of 
text in a table column , a pop up menu (the ones which disappear as soon 
as u take the mouse away) should be displayed which can be clicked to 
fwd to other action classes.
Does anybody have any idea if struts supports this ?? I know , that this 
can be done using DHTML but we are not using it ...

Thanks,
Kavita


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


Re: Why My JSTL Tag Cannot Do What Struts Tag Does?

Posted by Ed Griebel <ed...@gmail.com>.
You don't need to do the intermediate assignment to user, it should be
sufficient to do:
-----------
     <c:forEach var="User" items="${userRows } "
varStatus="idx">
    <c:choose>
          <c:when test="${( idx.count+1)%2 ==0}">
                <tr class="contentCell1">
          </c:when>
          <c:otherwise>
                <tr class="contentCell2">
          </c:otherwise>
    </c:choose>
                       <td><c:out value="${User.createdByUserID} "  /></td>
                       <td><c:out value="${User.firstName} "  /></td>
                       <td><c:out value="${User.lastName} "  /></td>
                 </tr>
    </c:forEach>
-------------------
Also, the convention is to keep var names lowercase, as in <c:forEach
var="user"...

-ed


On 6/21/06, Caroline Jen <ji...@yahoo.com> wrote:
> I am able to display a List of object returned from
> the database using the Struts tags:
> [code]
> .....
> <%@ page import=".....common.pojo.user.User" %>
> ....
> ....
> <%
>         List user =
> (List)request.getAttribute("Users");
>         pageContext.setAttribute("Users", user);
> %>
> .....
> .....
> <logic:iterate id="users" name="Users" type=".....
> commom.pojo.user.User" scope="request">
>         <tr>
>               <td><bean:write name="users"
> property="createdByUserID"/></td>
>              <td><bean:write name="users"
> property="firstName"/></td>
>              <td><bean:write name="users"
> property="lastName"/></td>
>         </tr>
> </logic:iterate>
> ......
> [/code]
>
> But, when I use JSTL tags to do the same thing, I
> cannot display my data.  I mean, I do "not" get any
> JSP error.  I can see each row in a table, but it is
> complete blank in every single column for every single
> row.  I "did" import the JSTL tag library.  And the
> JSTL tag library exists and works in other JSPs.
> Please help me to see what went wrong.  Here is my
> JSTL code (I am typing my code and there may be typos.
>  Anyway, no error is given in the browser.):
>
> [code]
> .....
> <%@ taglib uri="/tags/core" prefix="c" %>
> <%@ page import=".....common.pojo.user.User" %>
> ....
> ...
> <c:set var="userRows" value="${requestScope.Users}" />
> .....
>      <c:forEach var="User" items="${userRows } "
> varStatus="idx">
>      <% User user = (User)pageContext.getAttribute(
> "user" ); %>
>      <c:choose>
>            <c:when test="${( idx.count+1)%2 ==0}">
>                  <tr class="contentCell1">
>            </c:when>
>            <c:otherwise>
>                  <tr class="contentCell2">
>            </c:otherwise>
>      </c:choose>
>                         <td><c:out
> value="${user.createdByUserID} "  /></td>
>                         <td><c:out
> value="${user.firstName} "  /></td>
>                         <td><c:out
> value="${user.lastName} "  /></td>
>                   </tr>
>      </c:forEach>
> ......
> [/code]
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Re: Why My JSTL Tag Cannot Do What Struts Tag Does?

Posted by Scott Van Wart <sc...@indosoft.ca>.
> <c:set var="userRows" value="${requestScope.Users}" />
> .....
>      <c:forEach var="User" items="${userRows } "
> varStatus="idx">
>      <% User user = (User)pageContext.getAttribute(
> "user" ); %>
>   

I don't use this method at all (I prefer jsp:useBean), but maybe the 
"user" in getAttribute() should be capitalized as "User"?

- Scott

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