• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UIViewRoot findComponent

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anybody know ?
help :-)
 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic