• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF displaying last selected value in dropdown

 
Suraj Jallapelli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator



:thumb:
 
Suraj Jallapelli
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




 
Gopu Akraju
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic