Jsf Best Practice: Custom Components And Javascript
I am developing a JSF Custom Component, using the information I found on the following book Pro JSF and HTML5 by Apress. So far, I successfully developed: the java class to obtai
Solution 1:
If you want your components to be reusable, I encourage you to pack everything in an independent jar. If using Servlet 3.0, you'll be able to easily access the web resources putting them in META-INF/resources. Provide the jar a faces-config.xml and you'll make it JSF annotation scannable:
components
\-(Your cource code)
META-INF
\-faces-config.xml
\-resources (This ends up in docroot)
\-resources
\-js (Here they go your js files)
\-comp (Here your composite components)
\-css (Here your css)
Later on, you'll have to take care of avoiding the specific ids in your composites, as JSF modifies them while rendering. Your best is to pass the current component reference to your JS functions:
<h:inputTextstyleClass="myInputStyle"onclick="showInputText(this)" />
Just refer to included CSS styles and JS functions.
Last but not least, be careful when including the jar as a web resource, if the file paths remain in conflict with the ones in your web app, they won't be included.
See also:
Post a Comment for "Jsf Best Practice: Custom Components And Javascript"