struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark S Petrovic <m...@petrovic.org>
Subject Re: Newbie help with Struts idiom: functional if/else tags
Date Tue, 15 Nov 2005 13:57:54 GMT
Thank you for the reply.

1.  I want to say yes, Feature is a proper JavaBean, with essentials

public class Feature {
  private boolean premium;
  public void setPremium(boolean b) { premium = b; }
  public boolean isPremium()        { return premium; }
}

and no overloaded methods.

"features" is populated thusly

ArrayList features = new ArrayList();
Feature f = new Feature();
f.setPremium(true); // e.g.
features.add(f);

and finally, in the Action.execute() method of the associated Struts
action

            request.setAttribute("features", features);
            return (mapping.findForward(target));

where the request.setAttribute() is the share-with-JSP-view technique
used by the Struts book I'm reading.

2.  Failing to get the <c:choose> to work within <logic:iterate> in
#1 above, I also tried a different tack:  using <c:forEach> instead of
<logic:iterate> to cycle through the list elements that <logic:iterate>
formerly treated:

For the same ArrayList "features", containing instances of bean "Feature"
as above and set with the same Struts Action.execute via

            request.setAttribute("features", features);

I attempt

<c:forEach var="feature" items="${requestScope.features}">
   <tr>
      <td>
         <c:choose>
            <c:when test="${feature.premium == true}">
               True
            </c:when>
            <c:otherwise>
               False
            </c:otherwise>
         </c:choose>
      </td>
      <td>
         <c:out value="${feature.premium}"/>
      </td>
   </tr>
</c:forEach>

which isn't even iterating over the list items.  E.g, I get one line of
html output for the <c:out value="${feature.premium}"/> tag, containing
the string literal '${feature.premium}' in quotes - as if expansion of
${feature.premium} is not taking place.

I know the issues I'm raising are very elementary, but I hope they help
someone else in the process.

Mark

On 14Nov, Wendy Smoak wrote:
> On 11/14/05, Mark S Petrovic <mark@petrovic.org> wrote:
> 
> >    <c:when test="${feature.premium == true}">
> 
> Should just be  <c:when test="${feature.premium}">
> 
> Is 'feature' a proper JavaBean?  The types for get(is)/set methods
> match, no overloaded set methods, etc?
> 
> --
> Wendy
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

-- 
Mark Petrovic
Pasadena, CA  USA

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


Mime
View raw message