• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Replace scriplet reference to a static

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given these two classes:


I want to get rid of this scriptlet:


But I have not been able to figure out the syntax. (It would be nice to get rid of the expression also.) Can anyone clear this up for me?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does the constant exist in the first place? My question would not be how to reference the constant from the JSP, but how to get rid of it in the first place.
 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean, use a context init param instead? I think the reason it was done this way was to enable reading in all these settings via a Properties object and then populating the bean properties. I'm not quite following you.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question is simple: what is the purpose of the constants in the Constant class?

It's not all clear from what you're posting, and I'm having a hard time not seeing a huge anti-pattern red flag waving.

If the answer is: to provide run-time flags, then a constant class is a huge anti-pattern. Use a properties file. Easily read by a context listener and stored as a Map in app context where the EL can easily access it.
 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I more or less understand. I've been looking at this code and trying to understand why we need a class at all if it's just a big wrapper for a Properties object, and I could not come up with anything. This code was done a long time ago.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Updating a web app to move away from scriptlets and to the JSTL/EL is almost never as easy as a line-by-line substitution, unfortunately. There's usually some refactoring involved and this is a perfect example.

As previously mentioned, the approach I'd take is to put the values into a properties file and read them in in a context listener. Store the name/value pairs in a Map in app scope. Then it's trivial to access the values from anywhere in the app, including the JSPs.

It's not only a clearer, more conventional approach, but it doesn't require code changes and rebuilding to change the values.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic