• 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

What is the best practice of handling attribute names?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Scope attribute names in Servlets/Jsp are strings. Due to typing errors it is bad to use them as such.

It would be good to have an enum or an interface with string constants. But having such an interface it

becomes a dependency magnet, every servlet and jsp in the system depends on it and requires

recompilation on every attribute name change or attribute addition.

It there any best practice or pattern to handle scope attribute names?

Thanks,
Marcin
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marcin,

from my personal experience I'd suggest you to keep the "string" properties where they belong to. In my opinion it makes everything more difficult if create separate interfaces or classes to hold these constants.

Why not just create public static string constants in those classes where you need them? This is a common practice in many swing components which also use strings as property names for listeners and other components which depend on these names. So you have only one place where you really define the names and all other classes only have to rely on some public static final string constants.

Marco
 
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
In a modern web application, the largest consumer of scoped variable names is EL expressions. And since the EL does not natively have any way to access string constants, defining such constants for scoped variable names is problematic.

If you really really really want to do it that way, you can read this article in which I devise a way to expose constants to the EL, but I never use it for scoped variable names -- I think it creates too messy a level of indirection.

Personally, when it comes to scoped variable names, I just type carefully.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I didn't think about EL expression. In this case my advice is obviously not the very best idea

Marco
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic