Primefaces 来源 jsf
我已经下载了 primefaces 源代码,看看是否可以从中学习。该jar包含一堆java类,它们使用编写器来处理渲染等。我希望找到一些.xhtml文件,
<ui:composition> ... </ui:composition> and <cc:interface> etc etc
无论如何,这让我思考,是否有另一种方法来编写facelets和复合组件,或者他们在xhtml文件中编写所有内容然后将它们编译成java类?抱歉,如果我的问题很荒谬,我是 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
模板文件和复合组件只是为了方便最终用户,因为它们很容易编写和使用。基本的 JSF 实现(
f:
和h:
组件)和组件库,如 PrimeFaces 使用完整的 UI 组件。这些类扩展了 JSFUIComponent
类。
UIComponent
类的开发相对复杂且笨拙。开发它们时,您必须考虑很多事情,例如编写标记文件(您必须在 XML 文件中定义每个属性)、配置文件(将组件和渲染器相互链接)等,但是您最终会得到一个更加模块化和可重用的模型以及更高的效率。它们甚至可以在普通的旧 JSP 文件上使用。Facelets 模板与未编译为 Java 类的 JSP 文件不同。它们只是由 SAX (XML) 解析器加载并执行,该解析器本身已经用 Java 编写。
根据评论更新:如果涉及相对较多的业务/条件逻辑(与视图没有任何关系,例如一堆、
等基于非用户控制输入的标签。JSF 2.0 完整参考一书还涵盖了 第 10 章 "非复合组件”。 Java EE 5 教程也涵盖了,但它是针对 JSF 1.2。不幸的是,它不在 JSF 2 的 Java EE 6 教程 中,尽管该技术没有改变,但是有几个新的注释你需要了解。
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:
andh:
components) and component libraries like PrimeFaces use fullworthy UI components. That are classes which extend JSFUIComponent
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.
如果您想修补 primefaces2 的源代码,还有一个建议。它使用 org.primefaces.maven-jsf-plugin 生成许多 .java 文件。我曾经尝试修补其中一个,但令我惊讶的是,在
mvn package
之后更改总是丢失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 amvn package