You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Neal Kaiser <ne...@makeastore.com> on 2001/02/25 17:21:04 UTC

logic-equal for locale

When I do this:

<logic:equal parameter="locale" value="en">
You are English locale
</logic:equal>

I get an exception telling me that I am trying to compare a null variable to
"en".
What is the correct way to compare the locale with the logic:equal tag?

Thanks.


Re: logic-equal for locale

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Neal Kaiser wrote:

> When I do this:
>
> <logic:equal parameter="locale" value="en">
> You are English locale
> </logic:equal>
>

This test is looking for a request parameter named "locale", so that it
will
only work if you include such a parameter (say, as a hidden input
variable) in
your input form.

>
> I get an exception telling me that I am trying to compare a null variable to
> "en".
> What is the correct way to compare the locale with the logic:equal tag?
>
> Thanks.

If you want to check the standard session parameter that Struts
maintains, you
could try something like this:

    <logic:equal name="org.apache.struts.action.LOCALE"
      scope="session" property="language" value="en">
        You are in an English locale
    </logic:equal>

The reason this works is that "name" identifies the bean (in the scope
identified by "session") that contains the property you are interested
in.  In
this case, it's the Locale object maintained by the framework.  We are
going to
compare the "language" property of that object (i.e. the result of
calling
getLanguage()) with the constant for the language we are interested in.

Craig