Re: JSTL Question (EL vs. RT + Struts)

2002-11-21 Thread Kris Schneider
Well, for whatever reason, this seemed kind of entertaining (sad, huh?) so I
fleshed it out a bit and actually gave it a test run. Since both JSTL and Struts
taglibs can deal with a Map (JSTL doesn't have a clue about DynaBeans), that
seemed like a better way to go. So, the reflection can be done by a couple of
different methods:

public static DynaBean getConstantFieldsAsBean(Class cls)
   throws IllegalAccessException,
  InstantiationException,
  InvocationTargetException

public static Map getConstantFieldsAsMap(Class cls)
  throws IllegalAccessException

I added a context-param element to web.xml:

context-param
  param-namecom.dotech.CLASS_NAMES/param-name
 
param-valuejavax.servlet.http.HttpServletResponse,org.apache.struts.Globals/param-value
/context-param

along with a listener element:

listener
  listener-classcom.dotech.ConstantsContextListener/listener-class
/listener

The listener parses class names out of the context init param, invokes the
utility method to create a Map of its constants, and then stores the Map in
application scope using the class name as the key.

For the Struts taglibs, the following kinds of access worked fine:

bean:write name=org.apache.struts.Globals
property=ERROR_KEY/
bean:define id=strutsGlobals
 name=org.apache.struts.Globals \
 scope=application/
bean:write name=strutsGlobals
property=ERROR_KEY//p

For JSTL:

c:out value=${applicationScope['org.apache.struts.Globals'].ERROR_KEY}/
c:out value=${applicationScope['org.apache.struts.Globals']['ERROR_KEY']}/
c:set var=strutsGlobals
   value=${applicationScope['org.apache.struts.Globals']}/
c:out value=${strutsGlobals.ERROR_KEY}/
c:out value=${strutsGlobals['ERROR_KEY']}/

I have no idea if that's of help to anyone, but if you want more details I'd be
happy to follow-up.

Quoting Kris Schneider [EMAIL PROTECTED]:

 Sounds like a job for a beanutils mechanism that does something like 
 (untested):
 
 Class clazz = GLOBALS.class;
 String className = clazz.getName();
 
 Map propMap = new HashMap();
 List dynaProps = new ArrayList();
 Field[] allFields = clazz.getDeclaredFields();
 for (int i = 0, n = allFields.length; i  n; i++) {
Field f = allFields[i];
int mods = f.getModifiers();
if (Modifier.isPublic(mods) 
Modifier.isStatic(mods) 
Modifier.isFinal(mods)) {
  String name = f.getName();
  Class type = f.getType();
  Object value = f.get(null);
  DynaProperty prop = new DynaProperty(name, type);
  dynaProps.add(prop);
  propMap.put(name, value);
}
 }
 
 DynaProperty[] props = new DynaProperty[dynaProps.size()];
 dynaProps.toArray(props);
 
 BasicDynaClass dynaClass = new BasicDynaClass(className, null, props);
 DynaBean dynaBean = dynaClass.newInstance();
 BeanUtils.populate(dynaBean, propMap);
 servletCtx.setAttribute(className, dynaBean);
 
 Which gets you a DynaBean with all the constants exposed as properties. 
 Lots of other twists possible...
 
 Eddie Bush wrote:
  ... but can you even do that?  Can you use class-static methods without 
  an instance of the class?
  
  I've toyed with the idea of adding getters for constants into the 
  Globals class, and then placing an instance of that class into 
  application-scope.  What name should a person use though?  If you use 
  the typical method of doing this you wind up with a chicken and egg 
  scenario in your pages.  Of course, if we feel pretty satisfied that the 
  location of the Globals probably isn't going to change again we could 
  probably just decide that they will always be available under 
  org.apache.struts.GLOBALS and be done with it.  You could then get 
  ahold of the instance easily - and use that instance to reference other 
  objects.
  
  Incidentally, I don't believe there are any getters in the Globals class.
  
  David Graham wrote:
  
  I see, so I have to do constants.getMyKey().  I guess that's easy
 enough.
 
  David 
  
  
 
 -- 
 Kris Schneider mailto:[EMAIL PROTECTED]
 D.O.Tech   http://www.dotech.com/
 
 
 --
 To unsubscribe, e-mail:  
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]
 


-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Hohlen, John
My team is starting a new project with Struts.  In our previous Struts
projects, our JSPs used mostly tags from the Struts tag libraries.  For our
new project, I want my team to start using the JSTL.  For that reason, the
Struts-EL subproject is very appealing because it will force our
developers to learn the JSTL  -- as functionality duplicated in the Struts
libraries (Bean  Logic) are removed when it is available in the JSTL.
Obviously, we'll still be using many of the Struts tags -- especially those
tied to the Struts framework (e.g. all tags in the Struts html library).
However, we're not sure whether to use the Request Time (RT) version or
the Expression Language (EL) version of the JSTL library.  And we have the
same question for the Struts subproject (Struts-EL or Struts-RT)?

Does anyone have any advice here?  Will JSTL compliant application servers
be required to implement a EL and RT version of the JSTL, or will they
only have to implement the EL version?

One other issue:  We want to reference constants declared in our Java files
in our JSP.  These are often the bean or error key constants.  This helps
guard against a String typo in the JSP as any mistyped constant name  will
get caught a JSP compile time -- where a string typo will not be detected
until JSP execution time.  Does anyone how to reference Java variables in
your JSP if you're using the JSTL-EL tags?  Is this even possible?  If not,
what are the alternatives?

Thanks,

JOHN



--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread David Graham
You should use the JSTL EL library because of the expression language's 
power.  These tags replace most of the logic and bean tags from Struts.  On 
my projects I only use the struts html taglib and the rest is handled with 
jstl.  The constants in JSP issue is tricky and I haven't solved it myself.

David






From: Hohlen, John [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts-Help (E-mail) [EMAIL PROTECTED]
Subject: JSTL Question (EL vs. RT + Struts)
Date: Wed, 20 Nov 2002 13:14:43 -0600

My team is starting a new project with Struts.  In our previous Struts
projects, our JSPs used mostly tags from the Struts tag libraries.  For our
new project, I want my team to start using the JSTL.  For that reason, the
Struts-EL subproject is very appealing because it will force our
developers to learn the JSTL  -- as functionality duplicated in the Struts
libraries (Bean  Logic) are removed when it is available in the JSTL.
Obviously, we'll still be using many of the Struts tags -- especially those
tied to the Struts framework (e.g. all tags in the Struts html library).
However, we're not sure whether to use the Request Time (RT) version or
the Expression Language (EL) version of the JSTL library.  And we have 
the
same question for the Struts subproject (Struts-EL or Struts-RT)?

Does anyone have any advice here?  Will JSTL compliant application servers
be required to implement a EL and RT version of the JSTL, or will they
only have to implement the EL version?

One other issue:  We want to reference constants declared in our Java files
in our JSP.  These are often the bean or error key constants.  This helps
guard against a String typo in the JSP as any mistyped constant name  will
get caught a JSP compile time -- where a string typo will not be detected
until JSP execution time.  Does anyone how to reference Java variables in
your JSP if you're using the JSTL-EL tags?  Is this even possible?  If not,
what are the alternatives?

Thanks,

JOHN



--
To unsubscribe, e-mail:   
mailto:[EMAIL PROTECTED]
For additional commands, e-mail: 
mailto:[EMAIL PROTECTED]


_
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]



Re: JSTL Question (EL vs. RT + Struts + nested?? )

2002-11-20 Thread Jeff_Mychasiw

I am curious about how the nested taglib fits into this discussion.
 I have been using the nested tags for just about all my forms and logic
tags.
Do JSTL tags  have the capability as nested tags?

Thanks




David Graham [EMAIL PROTECTED] on 11/20/2002 01:37:27 PM

Please respond to Struts Users Mailing List
   [EMAIL PROTECTED]

To:[EMAIL PROTECTED]
cc:

Subject:Re: JSTL Question (EL vs. RT + Struts)


You should use the JSTL EL library because of the expression language's
power.  These tags replace most of the logic and bean tags from Struts.  On
my projects I only use the struts html taglib and the rest is handled with
jstl.  The constants in JSP issue is tricky and I haven't solved it myself.

David






From: Hohlen, John [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts-Help (E-mail) [EMAIL PROTECTED]
Subject: JSTL Question (EL vs. RT + Struts)
Date: Wed, 20 Nov 2002 13:14:43 -0600

My team is starting a new project with Struts.  In our previous Struts
projects, our JSPs used mostly tags from the Struts tag libraries.  For
our
new project, I want my team to start using the JSTL.  For that reason, the
Struts-EL subproject is very appealing because it will force our
developers to learn the JSTL  -- as functionality duplicated in the Struts
libraries (Bean  Logic) are removed when it is available in the JSTL.
Obviously, we'll still be using many of the Struts tags -- especially
those
tied to the Struts framework (e.g. all tags in the Struts html library).
However, we're not sure whether to use the Request Time (RT) version or
the Expression Language (EL) version of the JSTL library.  And we have
the
same question for the Struts subproject (Struts-EL or Struts-RT)?

Does anyone have any advice here?  Will JSTL compliant application servers
be required to implement a EL and RT version of the JSTL, or will they
only have to implement the EL version?

One other issue:  We want to reference constants declared in our Java
files
in our JSP.  These are often the bean or error key constants.  This helps
guard against a String typo in the JSP as any mistyped constant name  will
get caught a JSP compile time -- where a string typo will not be detected
until JSP execution time.  Does anyone how to reference Java variables in
your JSP if you're using the JSTL-EL tags?  Is this even possible?  If
not,
what are the alternatives?

Thanks,

JOHN



--
To unsubscribe, e-mail:
mailto:[EMAIL PROTECTED]
For additional commands, e-mail:
mailto:[EMAIL PROTECTED]


_
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


--
To unsubscribe, e-mail:   
mailto:[EMAIL PROTECTED]
For additional commands, e-mail: 
mailto:[EMAIL PROTECTED]








--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Kris Schneider
You pretty much need the RT taglibs to get at constants:

c_rt:set var=errorKey
  value=%= org.apache.struts.Globals.ERROR_KEY %/

c:set var=errors value=${requestScope[errorKey]}/

Quoting David Graham [EMAIL PROTECTED]:

 You should use the JSTL EL library because of the expression language's 
 power.  These tags replace most of the logic and bean tags from Struts.  On
 
 my projects I only use the struts html taglib and the rest is handled with 
 jstl.  The constants in JSP issue is tricky and I haven't solved it myself.
 
 David
 
 
 
 
 
 
 From: Hohlen, John [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: Struts-Help (E-mail) [EMAIL PROTECTED]
 Subject: JSTL Question (EL vs. RT + Struts)
 Date: Wed, 20 Nov 2002 13:14:43 -0600
 
 My team is starting a new project with Struts.  In our previous Struts
 projects, our JSPs used mostly tags from the Struts tag libraries.  For
 our
 new project, I want my team to start using the JSTL.  For that reason, the
 Struts-EL subproject is very appealing because it will force our
 developers to learn the JSTL  -- as functionality duplicated in the Struts
 libraries (Bean  Logic) are removed when it is available in the JSTL.
 Obviously, we'll still be using many of the Struts tags -- especially
 those
 tied to the Struts framework (e.g. all tags in the Struts html library).
 However, we're not sure whether to use the Request Time (RT) version or
 the Expression Language (EL) version of the JSTL library.  And we have 
 the
 same question for the Struts subproject (Struts-EL or Struts-RT)?
 
 Does anyone have any advice here?  Will JSTL compliant application servers
 be required to implement a EL and RT version of the JSTL, or will they
 only have to implement the EL version?
 
 One other issue:  We want to reference constants declared in our Java
 files
 in our JSP.  These are often the bean or error key constants.  This helps
 guard against a String typo in the JSP as any mistyped constant name  will
 get caught a JSP compile time -- where a string typo will not be detected
 until JSP execution time.  Does anyone how to reference Java variables in
 your JSP if you're using the JSTL-EL tags?  Is this even possible?  If
 not,
 what are the alternatives?
 
 Thanks,
 
 JOHN
 
 
 
 --
 To unsubscribe, e-mail:   
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail: 
 mailto:[EMAIL PROTECTED]
 
 
 _
 Protect your PC - get McAfee.com VirusScan Online 
 http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
 
 
 --
 To unsubscribe, e-mail:  
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]
 


-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Craig R. McClanahan


On Wed, 20 Nov 2002, Hohlen, John wrote:

 Date: Wed, 20 Nov 2002 13:14:43 -0600
 From: Hohlen, John [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: Struts-Help (E-mail) [EMAIL PROTECTED]
 Subject: JSTL Question (EL vs. RT + Struts)

 My team is starting a new project with Struts.  In our previous Struts
 projects, our JSPs used mostly tags from the Struts tag libraries.  For our
 new project, I want my team to start using the JSTL.  For that reason, the
 Struts-EL subproject is very appealing because it will force our
 developers to learn the JSTL  -- as functionality duplicated in the Struts
 libraries (Bean  Logic) are removed when it is available in the JSTL.
 Obviously, we'll still be using many of the Struts tags -- especially those
 tied to the Struts framework (e.g. all tags in the Struts html library).
 However, we're not sure whether to use the Request Time (RT) version or
 the Expression Language (EL) version of the JSTL library.  And we have the
 same question for the Struts subproject (Struts-EL or Struts-RT)?


The EL version is normally the one you want to use, because that is what
actually enables expression language support.

The RT version has exactly the same tags and attributes, but does not
recognize EL expressions.  It was created for the rare, but possible, case
that someone might have used a tag like this in a JSP page:

  mytags:foo bar=${baz}/

and expected the bar property of the tag to actually receive ${baz}
the way it would have prior to EL support.  (An EL-enabled version of the
tag would look up the baz attribute in page/request/session/application
scope and assign that value to bar.)

 Does anyone have any advice here?  Will JSTL compliant application servers
 be required to implement a EL and RT version of the JSTL, or will they
 only have to implement the EL version?

 One other issue:  We want to reference constants declared in our Java files
 in our JSP.  These are often the bean or error key constants.  This helps
 guard against a String typo in the JSP as any mistyped constant name  will
 get caught a JSP compile time -- where a string typo will not be detected
 until JSP execution time.  Does anyone how to reference Java variables in
 your JSP if you're using the JSTL-EL tags?  Is this even possible?  If not,
 what are the alternatives?


As was pointed out by others, the EL libraries don't recognize runtime
expressions so you can't use %= ... % to get these.  Your alternatives
would be:

* Go to the RT version (but give up EL expressions)

* Store the constants you need under some well known names,
  perhaps in application scope, so that you can use an
  EL expression to get them.

 Thanks,

 JOHN

Craig


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread David Graham
But what is the EL expression to get a constant like Constants.MY_KEY?

David







From: Craig R. McClanahan [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: Re: JSTL Question (EL vs. RT + Struts)
Date: Wed, 20 Nov 2002 13:58:57 -0800 (PST)



On Wed, 20 Nov 2002, Hohlen, John wrote:

 Date: Wed, 20 Nov 2002 13:14:43 -0600
 From: Hohlen, John [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: Struts-Help (E-mail) [EMAIL PROTECTED]
 Subject: JSTL Question (EL vs. RT + Struts)

 My team is starting a new project with Struts.  In our previous Struts
 projects, our JSPs used mostly tags from the Struts tag libraries.  For 
our
 new project, I want my team to start using the JSTL.  For that reason, 
the
 Struts-EL subproject is very appealing because it will force our
 developers to learn the JSTL  -- as functionality duplicated in the 
Struts
 libraries (Bean  Logic) are removed when it is available in the JSTL.
 Obviously, we'll still be using many of the Struts tags -- especially 
those
 tied to the Struts framework (e.g. all tags in the Struts html 
library).
 However, we're not sure whether to use the Request Time (RT) version 
or
 the Expression Language (EL) version of the JSTL library.  And we have 
the
 same question for the Struts subproject (Struts-EL or Struts-RT)?


The EL version is normally the one you want to use, because that is what
actually enables expression language support.

The RT version has exactly the same tags and attributes, but does not
recognize EL expressions.  It was created for the rare, but possible, case
that someone might have used a tag like this in a JSP page:

  mytags:foo bar=${baz}/

and expected the bar property of the tag to actually receive ${baz}
the way it would have prior to EL support.  (An EL-enabled version of the
tag would look up the baz attribute in page/request/session/application
scope and assign that value to bar.)

 Does anyone have any advice here?  Will JSTL compliant application 
servers
 be required to implement a EL and RT version of the JSTL, or will 
they
 only have to implement the EL version?

 One other issue:  We want to reference constants declared in our Java 
files
 in our JSP.  These are often the bean or error key constants.  This 
helps
 guard against a String typo in the JSP as any mistyped constant name  
will
 get caught a JSP compile time -- where a string typo will not be 
detected
 until JSP execution time.  Does anyone how to reference Java variables 
in
 your JSP if you're using the JSTL-EL tags?  Is this even possible?  If 
not,
 what are the alternatives?


As was pointed out by others, the EL libraries don't recognize runtime
expressions so you can't use %= ... % to get these.  Your alternatives
would be:

* Go to the RT version (but give up EL expressions)

* Store the constants you need under some well known names,
  perhaps in application scope, so that you can use an
  EL expression to get them.

 Thanks,

 JOHN

Craig


--
To unsubscribe, e-mail:   
mailto:[EMAIL PROTECTED]
For additional commands, e-mail: 
mailto:[EMAIL PROTECTED]


_
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]



RE: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Karr, David
There is none.  JavaBeans.  JavaBeans.  JavaBeans.

 -Original Message-
 From: David Graham [mailto:[EMAIL PROTECTED]]
 
 But what is the EL expression to get a constant like Constants.MY_KEY?
 
 David
 
 From: Craig R. McClanahan [EMAIL PROTECTED]
 
 On Wed, 20 Nov 2002, Hohlen, John wrote:
 
   Date: Wed, 20 Nov 2002 13:14:43 -0600
   From: Hohlen, John [EMAIL PROTECTED]
   Reply-To: Struts Users Mailing List 
 [EMAIL PROTECTED]
   To: Struts-Help (E-mail) [EMAIL PROTECTED]
   Subject: JSTL Question (EL vs. RT + Struts)
  
   My team is starting a new project with Struts.  In our 
 previous Struts
   projects, our JSPs used mostly tags from the Struts tag 
 libraries.  For 
 our
   new project, I want my team to start using the JSTL.  For 
 that reason, 
 the
   Struts-EL subproject is very appealing because it will force our
   developers to learn the JSTL  -- as functionality 
 duplicated in the 
 Struts
   libraries (Bean  Logic) are removed when it is available 
 in the JSTL.
   Obviously, we'll still be using many of the Struts tags 
 -- especially 
 those
   tied to the Struts framework (e.g. all tags in the Struts html 
 library).
   However, we're not sure whether to use the Request Time 
 (RT) version 
 or
   the Expression Language (EL) version of the JSTL 
 library.  And we have 
 the
   same question for the Struts subproject (Struts-EL or 
 Struts-RT)?
  
 
 The EL version is normally the one you want to use, 
 because that is what
 actually enables expression language support.
 
 The RT version has exactly the same tags and attributes, 
 but does not
 recognize EL expressions.  It was created for the rare, but 
 possible, case
 that someone might have used a tag like this in a JSP page:
 
mytags:foo bar=${baz}/
 
 and expected the bar property of the tag to actually 
 receive ${baz}
 the way it would have prior to EL support.  (An EL-enabled 
 version of the
 tag would look up the baz attribute in 
 page/request/session/application
 scope and assign that value to bar.)
 
   Does anyone have any advice here?  Will JSTL compliant 
 application 
 servers
   be required to implement a EL and RT version of the 
 JSTL, or will 
 they
   only have to implement the EL version?
  
   One other issue:  We want to reference constants declared 
 in our Java 
 files
   in our JSP.  These are often the bean or error key 
 constants.  This 
 helps
   guard against a String typo in the JSP as any mistyped 
 constant name  
 will
   get caught a JSP compile time -- where a string typo will not be 
 detected
   until JSP execution time.  Does anyone how to reference 
 Java variables 
 in
   your JSP if you're using the JSTL-EL tags?  Is this even 
 possible?  If 
 not,
   what are the alternatives?
  
 
 As was pointed out by others, the EL libraries don't 
 recognize runtime
 expressions so you can't use %= ... % to get these.  
 Your alternatives
 would be:
 
 * Go to the RT version (but give up EL expressions)
 
 * Store the constants you need under some well known names,
perhaps in application scope, so that you can use an
EL expression to get them.
 
   Thanks,
  
   JOHN
 
 Craig

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread David Graham
I see, so I have to do constants.getMyKey().  I guess that's easy enough.

David







From: Karr, David [EMAIL PROTECTED]
Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
To: Struts Users Mailing List [EMAIL PROTECTED]
Subject: RE: JSTL Question (EL vs. RT + Struts)
Date: Wed, 20 Nov 2002 14:05:03 -0800

There is none.  JavaBeans.  JavaBeans.  JavaBeans.

 -Original Message-
 From: David Graham [mailto:[EMAIL PROTECTED]]

 But what is the EL expression to get a constant like Constants.MY_KEY?

 David

 From: Craig R. McClanahan [EMAIL PROTECTED]
 
 On Wed, 20 Nov 2002, Hohlen, John wrote:
 
   Date: Wed, 20 Nov 2002 13:14:43 -0600
   From: Hohlen, John [EMAIL PROTECTED]
   Reply-To: Struts Users Mailing List
 [EMAIL PROTECTED]
   To: Struts-Help (E-mail) [EMAIL PROTECTED]
   Subject: JSTL Question (EL vs. RT + Struts)
  
   My team is starting a new project with Struts.  In our
 previous Struts
   projects, our JSPs used mostly tags from the Struts tag
 libraries.  For
 our
   new project, I want my team to start using the JSTL.  For
 that reason,
 the
   Struts-EL subproject is very appealing because it will force our
   developers to learn the JSTL  -- as functionality
 duplicated in the
 Struts
   libraries (Bean  Logic) are removed when it is available
 in the JSTL.
   Obviously, we'll still be using many of the Struts tags
 -- especially
 those
   tied to the Struts framework (e.g. all tags in the Struts html
 library).
   However, we're not sure whether to use the Request Time
 (RT) version
 or
   the Expression Language (EL) version of the JSTL
 library.  And we have
 the
   same question for the Struts subproject (Struts-EL or
 Struts-RT)?
  
 
 The EL version is normally the one you want to use,
 because that is what
 actually enables expression language support.
 
 The RT version has exactly the same tags and attributes,
 but does not
 recognize EL expressions.  It was created for the rare, but
 possible, case
 that someone might have used a tag like this in a JSP page:
 
mytags:foo bar=${baz}/
 
 and expected the bar property of the tag to actually
 receive ${baz}
 the way it would have prior to EL support.  (An EL-enabled
 version of the
 tag would look up the baz attribute in
 page/request/session/application
 scope and assign that value to bar.)
 
   Does anyone have any advice here?  Will JSTL compliant
 application
 servers
   be required to implement a EL and RT version of the
 JSTL, or will
 they
   only have to implement the EL version?
  
   One other issue:  We want to reference constants declared
 in our Java
 files
   in our JSP.  These are often the bean or error key
 constants.  This
 helps
   guard against a String typo in the JSP as any mistyped
 constant name
 will
   get caught a JSP compile time -- where a string typo will not be
 detected
   until JSP execution time.  Does anyone how to reference
 Java variables
 in
   your JSP if you're using the JSTL-EL tags?  Is this even
 possible?  If
 not,
   what are the alternatives?
  
 
 As was pointed out by others, the EL libraries don't
 recognize runtime
 expressions so you can't use %= ... % to get these.
 Your alternatives
 would be:
 
 * Go to the RT version (but give up EL expressions)
 
 * Store the constants you need under some well known names,
perhaps in application scope, so that you can use an
EL expression to get them.
 
   Thanks,
  
   JOHN
 
 Craig

--
To unsubscribe, e-mail:   
mailto:[EMAIL PROTECTED]
For additional commands, e-mail: 
mailto:[EMAIL PROTECTED]


_
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]



RE: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Karr, David
Well, if you actually have a scoped attribute named constants with a
getMyKey() accessor, then the expression would be
${constants.myKey}.

 -Original Message-
 From: David Graham [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, November 20, 2002 3:03 PM
 To: [EMAIL PROTECTED]
 Subject: RE: JSTL Question (EL vs. RT + Struts)
 
 I see, so I have to do constants.getMyKey().  I guess that's 
 easy enough.
 
 David
 
 From: Karr, David [EMAIL PROTECTED]
 
 There is none.  JavaBeans.  JavaBeans.  JavaBeans.
 
   -Original Message-
   From: David Graham [mailto:[EMAIL PROTECTED]]
  
   But what is the EL expression to get a constant like 
 Constants.MY_KEY?

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Wendy Smoak
 But what is the EL expression to get a constant like Constants.MY_KEY?
There is none.  JavaBeans.  JavaBeans.  JavaBeans.
 I see, so I have to do constants.getMyKey().  I guess that's easy enough.

What about c:out value=${constants.myKey} / ?

-- 
Wendy



Re: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Eddie Bush
... but can you even do that?  Can you use class-static methods without 
an instance of the class?

I've toyed with the idea of adding getters for constants into the 
Globals class, and then placing an instance of that class into 
application-scope.  What name should a person use though?  If you use 
the typical method of doing this you wind up with a chicken and egg 
scenario in your pages.  Of course, if we feel pretty satisfied that the 
location of the Globals probably isn't going to change again we could 
probably just decide that they will always be available under 
org.apache.struts.GLOBALS and be done with it.  You could then get 
ahold of the instance easily - and use that instance to reference other 
objects.

Incidentally, I don't believe there are any getters in the Globals class.

David Graham wrote:

I see, so I have to do constants.getMyKey().  I guess that's easy enough.

David 

--
Eddie Bush




--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Craig R. McClanahan


On Wed, 20 Nov 2002, David Graham wrote:

 Date: Wed, 20 Nov 2002 15:02:22 -0700
 From: David Graham [EMAIL PROTECTED]
 Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Re: JSTL Question (EL vs. RT + Struts)

 But what is the EL expression to get a constant like Constants.MY_KEY?


What I would do is have my app setup code save the value of
Constants.MY_KEY as a servlet context attribute such as MY_KEY.  Then,
the expression to access it would be the obvious one:  ${MY_KEY}.

 David


Craig


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Karr, David
It's a little more verbose, but you might also consider having a servlet
context Hashmap attribute, called constants, perhaps, and your app
setup would put all your constants into the map, so you would reference
it like this:

  '${constants[MY_KEY]}'

Actually, if you assume that all of your constant names have no spaces
in them (I guess that's reasonable :) ), you could also do:

  ${constants.MY_KEY}

 -Original Message-
 From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
 
 On Wed, 20 Nov 2002, David Graham wrote:
 
  Date: Wed, 20 Nov 2002 15:02:22 -0700
  From: David Graham [EMAIL PROTECTED]
  Reply-To: Struts Users Mailing List [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Subject: Re: JSTL Question (EL vs. RT + Struts)
 
  But what is the EL expression to get a constant like 
 Constants.MY_KEY?
 
 
 What I would do is have my app setup code save the value of
 Constants.MY_KEY as a servlet context attribute such as 
 MY_KEY.  Then,
 the expression to access it would be the obvious one:  ${MY_KEY}.
 
  David
 
 
 Craig
 
 
 --
 To unsubscribe, e-mail:   
mailto:[EMAIL PROTECTED]
For additional commands, e-mail:
mailto:[EMAIL PROTECTED]

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Karr, David
As long as we're experimenting here :) , you could even have a method
that takes a hashmap and a class, and uses reflection to load up all the
static final int constants into the hashmap.

 -Original Message-
 From: Karr, David [mailto:[EMAIL PROTECTED]]
 
 It's a little more verbose, but you might also consider 
 having a servlet
 context Hashmap attribute, called constants, perhaps, and your app
 setup would put all your constants into the map, so you would 
 reference
 it like this:
 
   '${constants[MY_KEY]}'
 
 Actually, if you assume that all of your constant names have no spaces
 in them (I guess that's reasonable :) ), you could also do:
 
   ${constants.MY_KEY}
 
  -Original Message-
  From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
  
  On Wed, 20 Nov 2002, David Graham wrote:
  
   Date: Wed, 20 Nov 2002 15:02:22 -0700
  
   But what is the EL expression to get a constant like 
  Constants.MY_KEY?
  
  
  What I would do is have my app setup code save the value of
  Constants.MY_KEY as a servlet context attribute such as 
  MY_KEY.  Then,
  the expression to access it would be the obvious one:  ${MY_KEY}.
  
   David
  
  
  Craig

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: JSTL Question (EL vs. RT + Struts)

2002-11-20 Thread Kris Schneider
Sounds like a job for a beanutils mechanism that does something like 
(untested):

Class clazz = GLOBALS.class;
String className = clazz.getName();

Map propMap = new HashMap();
List dynaProps = new ArrayList();
Field[] allFields = clazz.getDeclaredFields();
for (int i = 0, n = allFields.length; i  n; i++) {
  Field f = allFields[i];
  int mods = f.getModifiers();
  if (Modifier.isPublic(mods) 
  Modifier.isStatic(mods) 
  Modifier.isFinal(mods)) {
String name = f.getName();
Class type = f.getType();
Object value = f.get(null);
DynaProperty prop = new DynaProperty(name, type);
dynaProps.add(prop);
propMap.put(name, value);
  }
}

DynaProperty[] props = new DynaProperty[dynaProps.size()];
dynaProps.toArray(props);

BasicDynaClass dynaClass = new BasicDynaClass(className, null, props);
DynaBean dynaBean = dynaClass.newInstance();
BeanUtils.populate(dynaBean, propMap);
servletCtx.setAttribute(className, dynaBean);

Which gets you a DynaBean with all the constants exposed as properties. 
Lots of other twists possible...

Eddie Bush wrote:
... but can you even do that?  Can you use class-static methods without 
an instance of the class?

I've toyed with the idea of adding getters for constants into the 
Globals class, and then placing an instance of that class into 
application-scope.  What name should a person use though?  If you use 
the typical method of doing this you wind up with a chicken and egg 
scenario in your pages.  Of course, if we feel pretty satisfied that the 
location of the Globals probably isn't going to change again we could 
probably just decide that they will always be available under 
org.apache.struts.GLOBALS and be done with it.  You could then get 
ahold of the instance easily - and use that instance to reference other 
objects.

Incidentally, I don't believe there are any getters in the Globals class.

David Graham wrote:

I see, so I have to do constants.getMyKey().  I guess that's easy enough.

David 




--
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]