Can`t add javascript
zgood Apr 2, 2010 2:59 AMHello.
I am trying to add javascript to portlet GateIn 3.0.0-GA accroding to javascript configuration section in reference-guide.
Here is portlet
war structure:
{quote}./WEB-INF/lib/commons-collections-3.2.1.jar
./WEB-INF/lib/portletbridge-api-2.0.0.CR1.jar
./WEB-INF/lib/portletbridge-impl-2.0.0.CR1.jar
./WEB-INF/web.xml
./WEB-INF/portlet.xml
./WEB-INF/faces-config.xml
./WEB-INF/classes/com/icl/cs/z22/jsf/Clock.class
./WEB-INF/classes/com/icl/cs/z22/jsf/ClockController.class
./WEB-INF/conf/script/groovy/JavascriptScript.groovy
./jsf/clock.jsp
./javascript/clock.js
./META-INF
./META-INF/MANIFEST.MF{quote}
WEB-INF/conf/script/groovy/JavascriptScript.groovy contains single line:
{code}JavascriptService.addJavascript("com.icl.cs.z22.clock", "/javascript/clock.js", ServletContext);{code}
Here is ./javascript/clock.js file content:
{code}function startClock(elementId, year, month, date, hours, minutes, seconds) {
oDate = new Date(year, month, date, hours, minutes, seconds);
window.setInterval(function () {
clockStep(elementId, oDate);
}
,1000);
}
function clockStep(elementId, theTime) {
var nmins = theTime.getMinutes();
var nhours = theTime.getHours();
var nsec = theTime.getSeconds();
var nmonth = theTime.getMonth();
var ntoday = theTime.getDate();
var nyear = theTime.getFullYear();
var ssec = nsec;
nmonth = nmonth + 1;
if (ntoday < 10) {
ntoday = "0" + ntoday;
}
if (nmonth < 10) {
nmonth = "0" + nmonth;
}
if (nhours < 10) {
nhours = "0" + nhours;
}
if (nmins<10) {
nmins = "0" + nmins;
}
if (nsec < 10) {
ssec = "0" + ssec;
}
document.getElementById(elementId).value = ntoday + "." + nmonth + "." + nyear + " " + nhours + ":" + nmins + ":" + ssec;
theTime.setSeconds(nsec + 1);
}{code}
And in .jsf/clock.jsp I invoke js function:
{code}<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:view>
<script>
startClock("clock-area", ${clock.date.year + 1900},
${clock.date.month},
${clock.date.date},
${clock.date.hours},
${clock.date.minutes},
${clock.date.seconds});
</script>
<div>
<input id="clock-area">
</div>
<br/>
</f:view>{code}
After running this portlet clock doesn`t starts. And I don`t see clock.js in firebug and html source.