Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it an anti-pattern to put labels and such in property files (releated to JSP's and web development)

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.

like image 772
Berlin Brown Avatar asked Oct 15 '22 15:10

Berlin Brown


1 Answers

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.

like image 171
BalusC Avatar answered Dec 15 '22 14:12

BalusC