• Post Reply Bookmark Topic Watch Topic
  • New Topic

dynamic creation of id attribute

 
Yvette Gonzalez
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All - I am a JSF newbie. I have a datatable form with each row containing a drop-down selectonemenu and a inputtextbox. I would like to use javascript (or anything!) to have the drop-down populate the textbox. I wanted to assign the id's of the components using the rowindex of the datamodel for the datatable but id won't let me. What am I missing? Thanks!
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF already does it. You don´t need to do it. Just assign a fixed ID to h:form, h:dataTable, h:anyInputComponent and -if any- the f:subview so that JSF won´t autogenerate ID´s for you so that you have consistent element ID´s in the generated HTML output at end.
 
Yvette Gonzalez
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks but won't I have a table full of drop-down with the same id if I assign an id once in the datatable and it iterates over a datamodel? How can I reference it in the Javascrpit?

I apologize for my ignorance!! Thank you so much!!
 
Yvette Gonzalez
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way - your blog is wonderful and a lifesaver!! I was hoping you would reply! Thanks!
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the generated HTML output, make use of the 'this' reference in Javascript and a shot of logical thinking

Example:



 
Yvette Gonzalez
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bauke! I took a shot of logical thinking and now all is working!
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You´re welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!