You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Jouravlev <jm...@gmail.com> on 2005/11/14 19:43:35 UTC
Re: Newbie help with Struts idiom: functional if/else tags
Use either Struts <logic:equal> or JSTL <c:if> or bare scriptlet. In
your particular case you can make the decision in the bean itself. Do
not print HTML tags from Java, this produces unmaintable and
unportable code.
Michael.
On 11/14/05, Mark S Petrovic <ma...@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?
>
> Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Newbie help with Struts idiom: functional if/else tags
Posted by Mark S Petrovic <ma...@petrovic.org>.
Thank you for the reply.
Using, for example, <logic:equal> seems to solve only half the problem.
Using <logic:equal>, I can see my way clear to
<logic:equal name="feature" property="premium" value="true">
<td>True</a>
</logic:equal>
<logic:notEqual name="feature" property="premium" value="true">
<td>True</a>
</logic:notEqual>
which gives a crude if/else effect, but this is almost surely ill advised.
I think the same would apply to <c:if>, as I know of no "else" construct
that goes with either.
One could also perhaps use
<c:choose>
<c:when>
...
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
which looks a bit better.
Thanks.
Mark
On 14Nov, Michael Jouravlev wrote:
> Use either Struts <logic:equal> or JSTL <c:if> or bare scriptlet. In
> your particular case you can make the decision in the bean itself. Do
> not print HTML tags from Java, this produces unmaintable and
> unportable code.
>
> Michael.
>
> On 11/14/05, Mark S Petrovic <ma...@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?
> >
> > 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
Re: Newbie help with Struts idiom: functional if/else tags
Posted by Larry Meadors <lm...@apache.org>.
I like this:
<c:choose>
<c:when test="${bean.property}">true</c:when>
</c:choose>
Larry
On 11/14/05, Michael Jouravlev <jm...@gmail.com> wrote:
> Use either Struts <logic:equal> or JSTL <c:if> or bare scriptlet. In
> your particular case you can make the decision in the bean itself. Do
> not print HTML tags from Java, this produces unmaintable and
> unportable code.
>
> Michael.
>
> On 11/14/05, Mark S Petrovic <ma...@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?
> >
> > Thank you.
>
> ---------------------------------------------------------------------
> 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