Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP EL: How to access static class values?

Reply
Thread Tools

JSP EL: How to access static class values?

 
 
javaguy@sbcglobal.net
Guest
Posts: n/a
 
      02-18-2005
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: <cut value="${myClass.PARENT}"/>
Child is: <cut value="${child}"/>
Child also is: <cut 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why inner class can not have static data, static fields or nested class? Robin Java 0 06-06-2007 11:16 AM
referring to static fields of enclosing class from static inner class? bugbear Java 4 08-23-2006 08:26 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
(jsp) class loader not finding generated JSP class unixfreak0037@gmail.com Java 1 12-14-2005 09:35 AM
Instantiating a static class( Class with all static members - methods and variables) SaravanaKumar Java 6 10-19-2004 08:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57