You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by CarlHowarth <ca...@dlapiper.com> on 2007/08/14 16:36:11 UTC

Immediate property on self-submitting drop-down

Hello there,

I have a select one menu in a file that is included on all pages of my
webapp. This is to change the language of the site based on user's
preference. I have included onchange="submit();" and immediate="true"
however the immediate property appears to be ignored and validation occurs
on, for example, a data-entry screen.

Here's my JSF:
      <t:selectOneMenu value="#{sessionBean.preferredLocale}" 
immediate="true" onchange="submit();">
        <f:selectItems value="#{sessionBean.supportedLocales}"/>
      </t:selectOneMenu>

Does anybody know a workaround for this please?

Thanks, Carl
-- 
View this message in context: http://www.nabble.com/Immediate-property-on-self-submitting-drop-down-tf4267687.html#a12145684
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Immediate property on self-submitting drop-down

Posted by Simon Lessard <si...@gmail.com>.
Hello Carl,

You need to add a valueChangeListener as well and have it call
FacesContext.getCurrentInstance().renderResponse() after setting the new
Locale on the view root. So you need to add the following method to your
bean:

public void changeLanguage(ValueChangeEvent ev)
{
  FacesContext context = FacesContext.getCurrentInstance();

  Locale selectedLocale = (Locale)ev.getNewValue();
  if (selectedLocale != null)
  {
    context.getViewRoot().setLocale(selectedLocale);
  }

  context.renderResponse();
}

And in the page:
<t:selectOneMenu value="#{viewRoot.locale}"
                 valueChangeListener="#{sessionBean.changeLanguage}"
                 immediate="true"
                 onchange="submit();">
  <f:selectItems value="#{sessionBean.supportedLocales}"/>
</t:selectOneMenu>

Regards,

~ Simon

On 8/14/07, CarlHowarth <ca...@dlapiper.com> wrote:
>
>
> Hello there,
>
> I have a select one menu in a file that is included on all pages of my
> webapp. This is to change the language of the site based on user's
> preference. I have included onchange="submit();" and immediate="true"
> however the immediate property appears to be ignored and validation occurs
> on, for example, a data-entry screen.
>
> Here's my JSF:
>       <t:selectOneMenu value="#{sessionBean.preferredLocale}"
> immediate="true" onchange="submit();">
>         <f:selectItems value="#{sessionBean.supportedLocales}"/>
>       </t:selectOneMenu>
>
> Does anybody know a workaround for this please?
>
> Thanks, Carl
> --
> View this message in context:
> http://www.nabble.com/Immediate-property-on-self-submitting-drop-down-tf4267687.html#a12145684
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>