Generally, you would want the Action to handle that, and then tuck the
text into beans for the view to display. 

Alternatively, you can retrieve the locale in the Action, and set it to
your form. 

    public Locale getLocale(HttpServletRequest request) {
        Locale result = null;
        HttpSession session = request.getSession();
        if (session!=null) {
            result = (Locale) session.getAttribute(Action.LOCALE_KEY);
            if (result == null) result = Locale.getDefault();
        } else {
            result = Locale.getDefault();
        }
        return result;
    }

It's stored under a key in the user's session, so you can get to it
anywhere you can get to the session.

To change locales for a user, you should change the one under the
Action.LOCALE_KEY.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/struts/


Francesco Marsoni wrote:
> 
> I would like to write a method in a ActionForm to retrieve values from a
> database based on Locale set for the current user so I can use them in
> <html:options> tag.
> But I can't see the way to get the Locale.
> 
> public final class RoomForm extends ActionForm {
>   public void reset(ActionMapping mapping, HttpServletRequest request) {
>   }
> 
>   public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> request) {
>     ActionErrors errors = new ActionErrors();
>     return errors;
>   }
> 
>   public Enumeration getLabels() {
>    // Here I want to set the language so I need to get Locale.
>     String language = "en"
>     ?????
>     return (Facade.getInstance().getLabels(language));
>   }
> }
> 
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to