Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get generated ID of the JSF componenet dynamically in the JavaScript?  RSS feed

 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a number of components in a JSF page. Now in many of the cases i have to change their behavior using javaScript. Now every time I have to run the page and have to get its ID from the source of the generated page. I want to do it dynamically so that i use the simple id which i provide at the time of writing and it will take the specified component and will do the needful.


One solution which I thought was of using Regex as Component id which is provided by the user comes in the last like formName:ComponentID but dont know that it will work or not?

Please help to find out some suitable nad feasible solution to it.

Thanks in advance.
 
Victor Bucutea
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,


Yes it will work just fine . ids are generated in the form


formID:compID ,
and where's a table inolved ( data is wrapped in a UIData object ) you will have something like formID:tableID:compID ... not sure about that table id , but anyways it's a constant which you can easily get .
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean like this?


That's a snippet from a page where a Javascript function shifts a datatable containing arrival and departure times by a fixed amount. I've omitted the parts that don't relate directly.
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean similar to this line.



To write some general js function which will take the id given by the user and the form name as parameters and will make the id String that will be used by the getElemnetById function.

Will this be right??
 
Victor Bucutea
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,


If the above code actually returns the element , then it's ok . This is the way that JSF API handles ID's . If you don't beleive me , and you want to be introspective ,

Here , take a look at the JSF 1.2 specification document
http://jcp.org/aboutJava/communityprocess/final/jsr252/index.html


particularly section 3.2.3 ( Naming Container - objects that implement this interface actually add another colon-separated id - the implementing oject overrides the method getClientId() which in turn changes the default Id of a component )

section 4.1.3 - UIData Object and 4.1.4 - UIForm object , the part about getClientId() methods ;) .


victor
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!