Component Authoring
Component Authoring
101
If you’ve written any javascript code for a jsf page from a backing bean using icefaces you probably have loaded small portions of javascript code with the method javaScriptContext.addJavaScriptCall(). and this does indeed work if you have a small focused amount of javascript. But what if you had to include whole javascript libraries.
If you were writing a jsp tag, you might write a method that used a StringReader to read an external file of javascript into a byteArrayOutputStream and direct that to a servletoutputSteam.
Core Java Server Faces discusses a phaseListener that loads the javaScript necessary for the rico accordian custom control.
But what about icefaces. much of the external javascript used by icefaces comes from 2 js fies, icefaces-d2d.js and ice-extras.js these js files also contain prototype , scriptolous libraries and portions of the yahoo Js libraries , as well as javascript necessary for direct to dom rendering i.e.. icesubmitPartial in compressed format. Icesoft in the util package provides an utility to compress and uncompress the js, We haven’t seen a whole lot of difference between running the compressed and uncompressed version of ice-extras
iphoneHelper uses a method like the above. first of all we extend Javascript context.java as McvJavaScriptContext.java and add the following constant.
public static final String MCV_EXTRAS = "/xmlhttp" + StartupTime.getStartupInc() + "mcv-extras.js"
mcv-extra-js contains all the static custom javascript. Its important to stress only the static javascript is included here the dynamic portion will be constructed in the renderer.
Then in the constructor of the component we call the includeLib method which loads the javascript to the outputstream. (this is a slight oversimplification of the process , but essentially is correct)
public IphoneHelper() {
super();
McvJavascriptContext.includeLib(McvJavascriptContext.MCV_EXTRAS,
FacesContext.getCurrentInstance());
System.out.println("mcv context loaded");
}
Loading background javascript
6/2/08
Hint
If you need to make any modifications to ice-extras or icefaces-d2d.js you will have to uncompress the file. At least if you want to keep your sanity. As mentioned below icesoft does provide utilities for this, but there is an easier way if you are use Myeclipse , Aptana Studio or maybe regular Eclipse.
Just use the eclipse formatter, contol-shift F. It will take a short while but does a nice job of uncompressing the js. You will need to run the utility to re-compress it however.