<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>www.jugpadova.it: Tag JSF</title>
    <link>http://www.jugpadova.it/articles/tag/jsf</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Java User Group [Padova]</description>
    <item>
      <title>JSF and Facelets</title>
      <description>&lt;p&gt;One of the main issues with &lt;span class="caps"&gt;JSF&lt;/span&gt; is the plenty of use of custom tags in the view. If you don&amp;#8217;t want to use a visual instrument like Java Studio Creator, building a page could become a nightmare, especially if your graphic designer uses a huge amount of html components.&lt;/p&gt;


	&lt;p&gt;If you ever tried Tapestry you know that with that framework this is not a problem, when you have the html template you have only to put the proper attribute to dynamically rendered tags and it&amp;#8217;s all done.&lt;/p&gt;


	&lt;p&gt;Now also &lt;span class="caps"&gt;JSF&lt;/span&gt; allows you to do that: the project &lt;a href="https://facelets.dev.java.net/"&gt;facelets&lt;/a&gt; aims to have the same approach used when developing with Tapestry. With facelets you can use templating and write a plain html file as a view.&lt;/p&gt;
&lt;p&gt;Facelets is registered in the &lt;span class="caps"&gt;JSF&lt;/span&gt; framework as a &lt;tt&gt;ViewHandler&lt;/tt&gt;, so the only things you have to do to start using facelest are&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;em&gt;make &lt;span class="caps"&gt;JSF&lt;/span&gt; use facelets as ViewHandler&lt;/em&gt;: put those lines in the &lt;code&gt;faces-config.xml&lt;/code&gt;&lt;/li&gt;
	&lt;/ul&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;faces-config&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;application&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;view-handler&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;com.sun.facelets.FaceletViewHandler&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;view-handler&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;application&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;faces-config&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;ul&gt;
	&lt;li&gt;&lt;em&gt;import libraries&lt;/em&gt;: you have to put in your classpath the facelets implementation jar (jsf-facelets.jar) that you can find in the facelets&amp;#8217; site.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;em&gt;modify the &lt;span class="caps"&gt;DEFAULT&lt;/span&gt;_SUFFIX param&lt;/em&gt;: facelets pages are simple xhtml files. &lt;span class="caps"&gt;JSF&lt;/span&gt; by default uses jsp files as view, so you have to tell the framework that now the views are the xhtml files. To do this you simply modify your &lt;code&gt;web.xml&lt;/code&gt; in this way:&lt;/li&gt;
	&lt;/ul&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_xml "&gt;&lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;context-param&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param-name&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;javax.faces.DEFAULT_SUFFIX&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;param-name&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt;&lt;span class="tag"&gt;param-value&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;.xhtml&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;param-value&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="tag"&gt;context-param&lt;/span&gt;&lt;span class="punct"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;If you don&amp;#8217;t want to become crazy with html stuff (your graphic designer is paid enough for this, isn&amp;#8217;t it?) and you want to use &lt;span class="caps"&gt;JSF&lt;/span&gt;, try out facelets. If you want to learn more about facelets &lt;a href="http://www.jsfcentral.com/articles/facelets_1.html"&gt;here&lt;/a&gt; you can find an introductive article and &lt;a href="https://facelets.dev.java.net/nonav/docs/dev/docbook.html"&gt;here&lt;/a&gt;  you&amp;#8217;ve got the reference documentation.&lt;/p&gt;</description>
      <pubDate>Tue, 22 Nov 2005 11:42:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:10202317-a6f6-4cc3-a51d-2649b0972340</guid>
      <author>Andrea Nasato</author>
      <link>http://www.jugpadova.it/articles/2005/11/22/jsf-and-facelets</link>
      <category>Tips &amp; Tricks</category>
      <category>JSF</category>
      <category>Facelets</category>
    </item>
  </channel>
</rss>
