*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Programatically manipulate a component" Watch "Programatically manipulate a component" New topic
Author

Programatically manipulate a component

Terry Jeske
Greenhorn

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();
facesContext.getApplication().???

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

Joined: May 30, 2002
Posts: 1400
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.


- Varun
Abhi Raj
Greenhorn

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.
 
Don't get me started about those stupid light bulbs.
 
subject: Programatically manipulate a component
 
Similar Threads
Richfaces DataTable Problem
Translating GET parameters to POST parameters. There's got to be a better way.
JSF: Problem with valueChangeListener
Spring web flow, JSF and managedbean in servlet
Dynamic Component in JSF