File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes UIViewRoot findComponent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "UIViewRoot findComponent" Watch "UIViewRoot findComponent" New topic
Author

UIViewRoot findComponent

Patricio Hervas
Greenhorn

Joined: Mar 28, 2006
Posts: 16
Hi. Some time ago I was wondering if you could access a component by its
id like in javascript with getElemetById.
I just found that there's this findComponent in the UIViewRoot which
i guess would work like getElementById.
Now, my question is if you have a native html tag (lets say a DIV)
with an id, would it get mapped into the FacesContext tree ?
Or only jsf native components get mapped in the FacesContext.

I wonder if something like this would work:

<div id="someDiv">
....
</div>

--
FacesContext fc = FacesContext.getCurrentInstance();
UIViewRoot view = fc.getViewRoot();
UIComponent div = (UIComponent)view.findComponent("someDiv");
div.setStyle("border: 1px solid red");
Patricio Hervas
Greenhorn

Joined: Mar 28, 2006
Posts: 16
Does anybody know ?
help :-)
Rajeev Ravindran
Ranch Hand

Joined: Aug 27, 2002
Posts: 455
As far as I know, JSF will not consider native html as a component. But could you tell why you need the <div> tag inside your JSP ? Are you doing anything like dynamic label change using javascript ?

Thanks,
Rajeev
Patricio Hervas
Greenhorn

Joined: Mar 28, 2006
Posts: 16
Well, i'm learning jsf and i like it very much. but i have a background
on php programming, with a lot of css and javascript things going on
just to enhance the application's look and feel (i like cool interfaces)

definitely programming in jsf is very powerful in so many ways than
php, but i like having total control on the rendered html so that i can
apply dinamic css depending on things going on in the application.

so lets say that i enclose the <X:messsages> inside a div.
it would be cool if i could, inside a bean, put a border and
background color on the containing div if there's a message
displayed. also, depending on the message severity, the border
could be of different colors, etc.

its just an example of things that i would like to do from a bean
and if you could control tag properties from a bean like you do with
javascript it would give you a lot of possibilities inside your app
without scripting inside the page and maybe reusing code a such.

i like that with myFaces im able to use normal html tags with jsf
tags without using <f:verbatim> so i can use external css's with
no problem to control the layout of the page 100% . i just want not
to do scripting in javscript.

that's basically what i wish to have control over
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

OK, I am like a complete JSF newbie, but I am reading Pro JSF and Ajax, and it makes custom components, and it doesn't look too difficult, and there are attributes that you can make dynamic and assign programatically, so you could say create a subclass of a UIInput that takes in attributes that can be determined at runtime, and then it would render itself differently based on those attributes.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: UIViewRoot findComponent