You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Allen <da...@gmail.com> on 2004/09/29 21:42:30 UTC

inline conditional expression with JSTL EL

Does anyone know if there are plans for (or if an existing library is
floating around) that allows inline conditional expressions in the
POSIX style?  An example would look something like the following:

<c:out value="${user.registered ? 'registered' : 'guest'}"/>

I realize it is possible to use c:choose tags for such a condition,
but often times a simple either/or turns out to be much more verbose
than its resulting effect on the page.

Dan

-- 
Open Source Advocacy
http://www.mojavelinux.com

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


Re: inline conditional expression with JSTL EL

Posted by Jeff Beal <jb...@webmedx.com>.
Dan Allen wrote:
> Does anyone know if there are plans for (or if an existing library is
> floating around) that allows inline conditional expressions in the
> POSIX style?  An example would look something like the following:
> 
> <c:out value="${user.registered ? 'registered' : 'guest'}"/>
> 
> I realize it is possible to use c:choose tags for such a condition,
> but often times a simple either/or turns out to be much more verbose
> than its resulting effect on the page.
> 
> Dan
> 
Have you tried that?  I just checked the JSP EL specification, and 
that's permitted.

-- Jeff


RE: inline conditional expression with JSTL EL

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Dan,

Just don't forget to turn JSP 2.0 on for all JSP's
OR
on for selective JSP's using the in-page call:

<%@ page isELIgnored="false" %>

It definitely works for me on a per-jsp basic in Tomcat 5.0.28 when I tested
it this week under Eclipse v3.X. :)

Good luck,
David

-----Original Message-----
From: Dan Allen [mailto:dan.j.allen@gmail.com]
Sent: Wednesday, September 29, 2004 4:15 PM
To: Struts Users Mailing List
Subject: Re: inline conditional expression with JSTL EL


YES!!!  The missing link to JSTL has been added!  I'm excited...now I
guess I just need to migrate to JSP 2.0.

Dan

On Wed, 29 Sep 2004 15:59:30 -0400, David G. Friedman
<hu...@ix.netcom.com> wrote:
> Dan,
>
> If you are using a JSP 2.0 container, here is a snippet from a post I made
> in the last few days on how to use the "? :" conditional statement:
>
> JBoss v4.0 says it (like Tomcat 5.X.X) supports JSP 2.0.  So you can use
the
> standard Struts release and simply type in the ${expression} syntax from
JSP
> v2.0 directly into a struts tag or anywhere in the JSP page itself.  Do
> ${abc.xyz} to call the getXyz method of object abc.  Scopes should be
> searched automatically in order as mentioned in previous posts today (or
> yesterday) on JSP 2.0.  For IF statements, you can do ${ true ? "right" :
> "wrong" } where this prints out the word "right" while it could be a
method
> call to retrieve data to display instead of the string "right" or the
string
> "wrong".
>
> Again, "right" and "wrong" can be objects and methods (thing.piece.etc.)
> instead of double quoted text words.
>
> Or you can try using c:if + c:else OR the c:choose + c:when + c:otherwise
> combo as shown here:
>
http://archives.java.sun.com/cgi-bin/wa?A2=ind0209&L=jsp-interest&F=&S=&P=39
> 142
>
> For 2.0 ref docs, see section "ChoiceExpression" in gray on the left:
> http://java.sun.com/products/jsp/syntax/2.0/card20.pdf
>
> Regards,
> David
>
>
>
> -----Original Message-----
> From: Dan Allen [mailto:dan.j.allen@gmail.com]
> Sent: Wednesday, September 29, 2004 3:43 PM
> To: Struts Users Mailing List
> Subject: inline conditional expression with JSTL EL
>
> Does anyone know if there are plans for (or if an existing library is
> floating around) that allows inline conditional expressions in the
> POSIX style?  An example would look something like the following:
>
> <c:out value="${user.registered ? 'registered' : 'guest'}"/>
>
> I realize it is possible to use c:choose tags for such a condition,
> but often times a simple either/or turns out to be much more verbose
> than its resulting effect on the page.
>
> Dan
>
> --
> Open Source Advocacy
> http://www.mojavelinux.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



--
Open Source Advocacy
http://www.mojavelinux.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: inline conditional expression with JSTL EL

Posted by Dan Allen <da...@gmail.com>.
YES!!!  The missing link to JSTL has been added!  I'm excited...now I
guess I just need to migrate to JSP 2.0.

Dan

On Wed, 29 Sep 2004 15:59:30 -0400, David G. Friedman
<hu...@ix.netcom.com> wrote:
> Dan,
> 
> If you are using a JSP 2.0 container, here is a snippet from a post I made
> in the last few days on how to use the "? :" conditional statement:
> 
> JBoss v4.0 says it (like Tomcat 5.X.X) supports JSP 2.0.  So you can use the
> standard Struts release and simply type in the ${expression} syntax from JSP
> v2.0 directly into a struts tag or anywhere in the JSP page itself.  Do
> ${abc.xyz} to call the getXyz method of object abc.  Scopes should be
> searched automatically in order as mentioned in previous posts today (or
> yesterday) on JSP 2.0.  For IF statements, you can do ${ true ? "right" :
> "wrong" } where this prints out the word "right" while it could be a method
> call to retrieve data to display instead of the string "right" or the string
> "wrong".
> 
> Again, "right" and "wrong" can be objects and methods (thing.piece.etc.)
> instead of double quoted text words.
> 
> Or you can try using c:if + c:else OR the c:choose + c:when + c:otherwise
> combo as shown here:
> http://archives.java.sun.com/cgi-bin/wa?A2=ind0209&L=jsp-interest&F=&S=&P=39
> 142
> 
> For 2.0 ref docs, see section "ChoiceExpression" in gray on the left:
> http://java.sun.com/products/jsp/syntax/2.0/card20.pdf
> 
> Regards,
> David
> 
> 
> 
> -----Original Message-----
> From: Dan Allen [mailto:dan.j.allen@gmail.com]
> Sent: Wednesday, September 29, 2004 3:43 PM
> To: Struts Users Mailing List
> Subject: inline conditional expression with JSTL EL
> 
> Does anyone know if there are plans for (or if an existing library is
> floating around) that allows inline conditional expressions in the
> POSIX style?  An example would look something like the following:
> 
> <c:out value="${user.registered ? 'registered' : 'guest'}"/>
> 
> I realize it is possible to use c:choose tags for such a condition,
> but often times a simple either/or turns out to be much more verbose
> than its resulting effect on the page.
> 
> Dan
> 
> --
> Open Source Advocacy
> http://www.mojavelinux.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 



-- 
Open Source Advocacy
http://www.mojavelinux.com

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


RE: inline conditional expression with JSTL EL

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Dan,

If you are using a JSP 2.0 container, here is a snippet from a post I made
in the last few days on how to use the "? :" conditional statement:

JBoss v4.0 says it (like Tomcat 5.X.X) supports JSP 2.0.  So you can use the
standard Struts release and simply type in the ${expression} syntax from JSP
v2.0 directly into a struts tag or anywhere in the JSP page itself.  Do
${abc.xyz} to call the getXyz method of object abc.  Scopes should be
searched automatically in order as mentioned in previous posts today (or
yesterday) on JSP 2.0.  For IF statements, you can do ${ true ? "right" :
"wrong" } where this prints out the word "right" while it could be a method
call to retrieve data to display instead of the string "right" or the string
"wrong".

Again, "right" and "wrong" can be objects and methods (thing.piece.etc.)
instead of double quoted text words.

Or you can try using c:if + c:else OR the c:choose + c:when + c:otherwise
combo as shown here:
http://archives.java.sun.com/cgi-bin/wa?A2=ind0209&L=jsp-interest&F=&S=&P=39
142

For 2.0 ref docs, see section "ChoiceExpression" in gray on the left:
http://java.sun.com/products/jsp/syntax/2.0/card20.pdf

Regards,
David

-----Original Message-----
From: Dan Allen [mailto:dan.j.allen@gmail.com]
Sent: Wednesday, September 29, 2004 3:43 PM
To: Struts Users Mailing List
Subject: inline conditional expression with JSTL EL


Does anyone know if there are plans for (or if an existing library is
floating around) that allows inline conditional expressions in the
POSIX style?  An example would look something like the following:

<c:out value="${user.registered ? 'registered' : 'guest'}"/>

I realize it is possible to use c:choose tags for such a condition,
but often times a simple either/or turns out to be much more verbose
than its resulting effect on the page.

Dan

--
Open Source Advocacy
http://www.mojavelinux.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