users@woodstock.java.net

Re: How to set locale values to radiobutton options

From: Dan Labrecque <Dan.Labrecque_at_Sun.COM>
Date: Tue, 10 Jun 2008 12:06:30 -0400

Not certain the Option class has a setValueExpression method, but value
expressions are assigned like so:

    TableColumn col = new TableColumn();
    setValueExpression(col, "sort", "#{TableBean.sort}"); // Set sort.

    public static void setValueExpression(UIComponent component, String
name, String expression) {
        component.setValueExpression(name, createValueExpression(
            FacesContext.getCurrentInstance(), expression, Object.class));
    }

    public static ValueExpression createValueExpression(
            FacesContext context, String expr, Class value) {
        return context.getApplication().getExpressionFactory().
            createValueExpression(context.getELContext(), expr, value);
    }

You can also pull localized strings from a resource bundle. For example:

    /** Get a formatted message from the application's resource file. */
    public String getMessage(String key, Object[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle(
            "com.sun.webui.jsf.example.resources.Resources", getLocale());

        String message = null;
        try {
            message = bundle.getString(key);
        } catch (MissingResourceException e) {
        }
        return message;
    }

Dan

d1s4st3r d1s4st3r wrote:
> Hello,
>
> this is my first message on this ML.
>
> I would be pleased to get some help on how to set locale values to
> radiobutton options.
>
> In my JSF application I'm using a locale bundle and everything works
> fine with all the component, except for a radiobutton.
>
> I tried to use the following code to obtain what I need, but it
> doesn't work at all (myMessages is the bundle):
>
> |myRadioButtonDefaultOptions.setOptions(*new* com.sun.webui.jsf.model.Option[]{*new* com.sun.webui.jsf.model.Option("0", "#{myMessages.All}"), *new* com.sun.webui.jsf.model.Option("1", "#{myMessages.No_File}"), *new* com.sun.webui.jsf.model.Option("2", "#{myMessages.With_File}")});
>
> myRadioButtonDefaultOptions.setSelectedValue("0");
> |
>
> When the page gets rendered, the radiobutton default option labels are
> wrongly "#{blablabla}" instead of the right values depending on the
> locale.
>
> Any help would be really appreciated, thanks!
>
>
> --
> +-----------------------------------------+
> | ~~~[ d1s4st3r ]~~~ |
> | --------------------------------------- |
> | http://xoomer.alice.it/mental_insomnia/ |
> | http://d1s4st3r.blogspot.com/ |
> | http://d1s4st3r.deviantart.com/ |
> +-----------------------------------------+
> | "I live on the edge between the |
> | uncertainty and the wrong choice." |
> +-----------------------------------------+