This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSF and the fly likes Populating the form on ValueChangeListener event Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Populating the form on ValueChangeListener event" Watch "Populating the form on ValueChangeListener event" New topic
Author

Populating the form on ValueChangeListener event

M Yuvi
Greenhorn

Joined: Mar 19, 2008
Posts: 9
I have problem with populating the form with data, upon selecting a value in the list box. Upon selecting the list box, by handling the ValueChangeListener, I want to populate the form with the corresponding data.

Below is the JSP
...
<h:selectOneMenu valueChangeListener="#{user.fetchData}" onchange="submit();" value="#{user.userId}">
<f:selectItems value="#{user.userIdList}" />
</h:selectOneMenu>

<h:inputText value="#{user.userName}" />
<h:commandButton action="#{user.submit}" value="click"/>
...

The corresponding managed bean is ...

public class User {

private int userId;
private List<SelectItem> userIdList=new ArrayList<SelectItem>();
private String userName;

// getter and setter methods
public void fetchData(ValueChangeEvent event){
// some logic to assign the userName
userName="C";
}
}

Upon selecting a particular userId, the corresponding userName is displayed in the form if the "disabled" property of userName UI component is set to "true". Otherwise, the data is not displayed in the form. However my requirement is, the corresponding data should be displayed and the user should be allowed to edit the details and store it on submit.

Please help me in resolving this.
Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39
hi M Yuvi,

you can bind the username value to the corresponding inputtext in the backing bean and then set the value of the binding element

thankyou
Vishal Chaudhry
Greenhorn

Joined: Dec 16, 2009
Posts: 7
Have you provided getter and setter method for userName property in the bean?
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Populating the form on ValueChangeListener event
 
Similar Threads
Is it possible to refresh the dropdown h:selectOneMenu
Dymaic SelectOnelist and Onchange event
problem while setting default value for h:selectOneMenu
How to set default selection for selectOneMenu?
Create a Different selectOneListbox Depending On the Radio Button Clicked