• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF onchange event on SelectOneListbox

 
ming han chai
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here i got a problem pertaining to h:selectOneListbox, i have a page with a drop down list showing available languages, when the user change to other selection, the page will automatically change it's content base on the selected langauge (Locale).

Below shows the source code
....// jsp
<h:selectOneListbox id="select" value="#{localeTracker.defaultLocale}" valueChangeListener="#{localeTracker.changeLocale}" onchange="this.form.submit()" immediate="true" >
<f:selectItems value="#{localeTracker.langItems}" />
</h:selectOneListbox>

...// LocaleTracker class
public void setChoosenLocale( String choosenLocale )
{
this.choosenLocale = choosenLocale ;
}

public String getChoosenLocale()
{
return this.choosenLocale ;
}

public void changeLocale( ValueChangeEvent vc )
{
FacesContext con = FacesContext.getCurrentInstance();
con.getViewRoot()
.setLocale( new Locale( this.getChoosenLocale() ) );
}
..

For example. there are English and Spannish as current available langauge
and English is currently being selected, When i select Spannish, the locale change to English, and if i select english, the spannish is being used, meaning that the value being set to the choosenLocale is the value being deselected ( the old value )

Could anyone help me out pls. Thank you
 
Vladimir Bezugliy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code works well:


 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- You have used immediate=true in your tag, it hints me that you want to by pass some thing (like some other required="true" check or some other validation, conversion of some other component)

- Your valueChangeListener is not having the line - facesContxt.renderResponse() at the end, which means the objective your trying to achieve by using immediate="true" is not working,[ i.e. validations, or anything you want to by-pass are still happening ]

-- Use h:messages tag in the front end to see if you are receiving any error.
[ February 01, 2005: Message edited by: K Varun ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!