JavaScript in Facelets/XHTML
XHTML is more uniformed then regular html so here are few ways to add javascript code in a xhtml file
No. 1: Regular old style with special wrap (CDATA). Here is template.xhtml

No.2: External .js file
Create a .js file, like external.js
function externalJs(){
alert('external js file');
}
Now, add this <script type=”text/javascript” src=”external.js”></script> in the template.xhtml
Both of these java script call should work, one will come from template.xhmtl and other one will come from External JS file.
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:ice="http://www.icesoft.com/icefaces/component"> <ui:composition template="layout.xhtml"> <ui:define name="content"> <ice:form style="width: 45%;"> <a href="javascript: clicked();">JS in template.xhtml</a> <a href="javascript: externalJs();">External JS</a> </ice:form> </ui:define> </ui:composition> </f:view>
Related topics:
Five Steps to add Facelets
1 Comment »
Leave a comment
-
Archives
- November 2009 (1)
- July 2009 (1)
- June 2009 (5)
- May 2009 (2)
- April 2009 (4)
- March 2009 (2)
- January 2009 (3)
- December 2008 (1)
- November 2008 (2)
- October 2008 (1)
- September 2008 (3)
- August 2008 (2)
-
Categories
-
RSS
Entries RSS
Comments RSS
Maybe a noob question, but how come your IDE does not complaint when you put attribute xmlns as attribute inside f:view tag (in the line 01 of template.xhmtl)? As far a I know, f:view does not have this attribute…