Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JSF displaying last selected value in dropdown

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i am new to JSF.
I am facing a problem in displaying the last selected value in the dropdown.

On selecting any value in the dropdown, i need to display the details of the selected item on the same page in textfields. I am doing this with valuechangelistener.
but when i return back from the listener, The text field are filled with the new values but i get an empty dropdown box.
so i re-populated the dropdown in the same listener.
Now, due to repopulation, i cannot get the last selected value in the dropdown.

i also tried to set the selected value in the listener through setSelctedId() where selectedId binds to my value attribute of selectOneMenu, which works, but its takes it as another value change for that dropdown and calls the listener again on the next submit of the form.\

here is my dropdown ......

<h:selectOneMenu id="selectName" value="#{myBean.selectedId}" valueChangeListener="#{myBean.valueChange}" valuePassThru="true" onchange="submit()">
<f:selectItems value="#{myBean.searchResult}" />
</h:selectOneMenu >

here is my listener method .........

public void valueChange(ValueChangeEvent vcEvent){

setSelectedId((String)vcEvent.getNewValue());

// populate the search ComboBox
if(null!=_contextBean.getSearchString() && !("".equalsIgnoreCase(_contextBean.getSearchString())))
{
setSearchResult(getSearchList(_contextBean.getSearchString()));

// filling my textfields here ......
}


FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurre

ntInstance(),null,"samepage");


}

 
Suraj Jallapelli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the solution....

i created a component for that dropdown in backbean and made a binding for it in th page. Also, i removed the value="myBean.selectedId" form the dropdown as i am get teh selected value in the listener using even.hetNewValue().

Now, in the listener, added these two statements,

selectComponent = (HtmlSelectOneMenu) event.getComponent();
selectComponent.setValue((String)even.getNewValue());

This works.!!
 
Suraj Jallapelli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



:thumb:
 
Suraj Jallapelli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Could you please explain how to do? I am also facing similar problem. I have exaplined here. When the page refreshes to display the list, I am not able to get the selected value from the list. here
Thanks.
 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic