开发者

Primefaces sources jsf

I've downloaded primefaces sources to 开发者_高级运维see if I can learn from them. The jar contains a bunch of java classes that use writers to handle the rendering etc. I was expecting to find some .xhtml files with

<ui:composition> ... </ui:composition> and <cc:interface> etc etc

Anyway this got me thinking, is there another way to write facelets and composite components or they wrote everything in xhtml files then compiled them to java classes? Sorry if my question is absurd I am new to JSF.


Template files and composite components are just for enduser's convenience because it's easy to write and use them. The basic JSF implementation (the f: and h: components) and component libraries like PrimeFaces use fullworthy UI components. That are classes which extend JSF UIComponent class.

Development of UIComponent classes is relatively complex and clumsy. You've got to take a lot of things into account when developing them, such as writing tag files (you've to define every attribute in a XML file), configuration files (link component and renderer with each other), etc, but you end up with a more modular and reuseable model and better efficiency. They are even useable on plain old JSP files.

Facelets templates are unlike JSP files not compiled to Java classes. They're just loaded and executed by a SAX (XML) parser which is by itself already written in Java.


Update as per the comment: it will in general perform a tad better if there is relatively a lot of business/conditional logic involved which is in no way related to the view, such as a heap of <c:if>, <c:choose> etc tags based on non-user-controlled input.

The book JSF 2.0 The Complete Reference also covers custom UIComponent development in chapter 10 "Noncomposite components". The Java EE 5 tutorial covers it as well, but it's targeted on JSF 1.2. It's unfortunately not in Java EE 6 tutorial for JSF 2, although the technique has not changed, but there are several new annotations which you need to know about.


One more advice in case you want to patch around in the sources of primefaces2. It uses a org.primefaces.maven-jsf-plugin which generates many of the .java files. I once tried to patch one of them and I was surprised that the change always was lost after a mvn package

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜