This is an anti-template for placing labels and such property files (released for JSP and web development)

I see that many J2EE developers put labels in property files, but do not use different locales. This way you get many missing exceptions. And most importantly, it makes debugging and reading a JSP page difficult. Therefore, over time, you have thousands of lines of property files that may or may not be used with the JSP file.

For me it looks like a bad design, especially if you are not going to use the properties file with different languages ​​and can change the English or French language depending on the Locale.

I'm just wondering if you felt the same way and if there is a list or url of JAEE / JSP anti-patterns.

+4
source share
2 answers

Separating content from a template is always good practice. This way, you don’t need to rebuild, relocate and / or restart all this for any silly / typo / hiccup context changes. ResourceBundle API (which is standard for the JSTL fmt taglib and other i18n / l10n tags) smart is enough to dynamically update resource files with every change (at least if you are using JDK 1.6 or later, which has those enhancements built into ).

In addition, whenever you want to switch i18n or want to switch from a properties file to a database table or something else, you do not need to change the template to extract the contents from it - so that you would be bitten more if you do it later.

It’s a bit of work to compare the content and layout in the template with each other, I can imagine that this is the main fear among developers / maintainers. I compose the keys myself so that they roughly correspond to pagename.parentid.elementtype.elementname.contenttype (roughly, not all of them are necessary, but this gives an idea), so that it immediately becomes clear where it belongs.

eg. a home.login.label.username.tooltip that points to home.jsp with:

 <form id="login"> <label for="username" title="${text['home.login.label.username.tooltip']}"> 

Keep this agreement in sequence and you will find that it all simplifies.

+3
source

It is definitely a good practice to put labels in property files. Even if you do not plan to internationalize now, this may happen in the future. It also helps you use consistent naming on your pages.

I do not know why you get exceptions for property. On most systems, the system reads the default file (English) if the properties file for the user's locale is not found.

You need to get used to reading JSP pages with fields read from an external properties file. It is not that difficult, and the benefits far outweigh the chores.

+1
source

All Articles