Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF and Javascript why id elements have a strange names

 
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody:

Unfortunately I still have problems using Richfaces or Icefaces in my JSF application so I think to use plain Javascript. But now I got a problem, I try to get the element but it doesn't work because it seems to me that the ids and names are changed. When I see the generated code in my browser it looks like this:



I have in my code:
So the question is why my code works well with HTML but not with JSF tags? Do you think is better using Dynamic Faces (JSF Ajax Extension)? To many options but I don't know what way to choose and my time is running out. They gave me an opportunity but need results!

Could you give a hand to a newbie JSF programmer? Thanks!
 
Akaine Harga
Ranch Hand
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mmm, I haven't played enough with JSF so I don't know if there is any way to clean the ids. What you could do without digging the Web is this:

Hope you get the idea. I'd recommend changing indexOf to a regexp to specify that there is nothing after the id parameter (with indexOf you can get more than one element if their ids is like "myEl01one", "myEl01two"). And of course since with this code you'll through every element on the page it can be slow if you use it with high frequency in you algorithm.
 
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...I got your idea. I'll do my homework filtering the ids.

You'll hear from me soon.

Thanks a lot for your help, Akaine.
 
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found one way to solve my problem in Adding Ajax to JavaServer Faces Technology With Dynamic Faces

The solution is:

1) Add the JSF Extension(Ajax) to my project

2) in the web.xml add
3) Add the followint to my page JSF page:
4) and finally in the form tag:


This new attribute in JavaServer Faces 1.2 technology advises the JavaServer Faces runtime to not prepend any naming container IDs to your component IDs within the form. The result is that the IDs you type in the markup are the actual ones that appear in the page.
Taken from the article i mentioned before and it works!
 
Akaine Harga
Ranch Hand
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, will have in mind... =)
 
Samuel March
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you supply your own id to the form???

h:form id="someform"

next is the result............
h:input id="someform:firstinput"
 
Akaine Harga
Ranch Hand
Posts: 99
Java MyEclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Samuel March wrote:Did you supply your own id to the form???
h:form id="someform"
next is the result............
h:input id="someform:firstinput"
Hmm, I always had the ids this way and I always supplied the form id. So I don't know what's wrong or if there is anything wrong at all. JSF and especially Richfaces generate many elements to display one simple field and almost each elements has its id generated.
 
Enrique Villamizar
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:

You're right... I supplied an id to the form and then I called it the way you said (formId:elementId) and it works as well. The first time I did it I made a mistake given a no unique id to the form...now I realized about that. Anyway with JSF Extension(Ajax) allow me to add Ajax functionality to JSF's components.

A new task has arised ... How to use Dynamic Faces in my project...too many doubts . I'm on my way...

Thanks Samuel and Akaine for helping me.

 
Tim Holloway
Saloon Keeper
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The magic word is "naming container".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic