Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Struts - A MVC web framework
Tomcat - JSP/Servlet container
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
JSP - A mailing list about Java Server Pages specification and reference
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
Const in JSTL

Const in JSTL

2004-02-13       - By Karthik Arun

 Back
Reply:     1     2     3     4  

hi Mark,

I tried the 2nd way that you had suggested here are the details (I am not
sure I did everything alright) but it isnt working, it throws
"Method get() not implemented" error.

I have a class MyConstBean implementing Map with the following method.

 public Map get(String constName) throws Exception{
   HashMap map = new HashMap();
   Class constClass = Class.forName(constName);
   java.lang.reflect.Field[] flds = constClass.getDeclaredFields();
   for(int i = 0; i<flds.length; i++){
     map.put(flds[i].getName(), flds[i].get(null));
   }
   return map;
 }

Now in the jsp, I have the following lined, just to alert the constant
value.

       <%request.setAttribute("constantsBean", new
com.somePackage.MyConstBean());%>
       alert('<c:out
value="${constantsBean.SomeConstantsInterface.SOME_CONST}" />');

this is not working ......

The first option requires a lot of changes in some other's module, so not
thinking about it now.
I do not understand the last option. Can you give me an example for the
function & its call....

Regards,
Arun Karthik R

-- --Original Message-- --
From: Mark Roth [mailto:Mark.Roth@(protected)]
Sent: Thursday, February 12, 2004 9:29 PM
To: JSP-INTEREST@(protected)
Subject: Re: Const in JSTL


Hi Arun,

There is no direct way to access constants in the EL.  Here are a few
alternatives:

1. Create a Map in the application scope and put all the constants in
there.  (e.g. ${myConstantsMap.SOME_CONST})

2. Create a bean that implements java.util.Map Source code of java.util.Map and have it look up
constants (e.g. ${constantsBean.MyConstants.SOME_CONST} would call
constantsBean.get( "MyConstants" ).  This would return a Map containing
key/value pairs for the costants in MyConstants).  This is not hard to
write and could be done using introspection.

3. Create a function that looks up the constants (e.g. ${fn:constants(
"MyConstants.SOME_CONST" )} ).  Again, The function would use introspection.

We're looking into making this easier in a future version of the JSP
specification.

Hope this helps.

---
Mark Roth, Java Software
JSP 2.0 Co-Specification Lead
Sun Microsystems, Inc.


Karthik Arun wrote:
> hi All
>
> How can I use a Const (final static) member of a class MyConstants in
JSTL??
> I would like to do something like this:
>
> <c:if test="${state == MyConstants.SOME_CONST}" >
>   <c:set value="${stateCode + '<br><b>' + singleObjToProcess.stateStr +
> '</b><br>'}" var="stateCode" />
> </c:if>
>
> where SOME_CONST is a const in MyConstants class.state is a loop iterating
> variable, stateCode is some member variable of singleObjToProcess object
> that is in the page scope.
>
> Can somebody let me know how I can use the constant in the JSTL..????
>
> Regards,
> Arun Karthik R
>
>
>
>
===========================================================================
> To unsubscribe: mailto listserv@(protected) with body: "signoff
JSP-INTEREST".
> For digest: mailto listserv@(protected) with body: "set JSP-INTEREST
DIGEST".
>
> Some relevant archives, FAQs and Forums on JSPs can be found at:
>
>  http://java.sun.com/products/jsp
>  http://archives.java.sun.com/jsp-interest.html
>  http://forums.java.sun.com
>  http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto listserv@(protected) with body: "signoff
JSP-INTEREST".
For digest: mailto listserv@(protected) with body: "set JSP-INTEREST
DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com

===========================================================================
To unsubscribe: mailto listserv@(protected) with body: "signoff JSP-INTEREST".
For digest: mailto listserv@(protected) with body: "set JSP-INTEREST DIGEST".

Some relevant archives, FAQs and Forums on JSPs can be found at:

http://java.sun.com/products/jsp
http://archives.java.sun.com/jsp-interest.html
http://forums.java.sun.com
http://www.jspinsider.com



©2008 junlu.com - Jax Systems, LLC, U.S.A.