facebook

Struts internationalization

  1. MyEclipse IDE
  2.  > 
  3. Comments
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #211122 Reply

    Hi,

    I know I can use bean:write to access values in my properties files. But I’m stuck trying to use these values anywhere else.

    In my action clasee I use: MessageResources messageResources = servlet.getResources();

    and that works, though it’s flagged as “depracated” and don’t know what new method has replaced it.

    And for my business object, I’m completely unable to figure out how to access the values in my properties fiels. I don’t want to specifically open them as I want to take advantage of int8l features. I want to ensure that property file and resource bundle set in my struts config is the one i’m using.

    I’m trying to use these files to store configuration settings like “webRootDir” etc. so that as I move my application from development to test to production, I just change the properties.

    Any help would be appreciated….as well as any help on where there’s a good struts forum.

    Lee

    #211123 Reply

    Riyad Kalla
    Member

    Lee,
    The methods you want are on action (getMessages, getResources), however for storing app level things like that, you probably want to make them init parameters in your web.xml file, and then retrieve them via servlet.getServletContext().getInitParam (I forget the exact names).

    Think of another developer comming onto the project, it seems strange if he finds application initialization parameters stored in the internationalization properties file, that’s what the web.xml file is for.

    This is just a tip, of course you are free to do anything you feel is best.

    #211124 Reply

    @support-rkalla wrote:

    Lee,
    The methods you want are on action (getMessages, getResources), however for storing app level things like that, you probably want to make them init parameters in your web.xml file, and then retrieve them via servlet.getServletContext().getInitParam (I forget the exact names).

    Think of another developer comming onto the project, it seems strange if he finds application initialization parameters stored in the internationalization properties file, that’s what the web.xml file is for.

    This is just a tip, of course you are free to do anything you feel is best.

    Thanks–that’s why I asked 🙂

    Lee

    #211143 Reply

    Ok — I figured out how to put init-parms in the web.xml and read them back.

    Would like input on my following idea:

    In order to make these init params easily available to the rest of my app — I’ll craete a settingsVO (value object) class.

    In my BaseAction, which is a subclass of action that I use for all my action classes — I’ll put code that checks to see if session.settingsVO exists — and if not, then to instantiate one from the init-params and put it in the session.

    Then anywhere in my app I can just get sessions.settingsVO to get the value to get my application variables like “root directory path”.

    Lee

    #211150 Reply

    Riyad Kalla
    Member

    Few comments:
    If you are placing your SettingsVO object in the session, that means people need access to the session, which means “anywhere in my app…” probably means within the actions, correct? If taht is the case, the Actions already have implicit access to the servlet and servlet context, which have the init params already stored in them. By introducing the SettingsVO class you are basically duplicating what is already done for you, and you also run into the problem if the web.xml file changes, the container will reload your servlet, but your SettingsVO class values will not be updated, but the init-params will.

    I would suggest not introducing that additional level of abstraction, unless you really felt strongly about it, in which case I would suggest that you place it in your APPLICATION SCOPE, not the session scope. There is no reason for each session to have a copy, it will never change between sessions… and to put it in the application scope, you actually need to use servletContext.get/setProperty, which is exactly how you would be getting the init params anyway… so again, its duplicating work.

    I hope that helped, ultimately this is your project, you do whatever you think is best for you.

    #211201 Reply

    @support-rkalla wrote:

    I would suggest not introducing that additional level of abstraction, unless you really felt strongly about it, in which case I would suggest that you place it in your APPLICATION SCOPE, not the session scope. There is no reason for each session to have a copy, it will never change between sessions… and to put it in the application scope, you actually need to use servletContext.get/setProperty, which is exactly how you would be getting the init params anyway… so again, its duplicating work.

    I hope that helped, ultimately this is your project, you do whatever you think is best for you.

    Thanks again. Follow up question, if I may. If I want to use these values in my business objects, I guess I should pass them is as parameters from the action classes correct? That way the business objects do not need to know about the server.

    I guess that’s my problem, not separating my business logic from the application server. Basically I wanted “global variable” that I can access anywhere in my app that are stored in the applications config file.

    So, as long as the action class can access the servletContext, I just need to pass the values in to the business classes…correct?

    Lee

    #211234 Reply

    Riyad Kalla
    Member

    If I want to use these values in my business objects, I guess I should pass them is as parameters from the action classes correct? That way the business objects do not need to know about the server.

    This sounds like a good design to me, maybe this is where your SettingsVO object comes into play? Create it when you call the object (assuming its not too terribly often)?

    I guess that’s my problem, not separating my business logic from the application server. Basically I wanted “global variable” that I can access anywhere in my app that are stored in the applications config file.

    Hmm… well in a web app putting something in your servlet context is just this, a global scope… but if you want to keep your Busines Objects dumb to this, then I think you have the right idea of passing them in when you call them.

    So, as long as the action class can access the servletContext, I just need to pass the values in to the business classes…correct?

    Bingo

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Struts internationalization

You must be logged in to post in the forum log in