This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
I have a JSF page and want to launch a java script (calendar pick date popup) from it. The java script pass in the HTML input ID (inputText0) of the input field to populate (result from date pick).
But, I do not know the HTML input ID since JSF generate an ID (_id2:inputText0).
Here is the JSF code:
<h:form> <script type="text/javascript"> var calDFrom = new CalendarPopup("testdiv1"); calDFrom.showNavigationDropdowns(); </script>
Apologies if you've already considered this, but you may be making life difficult for yourself. Why not use one of the JSF Date Picker controls, such as Tomahawk InputDate/Input Calendar or RichFaces Calendar?
Two possible solutions that I can think of: 1. Declare the id's of the form and the component during compile time, i.e. assign an id for the form and component and embed the expected id in the js function.
Cons - Not scalable when you have multiple components using the same jsfunction
2. Implement a custom component that will dynamically embed the jsfunction during the render phase because you can get the formId and the componentId in the FacesContext instance
I hope this helps your problem.
Uy Jerwin Louise Vergara
Junior Developer / Research and Development at Incuventure Partners Corporation
email: jerwin.uy@incuventure.net
Henk Maritz
Greenhorn
Joined: Aug 03, 2008
Posts: 3
posted
0
Thanks for the response. I'll try the RichFaces first. It looks very good.
Henk Maritz
Greenhorn
Joined: Aug 03, 2008
Posts: 3
posted
0
I have assigned an unique ID to the h:form and use document.getElementById() in JS. It works well.
I have a similar requirement , can this requirement be achieved only with generic facets? could you please let me know how you have achieved this requirement?
Thanks a ton in advance.
~Siva(ji)
OCJP1.6, OCA 9i , IBM SOA Certified
Jerwin Louise Uy
Ranch Hand
Joined: Oct 27, 2007
Posts: 75
posted
0
I don't quite understand your question. ~_~
If you need to know the client id of a certain component during runtime, then I am afraid that feat is left to the NamingContainer of JSF.
Of course, you can tell the NamingContainer not to assign a unique identifier to your components if the id attribute has a value. Note that having two components reference the same id will cause your page not to function. (If I can remember, it will throw an error telling you that it found a Duplicate id in the UIViewRoot)
My another suggestion is to create your own custom component so that you can programatically get the client id at runtime as well as write the javascript function with your component. This way, you don't have to assign static id for each of your component.