You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by "Glenn R. Kronschnabl" <gr...@netquotient.com> on 2002/04/10 21:26:41 UTC

rtexprvalues in c:if test

A lot of the jstl examples you see are like:

<c:if test="${customer.credit > 100}">

what I would like to do is to remove the hardcoded '100'.
Ideally, I could have something close to:

<%@ page import="my.com.Constants" %>

<c:if test="${customer.credit > Constants.BIG_SPENDER}">

of course the above does not work.  What's the best way to do what I
want?  Should I use the c-rt?  I know the following works.

<c_rt:if test="<%= customer.getCredit() > Constants.BIG_SPENDER %>"

But I'm under the mindset to avoid the -rt versions - is that a
misconception?

TIA,
Glenn




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: rtexprvalues in c:if test

Posted by Shawn Bayern <ba...@essentially.net>.
Since the JSTL expression language is designed to expose JavaBean
properties, it's probably best to represent "constants" as such
properties.  E.g.,

  public class Constants {
    private final int BIG_SPENDER = 100;

    public int getBigSpender() { return BIG_SPENDER; }
  }

will let you use an expression like

  ${customer.credit > constants.bigSpender}

The JSTL expression language doesn't support static member fields in part
beacuse they might clash with JavaBean properties.

Shawn

On 10 Apr 2002, Glenn R. Kronschnabl wrote:

> A lot of the jstl examples you see are like:
> 
> <c:if test="${customer.credit > 100}">
> 
> what I would like to do is to remove the hardcoded '100'.
> Ideally, I could have something close to:
> 
> <%@ page import="my.com.Constants" %>
> 
> <c:if test="${customer.credit > Constants.BIG_SPENDER}">
> 
> of course the above does not work.  What's the best way to do what I
> want?  Should I use the c-rt?  I know the following works.
> 
> <c_rt:if test="<%= customer.getCredit() > Constants.BIG_SPENDER %>"
> 
> But I'm under the mindset to avoid the -rt versions - is that a
> misconception?
> 
> TIA,
> Glenn
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>