JSP EL: How to access static class values?

Discussion in 'Java' started by javaguy@sbcglobal.net, Feb 18, 2005.

  1. Guest

    I'm writing some JSP pages. I'd like to access some static text:

    class myClass {
    public static final String PARENT = "PAR";
    public static final String CHILD = "CHD";

    public static String getChild() { return CHILD; }

    ...
    }

    <jsp:useBean id="mine" class="myClass"/>
    <c:set var="child" value="${mine.CHILD}"/>
    Parent is: <c:eek:ut value="${myClass.PARENT}"/>
    Child is: <c:eek:ut value="${child}"/>
    Child also is: <c:eek:ut value="${mine.child}"/>


    Note that none of this works. The "mine.CHILD" attempt and "myfails
    with a warning that

    An error occurred while evaluating custom action attribute "value" with
    value "${mine.CHILD}": Unable to find a value for "CHILD" in object of
    class "myClass" using operator "." (null)

    (Tomcat 5.5.4, JDK 1.4.2)


    The "mine.child" attempt (calling mine.getChild()) fails silently.
    Apparently it returns null and EL converts it to an empty string. Same
    thing for "myClass.PARENT".

    I know I can get there by using <%= myClass.PARENT %>, but can it be
    done through EL alone?

    Thanks,

    Jerome.
     
    , Feb 18, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SaravanaKumar
    Replies:
    6
    Views:
    9,526
    Tony Morris
    Oct 19, 2004
  2. Replies:
    1
    Views:
    588
    Andrea Desole
    Dec 14, 2005
  3. Replies:
    0
    Views:
    4,598
  4. bugbear
    Replies:
    4
    Views:
    469
    bugbear
    Aug 23, 2006
  5. Robin
    Replies:
    0
    Views:
    439
    Robin
    Jun 6, 2007
Loading...

Share This Page