1

and in JavaScript

 document.getElementById('myId');

This is not working in JSF application. However, the same is working if I save the generated HTML in my system and open it .

Any Help ?

2
  • I dont know the significance of this. I'll do from now. Thanks Commented Dec 30, 2009 at 12:08
  • 1
    Visit your profile page stackoverflow.com/users/205505/abhishek, reread all the questions you posted and set answers which actually helped in answering/solving the question/problem to accepted by ticking the big white V on left hand side of the answer. Also upvote answers which were actually valueable. Downvote answers which are wrong. Leave normal/nothing-new-to-add answers as is. Commented Dec 30, 2009 at 15:51

1 Answer 1

2

When writing JavaScript code for a component based MVC framework which generates HTML, like JSF, you should not focus on the source code of the component based MVC framework, but on its generated HTML output.

If you can't tell this beforehand based on the source code, then you need to just open up the page in your favourite webbrowser and then rightclick the page and choose View Source. You'll see that the generated Client ID's are prepended by the ID's of the UINamingContainer components (like h:form, h:dataTable and f:subView). If you don't specify an ID for each of them, you will get an autogenerated ID like j_id_xxxx. To ease the work, you need to specify an ID for them. E.g.

<h:form id="form">

Also see this blog article for more information and hints. This blog article may also be useful to learn more about the wall between Java/JSP/JSF and JavaScript.

Sign up to request clarification or add additional context in comments.

2 Comments

But for html elements like <table> or <td> the id in the generated html output is same as what I gave in my source code.
Then your problem lies somewhere else. Maybe you executed the JS too early (before the DOM tree is fully built up and loaded in memory). If you intent to execute the JS during page load, hook the window.onload or body's onload attribute.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.