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 05:02:23 GMT
I'm still stumbling on some details.  

For

<logic:iterate id="feature" name="features">
   <tr>
      <td>
         <c:choose>
            <c:when test="${feature.premium == true}">
               <c:out value="true"/>
            </c:when>
            <c:otherwise>
               <c:out value="false"/>
            </c:otherwise>
         </c:choose>
      </td>
   </tr>
</logic:iterate>

fwiw, "features" is put in the request scope using 

            request.setAttribute("features", features);

in the Action that provides data to this JSP view.

The JSP prints false for cases where I know feature.isPremium() is true.
I suspect the 'feature' scripting variable has different meanings in the
two ways in which it is being used (logic:iterate tag and c:choose tag)

Help is appreciated, and I'm on my way to get modern books on both Struts
and JSPs.

On 14Nov, Craig McClanahan wrote:
> On 11/14/05, Mark S Petrovic <mark@petrovic.org> wrote:
> >
> > Good day. I am new to Struts, and while I am coming up to speed, I'm
> > still struggling with what are surely common idioms.
> >
> > In a JSP, I want to output, say, a <td> element body conditionally based
> > on a given bean property.
> >
> > In pseudocode, I want
> >
> > if bean.property == true
> > print <td> X </td>
> > else
> > print <td> Y </td>
> >
> > I examined the Struts Logic tags, but found no if/else construct, and
> > I suspect there is a good reason for this.
> >
> > Does Struts culture encourage me to somehow move the solution into the
> > bean itself, or is there a informed, stylish way to deal with this in
> > the JSP?
> 
> 
> You can easily simulate if/else (or even if - else if - else if) chains with
> the JSTL <c:choose> tag, with nested <c:when> or <c:otherwise> tags.
It's
> similar in spirit to using the "switch" statement in Java or C.
> 
> Craig
> 
> 
> Thank you.
> >
> > ---------------------------------------------------------------------
> > 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