Is it possible to get component Reference from the FacesContext

Hello Friends,

I am not much familier to JSF but have to perform some assigned work so need your valuable help.

I want to get the reference of Component (not binded with any bean)available on the JSF page in my Java code. I have to use its id attribute for this but not sure how I can get this. Is this possible with the FacesContext or someother mean.

Any suggestion will be appriciated.

Looking for some quick response.

Thanks.

[467 byte] By [Doga] at [2007-11-27 11:42:59]
# 1

Using the FacesContext you can get the UIViewRoot. From there you can search for the component with the correct id. I think there are even some convenience methods for that, check the API.

RaymondDeCampoa at 2007-7-29 17:47:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for your help.

However I could not get the result. I am using following code:

public void myaction(ActionEvent event)

{

FacesContext context = FacesContext.getCurrentInstance();

UIViewRoot view = context.getViewRoot();

UIComponent UI = view.findComponent("tab");

if(UI == null)

System.out.println("UI Not Found ");

else

System.out.println("Get Current FecesContext");

}

There is an Component having id "tab" is available on JSF page but I am getting "UI not Found" every time. Is there somthing wrong...Please suggest.

Doga at 2007-7-29 17:47:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Is "tab" also the actual client ID? Keep woodstock ID's in mind, the ID will be prefixed with the ID of every naming container (h:form and f:subview). In every datatable row the ID will also be prefixed with the row number.

Easiest way is to look into the generated HTML source what's the actual ID.

BalusCa at 2007-7-29 17:47:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...