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 JSF and Javascript why id elements have a strange names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF and Javascript why id elements have a strange names" Watch "JSF and Javascript why id elements have a strange names" New topic
Author

JSF and Javascript why id elements have a strange names

Enrique Villamizar
Ranch Hand

Joined: Jul 30, 2005
Posts: 93
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

Joined: Nov 03, 2009
Posts: 80

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.


Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
willCodeForFood("Java,PHP,C#,XML,VBS,XHTML,CSS,JavaScript,SQL"); //always looking for job opportunities in AU/NZ/US/CA/Europe :P
Enrique Villamizar
Ranch Hand

Joined: Jul 30, 2005
Posts: 93
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

Joined: Jul 30, 2005
Posts: 93
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

Joined: Nov 03, 2009
Posts: 80

Thanks, will have in mind... =)
Samuel March
Ranch Hand

Joined: Oct 28, 2009
Posts: 39
Did you supply your own id to the form???

h:form id="someform"

next is the result............
h:input id="someform:firstinput"


...did you have the fish?!............................ No.
Akaine Harga
Ranch Hand

Joined: Nov 03, 2009
Posts: 80

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

Joined: Jul 30, 2005
Posts: 93
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

Joined: Jun 25, 2001
Posts: 16137
    
  21

The magic word is "naming container".


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF and Javascript why id elements have a strange names