Facelets

From Wiki RB4

Introduction[edit]

Facelets ist eine alternative View-Handler Technologie für den JSF Standard, das heißt es ersetzt Java Server Pages für die Definition der Views. Facelets setzt als Eingabe gültige XML-Dokumente voraus. Deshalb werden die Seiten im XHTML-Format erstellt.

Facelets compiles the XHTML (or XML) markup into it's own format called a Facelet. The Facelet acts as a set of instructions for building the JSF component tree. Facelets do not relate to JSP at all.

Ein wichtiges Merkmal von Facelets ist das sogenannte component-aliasing. Damit ist es möglich, statt der Tags für die UI-Komponenten normale HTML-Tags, wie zum Beispiel <input> zu nutzen. Die Verbindung zu der UI-Komponente wird über das alias-Attribut jsfc im Tag hergestellt. Die entsprechende Komponente wird beim Kompilieren der Seite durch Facelets eingefügt. Der Vorteil des component-aliasing ist, dass Webdesigner die Seite mit herkömmlichen HTML-Editoren bearbeiten können, da die normalen HTML-Tags benutzt werden. Die zusätzlichen Attribute werden ignoriert.

Facelets comes ready to use all of the UIComponents in the JavaServer Faces API under the same rules as you would with JSP. Facelets uses the new EL-API specification with JSF. This means that you can use either ${ } or #{ } interchangeably

Implementation[edit]

General Configuration[edit]

Facelets is implemented as a JSF ViewHandler, which can be easily configured in your application. Simply make sure the Facelets JAR jsf-facelets.jar is in your project's classpath and add a single modification to your faces-config.xml:

<faces-config>
  <application>
    <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
  </application>
</faces-config>

JavaServer Faces defaults to JSP files for defining views (*.jsp). You will want to change this to some other type in your web.xml.

<context-param>
  <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  <param-value>.xhtml</param-value>
</context-param>

Tags[edit]

<composition>[edit]

The content before and after the compositon tag will not be rendered. The defines will be replaced in the template via <insert> tags.

<composition template="<TEMPLATE_PATH_FILENAME>">
  [<DEFINES>]
</composition>

<define>[edit]

The content between the begin and end tag will replaces the corresponding insert tag in the template.

<define name="<NAME>">
  (<HTML>|<include>)*
</define>

<include>[edit]

<include src="PATH_FILENAME">
</include>

<insert>[edit]

<insert name="<NAME>">
</insert>