• Post Reply Bookmark Topic Watch Topic
  • New Topic

Populating the form on ValueChangeListener event

 
M Yuvi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you provided getter and setter method for userName property in the bean?
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!