my dog learned polymorphism
The moose likes JSF and the fly likes Programatically manipulate a component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Programatically manipulate a component" Watch "Programatically manipulate a component" New topic

Programatically manipulate a component

Terry Jeske

Joined: Apr 06, 2004
Posts: 17
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();

Any ideas. Any better ways to handle postbacks?
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Are you looking for this?


where in
"form:componentId" - form is the name of your form
componentId is the id of the component in that form.

- Varun
Abhi Raj

Joined: Sep 08, 2004
Posts: 7
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.
I agree. Here's the link:
subject: Programatically manipulate a component
It's not a secret anymore!