Search This Blog

Friday, July 16, 2010

Add Javascript to Ice Faces or Facelets

There are several ways to add JavaScript code to an ice faces page. One of which is explained here.The "Direct to Dom" (akaD2D) rendering of icefaces makes it difficult to add javascript or any other code to it.

Q. Where to add the code? .
Ans. The answer is to put the < script type="text/javascript"> just code after the < ice:root> between < html> < head> .add the javascript in the similar way as you add it in jsp/html. then close the tag and at the end before closing the root (i.e < /ice:root> ) add the < /html> tag.

Q. How to call an icefaces componet?
Ans. Use the formname:componentid format to use it in the javascript function.

Q. How to use the body onload thing without using body tag.
Ans. The answer lies in using the window event.

Here is an example which makes everything clear


< jsp:root version="2.0" f="http://java.sun.com/jsf/core" h="http://java.sun.com/jsf/html" ice="http://www.icesoft.com/icefaces/component" jsp="http://java.sun.com/JSP/Page">
< f:view>
< script type="text/javascript>
function setFocusOnLogin(){ document.getElementById("icefaces_formaname:icefaces_component_id").focus(); }//its used to call the icefaces component's focus event
window.attachEvent("onload", setFocusOnLogin);//like body onload , its called on page load < /script>
< ice:portlet>
< ice:form id="icefaces_formaname">
< ice:inputtext id="icefaces_component_id" size="10">
< /ice:inputtext>
< /ice:form>
< /ice:portlet>
< /f:view>
< /jsp:root>

Hope you get it. For any concerns feel free to post a comment.

My Blog List