views:

92

answers:

2

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.

+1  A: 

It's definitely a good practice to put labels in property files. Even if you don't plan to internationalize now, this may happen in the future. It also helps you to use a consistent naming across your pages.

I don't know why are you getting property exceptions. In most frameworks the system will read the default (english) file, if a properties file for user's locale isn't found.

You need to get used on reading JSP pages with fields read from an external properties file. It isn't that hard and the benefits far out-weight the hassle.

kgiannakakis
+2  A: 

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.

BalusC