• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Populating the form on ValueChangeListener event

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you provided getter and setter method for userName property in the bean?
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic