I see a lot of J2EE developers put labels in property files but don't use different Locales. So, you get a lot of missing property exceptions. And the main thing is that it makes it hard to debug and read a JSP page. So over time, you have thousands of lines of property files that may or may not be used with the JSP file.
For me, it seems like a bad design, especially if you don't intend to use a property file with different languages and change to say english or french depending on Locale.
I was just wondering if you felt the same and is there a list or URL of J2EE/JSP anti-patterns.
Separation of content from template is always a good practice. This way you don't need to rebuild, redeploy and/or restart the whole thing for every stupid contextual change/typo/hiccup. The ResourceBundle
API (which is standard been used behind JSTL's fmt
taglib and other i18n/l10n taglibs) is smart enough to reload resource files dynamically on every change (at least, if you're using JDK 1.6 or newer, which has those enhancements builtin).
Also, whenever you want to go i18n or want to change from a propertiesfile to a database table or something else, then you don't need to change the template to extract the content from it --which would bite you much more if you do it afterwards.
It's only a bit of work to correlate the content and location in template with each other, I can imagine that this is the major fear among the developers/maintainers. I myself compose keys so that they roughly match pagename.parentid.elementtype.elementname.contenttype
(roughly; not all of them is necessary, but it gives an idea) so that it's already immediately clear where it belongs.
E.g. a home.login.label.username.tooltip
key which points to a home.jsp
with:
<form id="login">
<label for="username" title="${text['home.login.label.username.tooltip']}">
Keep this convention consistently and you'll find that it becomes more easy to maintain this all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With