Discussions

Web tier: servlets, JSP, Web frameworks: Question and propositions about a request access pattern

  1. Hi,

    I have been trough this problem twice this month, I have a way to solve it, but I want have an idea of the best practice for this particular problem.

    In a multilangage web application, we have a jsp-oriented Translator class to translate all the content of a web site following the current langage of the user-session. The translator use a classic Ressource Bundle. Obviously, the translator need the "request" or the "session" to get the current langage id (Locale) of the user to do his job. The "problem" occure when a lower-level class (like the database interface) need to return a error message in the current langage. At this point, the database interface dont use any request, and cannot use the tranlator. So what is the best way to solve the problem?

    1) give to every class the request object in parameter? This can be anoying?

    2) Give to the database interface class a "getErrorMessage" that would return the Ressouce Bundle key for the current error message? (that would need some good thread synchronization!) or put it in a "session, request" object... : we have the same problem!

    So, what is the best "pattern" ?

    Thanks

    Etienne.
    etienno@sympatico.ca
  2. Here's my take on it:
    I think it's wrong to mix your database interface up with UI-level issues (e.g, language of error reports). The database should return a "logical" value indicating the error type. This can be, for instance, a String used as the ResourceBundle key.
    The Translator should translate this logical error representation to an external error description just like it translates everything else: by looking up the description string in the ResourceBundle based on it's key.

    Gal
  3. you are right[ Go to top ]

    thanks, I agree. Etienne