This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Programatically manipulate a component

 
Terry Jeske
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my backing bean can I retrieve and manipulate the properties of a UI component?

For example, I have a datatable who's default value is set to null. On the postback, I want a combobox's ValueChangeEvent handler to get an instance of the datatable, and change it's value property with a bean method that will populate the table (this may be the wrong way, but I am trying to work around JSF's lack of postback handling -arrrgh!). I thought that if I got the current facesContext, and then got the application, that I should be able to get an instance of a component. But it appears that I can only create components using this technique.

I tried the following:
FacesContext facesContext = FacesContext.getCurrentInstance();
facesContext.getApplication().???

Any ideas. Any better ways to handle postbacks?
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you looking for this?

FacesContext.getCurrentInstance().getViewRoot().findComponent("form:componentId"));

where in
"form:componentId" - form is the name of your form
componentId is the id of the component in that form.
 
Abhi Raj
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you can create a component binding which binds the component to a backing bean.

e.g. <h utputText binding="#{bean.text}" /h>

Then, the bean contains an attribute : HtmlOutputText text

You can directly manipulate properties of the component from this reference.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic