<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaBeat &#187; Java Server Faces (JSF)</title>
	<atom:link href="http://www.javabeat.net/category/web-frameworks/java-server-faces-jsf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Tue, 21 May 2013 13:43:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How to create bounded taskflows in ADF using JDeveloper?</title>
		<link>http://www.javabeat.net/2012/11/how-to-create-bounded-taskflows-in-adf-using-jdeveloper/</link>
		<comments>http://www.javabeat.net/2012/11/how-to-create-bounded-taskflows-in-adf-using-jdeveloper/#comments</comments>
		<pubDate>Wed, 07 Nov 2012 04:19:49 +0000</pubDate>
		<dc:creator>Mohamed Sanaulla</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>
		<category><![CDATA[Web Frameworks]]></category>
		<category><![CDATA[Java Server Faces]]></category>
		<category><![CDATA[Oracle ADF]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=4929</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Taskflows are a very useful feature in Oracle ADF which provide a modular approach for defining control flow in an application. It allows to create application flow graphs which can be tied together to build the complete application. So instead of considering an application as a collection of different JSF pages, in ADF we would [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p><strong>Taskflows</strong> are a very useful feature in <a href="http://www.oracle.com/technetwork/developer-tools/adf/overview/index.html" target="_blank">Oracle ADF</a> which provide a modular approach for defining control flow in an application. It allows to create application flow graphs which can be tied together to build the complete application. So instead of considering an application as a collection of different <strong>JSF</strong> pages, in <strong>ADF</strong> we would consider an application as a collection of different <strong>taskflows</strong>.</p>
<p><strong>ADF Taskflows</strong> come in two forms:</p>
<ul>
<li>Bounded Taskflow</li>
<li>Unbounded Taskflow</li>
</ul>
<p><strong>Unbounded Taskflow:</strong> A set of activities (<strong>JSF</strong> Pages/views), control flow rules, and managed beans that interact to allow a user to complete a task. An ADF unbounded task flow consists of all activities and control flows in an application that are not included within any bounded task flow.</p>
<ul>
<li><a href="http://www.flipkart.com/oracle-fusion-developer-guide-0070701938/p/itmczyz77pqunzsh?pid=9780070701939&amp;affid=suthukrish" target="_blank"><strong>Building Rich Internet Applications with Oracle ADF Business Components &amp; ADF Faces</strong></a> (<a href="http://astore.amazon.com/javabeat-20/detail/0071622543" target="_blank">Amazon.com</a>)</li>
</ul>
<p><strong>Bounded Taskflow:</strong> A specialized form of task flow that, in contrast to an unbounded task flow, has a single entry point and zero or more exit points. It contains its own set of private control flow rules, activities, and managed beans.</p>
<p>A bounded taskflow:</p>
<ul>
<li>has single entry point.</li>
<li>zero or more exit points.</li>
<li>may accept input parameters.</li>
<li>may generate return value.</li>
<li>has its own memory scope called pageflow scope.</li>
</ul>
<p>The memory scope of a bounded taskflow called pageflow scope allows the developer to declare java bean classes in that scope making it available/accessible across all the JSF pages within the taskflow.</p>
<p>In this article we will look at how to create ADF bounded taskflow using JDeveloper. I am using JDeveloper Studio Edition Version 11.1.2.1.0 for this article.</p>
<h3>Creating a new ADF Web Application</h3>
<p>:<br />
From the Application Navigator click on <strong>New Application</strong> and you should see this popup:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/NewADFApp.jpg"><img class="aligncenter size-medium wp-image-4932" src="http://www.javabeat.net/wp-content/uploads/2012/11/NewADFApp-300x214.jpg" alt="" width="300" height="214" /></a></p>
<p>Select <strong>Fusion Web Application(ADF)</strong> and click on Ok to get the next popup:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/NewADFApp_Name.jpg"><img class="aligncenter size-medium wp-image-4933" src="http://www.javabeat.net/wp-content/uploads/2012/11/NewADFApp_Name-300x225.jpg" alt="" width="300" height="225" /></a><br />
Enter the Application name as <strong>BoundedTaskFlowCreation</strong> and then click on <strong>Finish</strong> button to create a new application. Once you have created a new application you would get this view:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/NewADFApp_Done.jpg"><img class="aligncenter size-medium wp-image-4935" src="http://www.javabeat.net/wp-content/uploads/2012/11/NewADFApp_Done-300x171.jpg" alt="" width="300" height="171" /></a><br />
With this you have your new ADF application setup. You would see 2 projects: Model and ViewController (assuming you didn&#8217;t change the defaults apart from adding new application name while creating the new application). The Model project contains all the code which deals with ADF Data binding layer called- ADFBC and ViewController project contains all the view related code like the JSF pages, the java classes which act as managed beans for those JSF pages.</p>
<h3>Creating a new bounded taskflow</h3>
<p>Right click on the ViewController project and click on New:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/NewBT_Prestart.jpg"><img class="aligncenter size-full wp-image-4937" src="http://www.javabeat.net/wp-content/uploads/2012/11/NewBT_Prestart.jpg" alt="" width="326" height="411" /></a><br />
In the new window select JSF/Facelets from the Web Tier categories in the right and then select <strong>ADF Taskflow</strong> from the right and click on <strong>Ok</strong> as shown below:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/NewBT_Start.jpg"><img class="aligncenter size-medium wp-image-4938" src="http://www.javabeat.net/wp-content/uploads/2012/11/NewBT_Start-300x202.jpg" alt="" width="300" height="202" /></a></p>
<p>In the <strong>Create Taskflow</strong> window enter the <strong>File Name</strong> which would be the name of the bounded taskflow, let the Directory be default, check the <strong>Create as Bounded Taskflow</strong> check box and <strong>uncheck</strong> the <strong>Create with Page Fragments</strong> checkbox. After you have entered the details, your screen would be more or less like:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/NewBT_First.jpg"><img class="aligncenter size-medium wp-image-4940" src="http://www.javabeat.net/wp-content/uploads/2012/11/NewBT_First-300x206.jpg" alt="" width="300" height="206" /></a><br />
A bounded taskflow is represented by an XML config file which contains the views/pages part of the taskflow, the control flow structure i.e navigation from one page/view to another which can also include conditional flows, any java bean classes which are referenced by the views/pages within the taskflow which are called as Managed beans. And creating a bounded taskflow with pagefragements will not allow it to be launched independently and hence I am creating a bounded taskflow without page fragments. A bounded taskflow with page fragments would allow us to create only JSFF files i.e JSF fragment files.</p>
<p>Once you have clicked on <strong>Ok</strong>, you will be shown the Bounded Taskflow Diagrammatic view as shown below:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/NewBT_Done.jpg"><img class="aligncenter size-medium wp-image-4941" src="http://www.javabeat.net/wp-content/uploads/2012/11/NewBT_Done-300x177.jpg" alt="" width="300" height="177" /></a></p>
<p>Generally lot of the work with taskflows can be easily done using the diagrammatic view. Most of us should be familiar with the GUI builders which are used for creating Swing applications or Flex applications. When we drag and drop components on the taksflow diagram, there is code generated in the XML which corresponds to the components added. You should be able to see the <strong>component palette</strong> on the right hand side and the <strong>Properties Inspector</strong> window at the bottom (the screenshot shown above shows the two windows). If you are not able to see these windows, you can always add them from the <strong>View</strong> menu.</p>
<p>In the component palette you can see a plethora of components which can be added to the taskflow. Search for <strong>View</strong> and then drag drop the <strong>View(ADF Task Flow.Components)</strong> on to the taskflow area. And then enter the name of the view as: firstPage. You should now see a view component in the taskflow as shown below:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/BT_1.jpg"><img class="aligncenter size-medium wp-image-4942" src="http://www.javabeat.net/wp-content/uploads/2012/11/BT_1-300x171.jpg" alt="" width="300" height="171" /></a></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>Note that after adding the View component no JSF/JSP page has been created. To create a JSF page for that view double click on the view component to get the following popup:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/BT_2.jpg"><img class="aligncenter size-medium wp-image-4943" src="http://www.javabeat.net/wp-content/uploads/2012/11/BT_2-300x276.jpg" alt="" width="300" height="276" /></a><br />
You can select/choose from the Layouts or just select the Blank option to create a new JSF page. In the same way described above add another view: secondPage.<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/BT_After2View.jpg"><img class="aligncenter size-medium wp-image-4944" src="http://www.javabeat.net/wp-content/uploads/2012/11/BT_After2View-300x171.jpg" alt="" width="300" height="171" /></a><br />
One can see a light green shade around firstPage component. This indicates that the default activity for the bounded taskflow is firstPage. One can change the default activity by selecting the bounded taskflow and changing the <strong>Default Activity</strong> property from the <strong>Property Inspector</strong> window.</p>
<p>Now I want to navigate from firstPage to secondPage drag and drop the <strong>Control Flow case</strong> by dragging from firstPage to secondPage and name that navigation as <strong>gotoSecond</strong>. The taskflow diagram would be as shown below:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/BT_AfterControlFlow.jpg"><img class="aligncenter size-medium wp-image-4948" src="http://www.javabeat.net/wp-content/uploads/2012/11/BT_AfterControlFlow-300x177.jpg" alt="" width="300" height="177" /></a></p>
<p>And after all this lets have a look at the XML for the first-bounded-task-flow.xml:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;windows-1252&quot; ?&gt;
&lt;adfc-config xmlns=&quot;http://xmlns.oracle.com/adf/controller&quot; version=&quot;1.2&quot;&gt;
  &lt;task-flow-definition id=&quot;first-bounded-task-flow&quot;&gt;
    &lt;default-activity&gt;firstPage&lt;/default-activity&gt;
    &lt;view id=&quot;firstPage&quot;&gt;
      &lt;page&gt;/firstPage.jsf&lt;/page&gt;
    &lt;/view&gt;
    &lt;view id=&quot;secondPage&quot;&gt;
      &lt;page&gt;/secondPage.jsf&lt;/page&gt;
    &lt;/view&gt;
    &lt;control-flow-rule id=&quot;__1&quot;&gt;
      &lt;from-activity-id&gt;firstPage&lt;/from-activity-id&gt;
      &lt;control-flow-case id=&quot;__2&quot;&gt;
        &lt;from-outcome&gt;gotoSecond&lt;/from-outcome&gt;
        &lt;to-activity-id&gt;secondPage&lt;/to-activity-id&gt;
      &lt;/control-flow-case&gt;
    &lt;/control-flow-rule&gt;
  &lt;/task-flow-definition&gt;
&lt;/adfc-config&gt;
</pre>
<p>Now double click on firstPage view to get the firstPage.jsf and switch to the <strong>Source</strong> view. Now add the following code to the firstPage.jsf between the af:form tag:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;af:outputText value=&quot;This is first page&quot; id=&quot;ot1&quot;/&gt;
&lt;af:commandButton text=&quot;Goto Second Page&quot; id=&quot;cb1&quot; action=&quot;gotoSecond&quot;/&gt;
</pre>
<p>The above code shows- an output text to show some text and a button to navigate to the next page. The action attribute above is assigned the name of the control flowcase created above.</p>
<p>Now go back to the first-bounded-task-flow and double click on the secondPage view to get secondPage.jsf. In the secondPage.jsf add the following code between af:form tag:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;af:outputText value=&quot;This is second page&quot; id=&quot;ot1&quot;/&gt;
</pre>
<p>Now you have a bounded taskflow and go to the bounded taskflow and right click and then click on Run for the application to be deployed. It will run an Integrated Web Logic server and deploy the application to it.<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/BT_Run.jpg"><img class="aligncenter size-medium wp-image-4950" src="http://www.javabeat.net/wp-content/uploads/2012/11/BT_Run-173x300.jpg" alt="" width="173" height="300" /></a></p>
<p>Once the application runs- you will get a page which shows:<br />
<a href="http://www.javabeat.net/wp-content/uploads/2012/11/firstPage.jpg"><img class="aligncenter size-full wp-image-4951" src="http://www.javabeat.net/wp-content/uploads/2012/11/firstPage.jpg" alt="" width="211" height="38" /></a><br />
Now clicking on the button would take you to the next page.</p>
<p>I have <a href="http://www.javabeat.net/wp-content/uploads/2012/11/BoundedTaskFlowCreation.zip">uploaded the project</a> for anyone who wants to look into the project.</p>
<p><strong>JSF Books:</strong></p>
<ul>
<li><a href="http://www.flipkart.com/java-server-faces-action-8177224190/p/itmdyufmtyhxpn5p?pid=9788177224191&amp;affid=suthukrish" target="_blank">Java Server Faces in Action</a> (<a href="http://astore.amazon.com/javabeat-20/detail/1932394125" target="_blank">Amazon.com</a>)</li>
<li><a href="http://www.flipkart.com/mastering-java-server-faces-8126505311/p/itmdytmgadkvfgce?pid=9788126505319&amp;affid=suthukrish" target="_blank">Mastering Java Server Faces (JSF)</a></li>
<li><a href="http://www.flipkart.com/core-javaserver-faces-8131761924/p/itmczyqfsafyyf9e?pid=9788131761922&amp;affid=TrackingID" target="_blank">Core Java Server Faces (JSF)</a> (<a href="http://astore.amazon.com/javabeat-20/detail/0131738860" target="_blank">Amazon.com</a>)</li>
</ul>
<p><strong> If you are interested in receiving the future java articles and tips from us, please</strong> <a href="http://www.javabeat.net/subscribe/">subscribe here</a>.</p>
<p><strong><span style="color: #000080;">If you have any doubts on ADF or Java Server faces (JSF), please post it in the comments section.</span> </strong></p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fcategory%2Fweb-frameworks%2Fjava-server-faces-jsf%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/category/web-frameworks/java-server-faces-jsf/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/category/web-frameworks/java-server-faces-jsf/feed/" data-count="vertical" data-text="Java Server Faces (JSF)" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2012/11/how-to-create-bounded-taskflows-in-adf-using-jdeveloper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internationalization in JSF 1.x</title>
		<link>http://www.javabeat.net/2011/04/internationalization-in-jsf-1-x/</link>
		<comments>http://www.javabeat.net/2011/04/internationalization-in-jsf-1-x/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 00:02:44 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=659</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Internationalization &#38; Localization Introduction In the current arena of Globalization, the user base of a web application has been extensively increasing day by day. With this huge increase in the user base, it is very essential that the applications are very well understood and interpreted by people of different cultures and different languages. It is [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h1 style="text-align: center;">Internationalization &amp; Localization</h1>
<h2>Introduction</h2>
<p>In the current arena of Globalization, the user base of a web application has been extensively increasing day by day. With this huge increase in the user base, it is very essential that the applications are very well understood and interpreted by people of different cultures and different languages. It is then, the whole concept of <strong><em>Internationalization</em></strong> becomes very vital for a web application.</p>
<h2>What is Internationalization?</h2>
<p><strong><em>Internationalization</em></strong> is a process of preparing a web application content compatible to a user/region’s preferred language and country. For example, an application with Japanese content will be better understood by Japanese people rather than people who do not understand Japanese. In other words, Internationalization makes it possible for a web application to support more than one language.Internationalization is also referred to as I18N.</p>
<p>The need for <strong><em>Internationalization</em></strong> is, in the current global scenario like developing a website or an application, there will be multiple service requests from multiple countries. So, we cannot use a common language and format to cater all these varied requests.<br />
Usually internationalization will be done for label text for UI components, messages and other static strings displayed on the page. The format of display of date, currency etc can be internationalized to suit a particular locale.</p>
<p><strong><em>Localization</em></strong> is a process of adapting an internationalized application to support specific region or a locale. Locale is a representation of language and country combination. Typically a locale is represented as: &lt;language code&gt;_&lt;country code&gt;</p>
<p>Although, Internationalization and Localization of applications plays a very important role in the scenario of web applications it can be extended to any of the Client user interfaces.</p>
<h2>Internationalization using JSF</h2>
<p>JSF provides a support to achieve Internationalization and Localization. In JSF for supporting more than one language, we need to provide all required locale specific messages in a .properties file. These locale based .properties files are called Resource Bundle in JSF. The locale specific resource bundles are supposed to have a naming convention as follows:<strong><em>Filename_language_country.properties</em></strong></p>
<p>Usually, when a request is sent the preferred language is taken from the request header and it is used to select the most nearest matching resource bundle. For example, if a request has ‘ja-JP’ as the preferred locale, and then JSF will try to find a resource bundle having _ja_JP in its name as per the above naming convention. If resource bundle with _ja_JP is not found, then it will try to select a resource bundle with _ja. If this bundle is also not available then it selects the default locale mentioned for the web application.</p>
<h2>Steps for implementing Internationalization in JSF</h2>
<p>Implementing I18N in JSF requires some simple steps which are as follows:</p>
<ul>
<li>Create locale specific resource bundles (.properties file) with proper naming convention and place it inside the src folder.</li>
<li>Register the resource bundles created in <strong>faces-config.xml</strong> using <strong>&lt;message-bundle&gt;</strong>or using<strong>&lt;f:loadBundle &gt;</strong></li>
</ul>
<p>Eg: Using <strong>&lt;f:loadBundle&gt;</strong> in each view</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;f:loadBundle   var=&quot;msg&quot;     basename=&quot;ApplicationResource&quot;/&gt;</pre></td></tr></table></div>

<p>Using faces-config.xml for entire application</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;application&gt;
    	&lt;resource-bundle&gt;
		&lt;base-name&gt;ApplicationResource&lt;/base-name&gt;
    		&lt;var&gt;msg&lt;/var&gt;
   	 &lt;/resource-bundle&gt;
    	 &lt;locale-config&gt;
      		&lt;default-locale&gt;en_US&lt;/default-locale&gt;
      		&lt;supported-locale&gt; ja_JP &lt;/supported-locale&gt;
    	 &lt;/locale-config&gt;
  &lt;/application&gt;</pre></td></tr></table></div>

<h3>Configure I18N support in the required JSF views</h3>
<p>The JSF view should be configured to support the Internationalization. The loadBundle of the JSF core library should be defined, as follows.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;f:loadBundle basename=&quot;ApplicationResource&quot; var=&quot;mapValue&quot; /&gt;</pre></td></tr></table></div>

<p>Here, ‘basename’ is the name of the filename of the resource bundle, without the language and country code. ‘var’ is the identifier (a request scoped variable) that is to be used for fetching values from the selected bundle.</p>
<p>A resource bundle contains key value pairs for all the required messages. The key will be used (with the identifier mentioned by ‘var’ of) to fetch the corresponding values.</p>
<p>A simple implementation of I18N in a web application is shown below.</p>
<h4>Step 1: Create all the required resource bundle files</h4>
<p>The resource bundle for English (default locale) and Japanese (supported local) having file name ApplicationResource.properties and ApplicationResource_ja_JP.properties respectively are shown below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="language" style="font-family:monospace;"># Resource bundle for English
username= Username
password= Password
&nbsp;
&nbsp;
# Resource bundle for Japanese
&nbsp;
username= Shougou
password= aikotoba</pre></td></tr></table></div>

<p>Shougou and aikotoba are the Japanese word for Username and password respectively.The unicode to view the japanese script is as follows.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">username= \u610F\u5473
password= \u89E3\u6790</pre></td></tr></table></div>

<h4>Step 2: Usage of resource bundles in the different views in the JSF application</h4>
<p>To use the resource bundle in the view, we use the load bundle tag as shown in the Login.jsp page as shown below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@page contentType=&quot;text/html&quot; pageEncoding=&quot;UTF-8&quot;%&gt;
&lt;%@taglib prefix=&quot;f&quot; uri=&quot;http://java.sun.com/jsf/core&quot;%&gt;
&lt;%@taglib prefix=&quot;h&quot; uri=&quot;http://java.sun.com/jsf/html&quot;%&gt;
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
   &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
 &lt;title&gt;Login JSP&lt;/title&gt;&lt;/head&gt;
    &lt;f:view&gt;
&lt;f:loadBundle basename=&quot;ApplicationResource&quot; var=&quot;localeValue&quot; /&gt;
    &lt;body&gt;
      &lt;h:outputText value=&quot;#{localeValue.username}&quot; /&gt;&lt;h:inputText value=”#{login.username}” /&gt;
      &lt;h:outputText value=&quot;#{localeValue.password}&quot;/&gt; &lt;h:inputText value=”#{login.password}” /&gt;
&lt;/body&gt;&lt;/f:view&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<h4>Step 3: Configuring it in the faces-config.xml</h4>
<p>If we want to internationalize the entire web application we can also load the respective resource bundle files in the faces-config.xml, configuration file. The resource bundle is mapped in faces-config.xml as shown below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;application&gt;
        &lt;locale-config&gt;
               &lt;default-locale&gt;en&lt;/default-locale&gt;
               &lt;supported-locale&gt;ja&lt;/supported-locale&gt;
       &lt;/locale-config&gt;
               &lt;message-bundle&gt;ApplicationResource&lt;/message-bundle&gt;
         &lt;/application&gt;</pre></td></tr></table></div>

<h4>Step 4:Output of the Application</h4>
<p><a href="http://www.javabeat.net/wp-content/uploads/2011/04/1.png"><img class="aligncenter size-full wp-image-1203" title="1" src="http://www.javabeat.net/wp-content/uploads/2011/04/1.png" alt="" width="290" height="148" /></a></p>
<p><center></center><center><span style="color: red;">In English</span></center><center><a href="http://www.javabeat.net/wp-content/uploads/2011/04/2.png"><img class="aligncenter size-full wp-image-1201" title="2" src="http://www.javabeat.net/wp-content/uploads/2011/04/2.png" alt="" width="264" height="148" /></a></center><center></center><center><span style="color: red;">In Japanese</span></center></p>
<h2>Conclusion:</h2>
<p>In this article, I have explained the importance of Internationalization and Localization of web applications. Also I have discussed about making a JSF web application support for different locales with the help of code snippet.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2011/04/internationalization-in-jsf-1-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Spring Web Flow with JSF</title>
		<link>http://www.javabeat.net/2010/11/integrating-spring-web-flow-with-jsf/</link>
		<comments>http://www.javabeat.net/2010/11/integrating-spring-web-flow-with-jsf/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 01:23:50 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Spring Web Flow]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=520</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Introduction Spring Web Flow is a framework that provides abilities to developers to capture the workflow of a web application in the form of configurational constructs called Flows. JSF is a UI framework that provides support for developing complex user interface components along with simplified page navigation rules and event handling. In this article we [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Introduction</h2>
<p align="justify">Spring Web Flow is a framework that provides abilities to developers to capture the workflow of a web application in the form of configurational constructs called Flows. JSF is a UI framework that provides support for developing complex user interface components along with simplified page navigation rules and event handling. In this article we will discuss about the integration techniques between Spring Web Flow and JSF with the assumption that the readers have a good understanding of these two technologies.</p>
<h2>Download Source Code</h2>
<ul>
<li><a href="http://www.javabeat.net/articles/sourcecode/2010/201011-spring-web-flow-with-jsf.zip">Spring Web Flow and JSF Sample Code</a></li>
</ul>
<p><em>If you are not familiar with <strong>Java Server Faces</strong>, first read our list of articles on <a href="http://www.javabeat.net/articles/jsf/1/">Java Server Faces (JSF)</a> including <a href="http://www.javabeat.net/articles/11-introduction-to-java-server-faces-1.html">Introduction to Java Server Faces</a> by <a href="http://www.javabeat.net/authors/Raja/">Raja</a></em>. We have also listed some of the popular <a href="http://astore.amazon.com/javabeat-20?_encoding=UTF8&amp;node=12">JSF Books</a> in our <a href="http://astore.amazon.com/javabeat-20">Java Book Store</a>.</p>
<h2>Test application</h2>
<p align="justify">In this section, we will see the basic artifacts necessary for integrating Spring Web flow with JSF by developing a simple application. Because the idea is to illustrate the integration between Spring Web Flow and JSF, the application does nothing other than displaying a simple JSF invoked from Spring Web Flow. In the later sections of the article, we will see how to use services that makes use of database.</p>
<h3>Web application deployment descriptor</h3>
<p align="justify">We will start with defining the deployment descriptor of the application which is given below. Note that the following code snippet contains declarations specific to Spring Web Flow as well as JSF.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;web-app xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;
	version=&quot;2.4&quot;&gt;
&nbsp;
	&lt;context-param&gt;
		&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
		&lt;param-value&gt;
			/WEB-INF/config/spring-fc-config.xml
		&lt;/param-value&gt;
	&lt;/context-param&gt;
&nbsp;
	&lt;context-param&gt;
		&lt;param-name&gt;javax.faces.DEFAULT_SUFFIX&lt;/param-name&gt;
		&lt;param-value&gt;.xhtml&lt;/param-value&gt;
	&lt;/context-param&gt;
&nbsp;
  	&lt;context-param&gt;
        &lt;param-name&gt;facelets.DEVELOPMENT&lt;/param-name&gt;
   		&lt;param-value&gt;true&lt;/param-value&gt;
  	&lt;/context-param&gt;
&nbsp;
  	&lt;context-param&gt;
  		&lt;param-name&gt;facelets.REFRESH_PERIOD&lt;/param-name&gt;
  		&lt;param-value&gt;1&lt;/param-value&gt;
  	&lt;/context-param&gt;
&nbsp;
    &lt;filter&gt;
        &lt;filter-name&gt;charEncodingFilter&lt;/filter-name&gt;
        &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;encoding&lt;/param-name&gt;
            &lt;param-value&gt;UTF-8&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;init-param&gt;
            &lt;param-name&gt;forceEncoding&lt;/param-name&gt;
            &lt;param-value&gt;true&lt;/param-value&gt;
        &lt;/init-param&gt;
    &lt;/filter&gt;
&nbsp;
    &lt;filter-mapping&gt;
        &lt;filter-name&gt;charEncodingFilter&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
&nbsp;
	&lt;listener&gt;
		&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
	&lt;/listener&gt;
&nbsp;
	&lt;servlet&gt;
		&lt;servlet-name&gt;Resources Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.springframework.js.resource.ResourceServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;0&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
&nbsp;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Resources Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/resources/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&nbsp;
	&lt;servlet&gt;
		&lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
		&lt;init-param&gt;
			&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
			&lt;param-value&gt;&lt;/param-value&gt;
		&lt;/init-param&gt;
		&lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
&nbsp;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Spring MVC Dispatcher Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/spring/*&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&nbsp;
	&lt;servlet&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
&nbsp;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;*.faces&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&nbsp;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;
&nbsp;
&lt;/web-app&gt;</pre></td></tr></table></div>

<p align="justify">The mapping for all the faces requests are handled by the Faces Servlet and the context path containing &#8216;spring&#8217; is handled by Spring&#8217;s Dispatcher Servlet. A listener is configured which will load the application context which is found in the path &#8216;/WEB-INF/config/spring-fc.xml&#8217;.</p>
<h3>Spring&#8217;s Configuration file</h3>
<p align="justify">The content of Spring&#8217;s configuration file is given below. Note that this file contains a mixture of definitions related to Spring Web Flow and Spring MVC although it is possible to segregate them.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
       xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
       xmlns:webflow=&quot;http://www.springframework.org/schema/webflow-config&quot;
       xmlns:faces=&quot;http://www.springframework.org/schema/faces&quot;
       xsi:schemaLocation=&quot;
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/webflow-config
           http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd
           http://www.springframework.org/schema/faces
           http://www.springframework.org/schema/faces/spring-faces-2.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd&quot;&gt;
&nbsp;
	&lt;webflow:flow-executor id=&quot;flowExecutor&quot;&gt;
	&lt;/webflow:flow-executor&gt;
&nbsp;
	&lt;webflow:flow-registry id=&quot;flowRegistry&quot; flow-builder-services=&quot;facesFlowBuilderServices&quot;&gt;
		&lt;webflow:flow-location path=&quot;/WEB-INF/flows/test.xml&quot; /&gt;
	&lt;/webflow:flow-registry&gt;
&nbsp;
	&lt;faces:flow-builder-services id=&quot;facesFlowBuilderServices&quot; /&gt;
&nbsp;
	&lt;bean class=&quot;org.springframework.web.servlet.handler.SimpleUrlHandlerMapping&quot;&gt;
		&lt;property name=&quot;mappings&quot;&gt;
			&lt;value&gt;
				/test=flowController
			&lt;/value&gt;
		&lt;/property&gt;
		&lt;property name=&quot;defaultHandler&quot;&gt;
			&lt;bean class=&quot;org.springframework.web.servlet.mvc.UrlFilenameViewController&quot; /&gt;
		&lt;/property&gt;
	&lt;/bean&gt;
&nbsp;
	&lt;bean id=&quot;flowController&quot; class=&quot;org.springframework.webflow.mvc.servlet.FlowController&quot;&gt;
		&lt;property name=&quot;flowExecutor&quot; ref=&quot;flowExecutor&quot;/&gt;
	&lt;/bean&gt;
&nbsp;
	&lt;bean id=&quot;faceletsViewResolver&quot; class=&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;&gt;
		&lt;property name=&quot;viewClass&quot; value=&quot;org.springframework.faces.mvc.JsfView&quot;/&gt;
		&lt;property name=&quot;prefix&quot; value=&quot;/WEB-INF/&quot; /&gt;
		&lt;property name=&quot;suffix&quot; value=&quot;.xhtml&quot; /&gt;
	&lt;/bean&gt;
&nbsp;
&lt;/beans&gt;</pre></td></tr></table></div>

<p align="justify">We have defined the Spring Web Flow&#8217;s flow Controller that is responsible for creating the flow definitions by loading the flows from the file &#8216;/WEB-INF/flows/test.xml&#8217;. We have defined URL based mapping of requests by defining &#8216;SimpleUrlHandlerMapping&#8217;. Note that for JSf integration, the declaration of &#8216;faces:flow-builder-services&#8217; is necessary.</p>
<h3>Faces Configuration file</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE faces-config PUBLIC
  &quot;-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN&quot;
  &quot;http://java.sun.com/dtd/web-facesconfig_1_0.dtd&quot;&gt;
&nbsp;
&lt;faces-config&gt;
	&lt;application&gt;
		&lt;!-- Enables Facelets --&gt;
		&lt;view-handler&gt;com.sun.facelets.FaceletViewHandler&lt;/view-handler&gt;  
	&lt;/application&gt;
&lt;/faces-config&gt;</pre></td></tr></table></div>

<p align="justify">In the above faces configuration file, we have explicitly instructed to make use of Faceets as the view technology instead of JSF. Also note that the managed beans declarations and the navigation rules will simply go off and won&#8217;t be required at all as part of the integration since it will be taken care by Spring Web Flow itself.</p>
<h3>Welcome file</h3>
<p align="justify">The welcome file mentioned in the Web application&#8217;s deployment descriptor is &#8216;index.htm&#8217; whose contents is given below.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;html&gt;
&lt;head&gt;
  &lt;meta http-equiv=&quot;Refresh&quot; content=&quot;0; URL=spring/start&quot;&gt;
&lt;/head&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p align="justify">Note that it re-directs the control to the url mapping which will be handled by Spring&#8217;s dispatcher servlet.</p>
<h3>Flow Definition file</h3>
<p align="justify">The code snippet for the flow definition file is given below. Remember that the below definitions will be loaded by Spring Web Flow&#8217;s Flow Controller as we have configured a context listener in the web.xml file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;flow xmlns=&quot;http://www.springframework.org/schema/webflow&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd&quot;&gt;
&nbsp;
	&lt;view-state id=&quot;test&quot;&gt;
	&lt;/view-state&gt;
&nbsp;
&lt;/flow&gt;</pre></td></tr></table></div>

<p align="justify">There is only one state defined which is &#8216;test&#8217;. So, when the flow is invoked, the framework will look out for a file called &#8216;test.xhtml&#8217; in the directory &#8216;/WEB-INF/flows&#8217; as that is how we have configured the view resolver in the Spring&#8217;s application context file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;bean id=&quot;faceletsViewResolver&quot; class=&quot;org.springframework.web.servlet.view.UrlBasedViewResolver&quot;&gt;
		&lt;property name=&quot;viewClass&quot; value=&quot;org.springframework.faces.mvc.JsfView&quot;/&gt;
		&lt;property name=&quot;prefix&quot; value=&quot;/WEB-INF/&quot; /&gt;
		&lt;property name=&quot;suffix&quot; value=&quot;.xhtml&quot; /&gt;
	&lt;/bean&gt;</pre></td></tr></table></div>

<h3>Sample Facelets file</h3>
<p align="justify">The sample facelets file is given below. Note that it really does nothing other than displaying information message to the user. Also note that in the below file we are making use of templates and the name of the template file is &#8216;template.xhtml&#8217;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
      xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
      xmlns:h=&quot;http://java.sun.com/jsf/html&quot;&gt;
    &lt;body&gt;
&nbsp;
        &lt;ui:composition template=&quot;../template.xhtml&quot;&gt;
&nbsp;
            &lt;ui:define name=&quot;heading&quot;&gt;            
            &lt;/ui:define&gt;
&nbsp;
            &lt;ui:define name=&quot;body&quot;&gt;
                Sample page which illustrates the integration between JSF and Spring Web Flow
            &lt;/ui:define&gt;
&nbsp;
        &lt;/ui:composition&gt;
&nbsp;
    &lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<h3>Starting Page</h3>
<p align="justify">Note that this is the page that will be invoked at startup and from here the control resumes back to Spring Web flow for displaying the page &#8216;test.xhtml&#8217;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;!DOCTYPE composition PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;ui:composition xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
	    		xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
	  			xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
	  			xmlns:f=&quot;http://java.sun.com/jsf/core&quot;
                xmlns:sf=&quot;http://www.springframework.org/tags/faces&quot;
				template=&quot;template.xhtml&quot;&gt;
&nbsp;
    &lt;ui:define name=&quot;heading&quot;&gt;
    &lt;/ui:define&gt;
&nbsp;
    &lt;ui:define name=&quot;body&quot;&gt;
        &lt;div align=&quot;left&quot;&gt;
            &lt;p align=&quot;left&quot;&gt;
                &lt;a href=&quot;test&quot;&gt;Click here to invoke the Facelets page&lt;/a&gt;
            &lt;/p&gt;
        &lt;/div&gt;
    &lt;/ui:define&gt;
&lt;/ui:composition&gt;</pre></td></tr></table></div>

<h3>Running the application</h3>
<p align="justify">When the application is invoked, the welcome.html is invoked which redirects the control with the url pattern &#8216;spring/start&#8217; which will ultimately invoke the file start.xhtml. From here, when the user clicks the link, the url &#8216;test&#8217; will be mapped to test.xhtml file present in the directory &#8216;/WEB-INF/flows&#8217;. Running the above application will result in something like the following.</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2010/11/11.jpg"><img src="http://www.javabeat.net/wp-content/uploads/2010/11/11-300x160.jpg" alt="" title="1" width="300" height="160" class="aligncenter size-medium wp-image-981" /></a></p>
<p><em>Sample application</em></p>
<p align="justify">That&#8217;s it. We have run the first sample application that integrates Spring Web Flow and JSF.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/11/integrating-spring-web-flow-with-jsf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing JSF applications for J2ME clients</title>
		<link>http://www.javabeat.net/2010/10/writing-jsf-applications-for-j2me-clients/</link>
		<comments>http://www.javabeat.net/2010/10/writing-jsf-applications-for-j2me-clients/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 01:19:57 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[J2ME]]></category>
		<category><![CDATA[Java Server Faces (JSF)]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=514</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Introduction JSF is a Web framework for developing Component oriented web applications in the User Interface layer. Amongst the various capabilities that JSF provides, one of the major strengths of JSF is that it is not tied to any specific target device. For example, currently most of the JSF applications are running in a web [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Introduction</h2>
<p align="justify"><a href="http://www.javabeat.net/articles/11-introduction-to-java-server-faces-1.html">JSF</a> is a Web framework for developing Component oriented web applications in the User Interface layer. Amongst the various capabilities that JSF provides, one of the major strengths of JSF is that it is not tied to any specific target device. For example, currently most of the JSF applications are running in a web server and are accessible through a web browser. However, web browser is not the only target for a JSF application to be viewed; it can be even accessed through a hand-held device, for example through a mobile phone. In this example, we will see how to develop JSF applications targeted for mobile phones. This article assumes that the reader has a good understanding of <strong>JSF</strong>, its life-cycle and some understanding on <strong>JSF</strong> renderer kits.</p>
<h2>Download Sample Code for JSF Application for J2ME Clients</h2>
<ul>
<li><a href="http://www.javabeat.net/articles/sourcecode/2010/201010-jsf-applications-for-j2me-clients.zip">Download Sample Code for JSF Application for J2ME Clients</a></li>
</ul>
<h2>Renderer kits</h2>
<p align="justify">The responsibility of displaying a view in a target device is done through renderer kits. Renderer kits in <strong>JSF</strong> are nicely abstracted so it is possible to write custom implementation of renderer kits. Sun&#8217;s implementation of <strong>JSF</strong> provides a reference implementation of a HTML renderer kit. The HTML renderer kit is responsible for displaying the view in a web browser. So while writing a renderer kit implementation amongst the various factors to be taken into consideration, the important things are the target device, the protocol, the markup language and the scripting language. For a HTML renderer kit implementation, these would be the Web browsers, HTTP, hyper text markup language and java script.</p>
<p align="justify">Similarly a render kit implementation would consider the mobile phone browser, Wireless application protocol, the Wireless markup language (WML) and WML Script for providing suitable support in the mobile or any WAP browser. Wireless application protocol is the standard defined for displaying contents on wireless devices such as mobile phones. Similar to HTML that targets Web browsers, WML is the markup language for mobile phones. Consider the sample WML script,</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE wml PUBLIC &quot;-//WAPFORUM//DTD WML 1.1//EN&quot;
   &quot;http://www.wapforum.org/DTD/wml_1.1.xml&quot; &gt;
&lt;wml&gt;
	&lt;card id=&quot;test&quot; title=&quot;Test card&quot;&gt;
		&lt;p&gt;This is a test WML page.&lt;/p&gt;
	&lt;/card&gt;
&lt;/wml&gt;</pre></td></tr></table></div>

<p align="justify">Usually WML document can be thought of as a collection of cards. Each user interaction will be modeled as a card and each card will be inter-dependant. The syntax will mostly look like HTML for displaying the UI elements and content in the WML browser.</p>
<p align="justify">WML script, similar to Java script, is the client side scripting language for WML. It is mainly used for dynamically validating user input and it generally will appear in a separate file. Consider the following example script,</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">extern function sayHello()
{
	WMLBrowser.setVar(&quot;message&quot;, &quot;Hello World.&quot;);
	WMLBrowser.refresh();
}</pre></td></tr></table></div>

<p align="justify">The above script will appear in a separate file, say &#8216;hello.wmls&#8217; and the following wml page will provide a reference to the above wml script.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE wml PUBLIC &quot;-//WAPFORUM//DTD WML 1.1//EN&quot;
   &quot;http://www.wapforum.org/DTD/wml_1.1.xml&quot; &gt;
&lt;wml&gt;
	&lt;card id=&quot;test&quot; title=&quot;Test card&quot;&gt;
		&lt;p&gt;&lt;a href=&quot;hello.wmls#sayHello()&quot;&gt;Run&lt;/a&gt;&lt;br/&gt;
		$(message)
		&lt;/p&gt;
	&lt;/card&gt;
&lt;/wml&gt;</pre></td></tr></table></div>

<h3>Mobile Faces</h3>
<p align="justify">Mobile Faces for <strong>JSF</strong> provides a framework for simplifying the development of <strong>JSF</strong> applications targeted for wireless devices. The framework comes packaged with an implementation of renderer kits for HTML, XHTML-MP and WML. Also it supports various commonly used scripting languages such as Java Script, WML Script and ECMA Script. For testing <strong>JSF</strong> faces developed through Mobile Faces framework, we will be using OpenWave Browser for WAP. It serves as an emulator for testing WAP applications. In this article, we will be showing how to develop applications using the Mobile Faces toolkit.</p>
<h3>Setting up the development environment</h3>
<p align="justify">Download the following components before proceeding to the next section.</p>
<ul>
<li><a href="http://wapreview.com/download/Openwave_v70_Simulator.exe">Open Wave</a></li>
<li><a href="https://mobilejsf.dev.java.net">Mobile Faces</a></li>
</ul>
<p align="justify">OpenWave is used for testing the <strong>JSF</strong> application in the WAP Browser. Mobile Faces distribution has to be downloaded, jar file has to be built from the distribution&#8217;s ant file and the same has to be made available in the application&#8217;s class path.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/10/writing-jsf-applications-for-j2me-clients/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to Facelets</title>
		<link>http://www.javabeat.net/2010/09/introduction-to-facelets/</link>
		<comments>http://www.javabeat.net/2010/09/introduction-to-facelets/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 01:12:09 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=500</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Introduction This article will provide an introduction to the Facelets framework with the assumption that the readers have a basic understanding on Java Server Pages. With the Introduction of JSF, the idea is to make JSP as the view technology for JSF. However the architecture of JSF and JSP are completely different and there were [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Introduction</h2>
<p align="justify">This article will provide an introduction to the <strong>Facelets framework</strong> with the assumption that the readers have a basic understanding on Java Server Pages. With the <strong><a href="http://www.
<pre lang="LANGUAGE" line="1" lang="LANGUAGE" line="1".net/articles/11-introduction-to-java-server-faces-1.html">Introduction of JSF</a></strong>, the idea is to make JSP as the view technology for JSF. However the architecture of <strong>JSF</strong> and JSP are completely different and there were integration issues with the combination of JSF and JSP. With this in mind, Facelets was introduced which is another view definition framework similar to JSP. However, the architecture of the Facelets was designed with the complex <strong>JSF</strong> architecture and life-cycle in mind so that the component trees construction of Facelets can nicely mingle with <strong>JSF</strong>. Also in comparision with <strong>JSF</strong>, facelets can provide extending re-use of content code through templates.</p>
<h2>Download Example Code for Facelets</h2>
<ul>
<li><a href="http://www.
<pre lang="LANGUAGE" line="1" lang="LANGUAGE" line="1".net/articles/sourcecode/2010/201009-facelets.zip">Facelets Example Code</a></li>
</ul>
<h2>Hello World Application</h2>
<p align="justify">In this section, we will look into a starter application that will display the text Hello in the browser. The application will make the view as Facelets instead. We will provide explanation with the various aspects while going through the snippet code in the relevant section.</p>
<h3>JSP Page</h3>
<p align="justify">In the example application, the web application deployment descriptor is configured to look up for the file hello.jsp. The following is the code listing for the file hello.jsp. The page does a forward to the file hello.jsf. The extension of the forward file is &#8216;.jsf&#8217; and in the application&#8217;s deployment descriptor (which we will be seeing in the next section), we will see such requests forwarded to the Faces Servlet.</p>
<p><strong>hello.jsp</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;%@page contentType=&quot;text/html&quot; pageEncoding=&quot;UTF-8&quot;%&gt;
&lt;jsp:forward page=&quot;hello.jsf&quot;/&gt;</pre></td></tr></table></div>

<h3>Facelets Page</h3>
<p align="justify">The code listing for the facelets page is given below. Once we can see that the following page has the extension .xhtml. Later on we will see how to map this extension to a Facelets page. Also within the page we have included the namespace uri &#8216;http://java.sun.com/jsf/facelets&#8217; so that we can refer to Facelets related tags in the page.</p>
<p><strong>Hello.xhtml</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version='1.0' encoding='UTF-8' ?&gt; 
	&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
	&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
	xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
	xmlns:h=&quot;http://java.sun.com/jsf/html&quot;&gt;
	&lt;body&gt;
&nbsp;
	&lt;ui:composition template=&quot;/template.xhtml&quot;&gt;
&nbsp;
		&lt;ui:define name=&quot;heading&quot;&gt;
		Hello world application(Heading area)
		&lt;/ui:define&gt;
&nbsp;
		&lt;ui:define name=&quot;body&quot;&gt;
		Hello World1! (Body area)
		&lt;/ui:define&gt;
&nbsp;
	&lt;/ui:composition&gt;
&nbsp;
	&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p align="justify">In the above page, we have included the ui:composition and ui:define tags. The ui:composition along with the template attribute instructs that we want to use the page referenced in the attribute as the template page. The template page that we will look in the following section defines the section for the title content and the body content through &#8216;h1&#8242; (heading) and &#8216;p&#8217; (body) contents. The logical names given for the heading and the body content are &#8216;heading&#8217; and &#8216;body&#8217;. Now back to the &#8216;hello.xhtml&#8217;, it is always possible to define or override the logical named sections in the template page. In our case, we have overridden the sections &#8216;heading&#8217; and &#8216;body&#8217; with some simple customized content through ui:define tags.</p>
<h3>Template.xhtml</h3>
<p align="justify">One could remember the usage of template.xhtml is the previous section, the content being giving in the following section. As discussed, this template page has provided named logical sections for the heading and the body area. It does this definition with the usage of ui:insert tags. Once this template page is defined, it is possible to override the named logical sections. For example, if the logical section &#8216;heading&#8217; is not defined in the template-client page, i.e. the template page used by some client, in our case this file is hello.xhtml, then the content in the template.xhtml will be displayed.</p>
<p><strong>template.xhtml</strong></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version='1.0' encoding='UTF-8' ?&gt; 
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
    xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;&gt;
&nbsp;
	&lt;head&gt;
		&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
		&lt;title&gt;Facelets - Template Example&lt;/title&gt;
		&lt;link href=&quot;./css/default.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
	&lt;/head&gt;
&nbsp;
	&lt;body&gt;
		&lt;h1&gt;
			&lt;ui:insert name=&quot;heading&quot;&gt;Default Heading area to be overriden&lt;/ui:insert&gt;
		&lt;/h1&gt;
		&lt;p&gt;
			&lt;ui:insert name=&quot;body&quot;&gt;Default body area to be overriden&lt;/ui:insert&gt;
		&lt;/p&gt;
	&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></td></tr></table></div>

<h3>Web Application deployment Descriptor</h3>
<p align="justify">The web application&#8217;s deployment descriptor file is given below. As you can see in the snippet code, the requests ending with &#8216;*.jsf&#8217; are mapped to Faces Servlet. But till now we haven&#8217;t specified how Facelets is coming into the picture. We will see it shortly.</p>
<p><strong>web.xml</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app version=&quot;2.5&quot; xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;com.sun.faces.verifyObjects&lt;/param-name&gt;
		&lt;param-value&gt;true&lt;/param-value&gt;
	&lt;/context-param&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;com.sun.faces.validateXml&lt;/param-name&gt;
		&lt;param-value&gt;true&lt;/param-value&gt;
	&lt;/context-param&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;javax.faces.DEFAULT_SUFFIX&lt;/param-name&gt;
		&lt;param-value&gt;.xhtml&lt;/param-value&gt;
	&lt;/context-param&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;facelets.DEVELOPMENT&lt;/param-name&gt;
		&lt;param-value&gt;true&lt;/param-value&gt;
	&lt;/context-param&gt;
	&lt;context-param&gt;
		&lt;param-name&gt;facelets.SKIP_COMMENTS&lt;/param-name&gt;
		&lt;param-value&gt;true&lt;/param-value&gt;
	&lt;/context-param&gt;
&nbsp;
	&lt;servlet&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
		&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&nbsp;
	&lt;session-config&gt;
		&lt;session-timeout&gt;
		30
		&lt;/session-timeout&gt;
	&lt;/session-config&gt;
&nbsp;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;hello.jsp&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;
&lt;/web-app&gt;</pre></td></tr></table></div>

<p align="justify">Also, there are various parameters defined with respect to the Faces Servlet. Significant parameters being the development mode (represented through facelets.DEVELOPMENT) which when set to true instructs the framework that the application is still in development and any errors during page requests will be displayed in the browser.</p>
<h3>Sun-web.xml</h3>
<p align="justify">The vendor specific application&#8217;s deployment descriptor is given below. It defines the context name of the application set to Facelets-Helo</p>
<p><strong>sub-web.xml</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE sun-web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN&quot; &quot;http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd&quot;&gt;
&lt;sun-web-app error-url=&quot;&quot;&gt;
	&lt;context-root&gt;/Facelets-Hello&lt;/context-root&gt;
&lt;/sun-web-app&gt;</pre></td></tr></table></div>

<h3>Faces Configuration file</h3>
<p align="justify">The view handler for <strong>JSF</strong> is implemented through ViewHandler. To ensure that our application is using the View definition framework of Facelets, all we have to do is to replace the <strong>JSF</strong> version of View Handler with the Facelets view which happens to be &#8216;com.sun.facelets.FaceletViewHandler&#8217; in the configuration file.</p>
<p><strong>faces-config.xml</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">&lt;?xml version='1.0' encoding='UTF-8'?&gt;
&nbsp;
&lt;faces-config version=&quot;1.2&quot; 
	xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; 
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd&quot;&gt;
&nbsp;
	&lt;application&gt;
		&lt;view-handler&gt;
			com.sun.facelets.FaceletViewHandler
		&lt;/view-handler&gt;    
	&lt;/application&gt;
&nbsp;
&lt;/faces-config&gt;</pre></td></tr></table></div>

<p><a href="http://www.javabeat.net/wp-content/uploads/2010/09/11.jpg"><img src="http://www.javabeat.net/wp-content/uploads/2010/09/11-300x176.jpg" alt="" title="1" width="300" height="176" class="aligncenter size-medium wp-image-965" /></a></p>
<p><em>Facelets &#8211; Hello Application.</em></p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/09/introduction-to-facelets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to JSFUnit</title>
		<link>http://www.javabeat.net/2010/09/introduction-to-jsfunit/</link>
		<comments>http://www.javabeat.net/2010/09/introduction-to-jsfunit/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 01:09:49 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>
		<category><![CDATA[JSFUnit]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=495</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Introduction Testing has become an important aspect for every application and an application cannot be released unless it is not thoroughly tested. JSFUnit provides an attempt to bring in testing capabilities for JSF applications. Not many frameworks exists in the market for testing JSF applications and this framework which originated from JBoss community provides wider [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Introduction</h2>
<p align="justify">Testing has become an important aspect for every application and an application cannot be released unless it is not thoroughly tested. <strong><em>JSFUnit</em></strong> provides an attempt to bring in testing capabilities for <strong>JSF</strong> applications. Not many frameworks exists in the market for testing JSF applications and this framework which originated from <strong><em>JBoss community</em></strong> provides wider coverage for testing JSF applications with respect to the managed beans state, navigation flows, application configuration etc. This article is an attempt to provide an introduction to the framework <strong><em>JSFUnit</em></strong>.</p>
<p><em>If you are not familiar with <strong>Java Server Faces</strong>, first read our list of articles on Java Server Faces (JSF) including <a href="http://www.javabeat.net/2007/05/introduction-to-java-server-faces/">Introduction to Java Server Faces</a> by Raja</em>. We have also listed some of the popular <a href="http://www.javabeat.net/jsf-framework-books/">JSF Books</a>.</p>
<ul>
<li><a title="Permanent Link to Introduction to Java Server Faces" href="http://www.javabeat.net/2009/02/jsf-interview-questions/" rel="bookmark">JSF Interview Questions</a></li>
<li><a href="http://www.javabeat.net/jsf-framework-books/">JSF books</a></li>
<li><a title="Building JSF application with Exadel IDE" href="http://www.javabeat.net/2007/04/building-jsf-application-with-exadel-ide/" rel="bookmark">Building JSF application with Exadel IDE</a></li>
</ul>
<h2>JSFUnit Starter</h2>
<p align="justify">In this section, we will see how to setup <strong>JSFUnit</strong> framework for testing JSF applications. We will also see how to write simple <strong><em>JSF test cases</em></strong> at the end of the section. The example is as simple as it will display a JSP page that will return static html content to the browser.</p>
<h3>JSF Page</h3>
<p align="justify">Given below is the code snippet of the JSF page. Note that for each component we have explicitly assigned identifiers through the id attribute. This is absolutely necessary because later on the test case access will try to get a reference to a JSF page component only through identifiers.</p>
<p><strong>index.jsp</strong></p>
<pre class="brush: java; title: ; notranslate">
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot; %&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %&gt;

&lt;HTML&gt;

	&lt;f:view&gt;
		&lt;h1&gt;&lt;h:outputText value=&quot;JSFUnit HelloJSF Demo Application&quot; id=&quot;title&quot;/&gt;&lt;/h1&gt;
		&lt;h:form id=&quot;startupForm&quot;&gt;
		&lt;h:outputText value=&quot;JSF application is running&quot; id=&quot;test&quot;/&gt;
		&lt;/h:form&gt;
	&lt;/f:view&gt;

&lt;/HTML&gt;

</pre>
<h1></h1>
<p align="justify">The above JSF page makes use of two outputText tags for displaying static content one being embedded within the form whereas the other didn&#8217;t.</p>
<h3>Web Application Deployment Descriptor</h3>
<p align="justify">In the below web application&#8217;s deployment description, apart from the regular entries related to <strong>JSF</strong> mapping, we have configured plenty of configurations related to <strong>JSFUnit</strong> suitable for performing testing on JSF pages.</p>
<p><strong>web.xml</strong></p>
<pre class="brush: java; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot; &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;
&lt;web-app&gt;

	&lt;filter&gt;
		&lt;filter-name&gt;JSFUnitFilter&lt;/filter-name&gt;
		&lt;filter-class&gt;org.jboss.jsfunit.framework.JSFUnitFilter&lt;/filter-class&gt;
	&lt;/filter&gt;

	&lt;filter-mapping&gt;
		&lt;filter-name&gt;JSFUnitFilter&lt;/filter-name&gt;
		&lt;servlet-name&gt;ServletTestRunner&lt;/servlet-name&gt;
	&lt;/filter-mapping&gt;

	&lt;filter-mapping&gt;
		&lt;filter-name&gt;JSFUnitFilter&lt;/filter-name&gt;
		&lt;servlet-name&gt;ServletRedirector&lt;/servlet-name&gt;
	&lt;/filter-mapping&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
	&lt;/servlet&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;ServletRedirector&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.jboss.jsfunit.framework.JSFUnitServletRedirector&lt;/servlet-class&gt;
	&lt;/servlet&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;ServletTestRunner&lt;/servlet-name&gt;
		&lt;servlet-class&gt;org.apache.cactus.server.runner.ServletTestRunner&lt;/servlet-class&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;*.faces&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;ServletRedirector&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/ServletRedirector&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;ServletTestRunner&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/ServletTestRunner&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;

&lt;/web-app&gt;
</pre>
<p align="justify"><strong><em>JSFUnit framework</em></strong> provides a facility for running the unit test cases for JSF application directly from the browser. To make use of it, we have to define a <strong><em>JSFUnit Filter</em></strong> represented through <strong><em>org.jboss..JSFUnitFilter</em></strong> which is used to initiate the environment suitable for running test cases. The <strong><em>JSF Servlet Redirector</em></strong> represented through <strong><em>org.jboss..JSFUnitServletRedirector</em></strong> is used for invoking test cases for JSF as well as does the job of clean up. As the name suggests, the component <strong><em>org.apache.cactus..ServletTestRunner</em></strong> acts as a Servlet for starting a <strong><em>JUnit Runner</em></strong> within a web application.</p>
<h3>Vendor Specific Web Deployment Descriptor</h3>
<p align="justify">This example is targeted to be deployed in Glassfish and the below vendor specific configuration file is used to define the context root for the web application as &#8216;JSFUnit-Startup&#8217;.</p>
<p><strong>sun-web.xml</strong></p>
<pre class="brush: java; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE sun-web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN&quot; &quot;http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd&quot;&gt;
&lt;sun-web-app error-url=&quot;&quot;&gt;

	&lt;context-root&gt;/JSFUnit-Startup&lt;/context-root&gt;

&lt;/sun-web-app&gt;
</pre>
<h3>Faces Configuration</h3>
<p align="justify">In this example application, there is no need to define managed beans or the navigation rules, so the faces configuration file will be empty.</p>
<p><strong>faces-config.xml</strong></p>
<pre class="brush: java; title: ; notranslate">
&lt;?xml version='1.0' encoding='UTF-8'?&gt;
&lt;!DOCTYPE faces-config PUBLIC
  &quot;-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN&quot;
  &quot;http://java.sun.com/dtd/web-facesconfig_1_1.dtd&quot;&gt;

	&lt;faces-config&gt;

&lt;/faces-config&gt;
</pre>
<h3>JSF Test Case</h3>
<p align="justify">In this example, we will see how to write simple test cases for the above <strong>JSF</strong> page that we have written. Note that the following compile-time and run-time jar files need to be present in the classpath.</p>
<ul>
<li>ant-1.5.4.jar</li>
<li>aspectjrt-1.2.1.jar</li>
<li>cactus-13-1.7.1.jar</li>
<li>cactus-ant-13-1.7.1.jar</li>
<li>cargo-0.5.jar</li>
<li>commons-codec-1.3.jar</li>
<li>commons-collections-3.2.jar</li>
<li>commons-httpclient-3.1.jar</li>
<li>commons-io-1.4.jar</li>
<li>commons-lang-2.4.jar</li>
<li>commons-logging-1.1.1.jar</li>
<li>cssparser-0.9.5.jar</li>
<li>htmlunit-2.4.jar</li>
<li>htmlunit-core-js-2.4.jar</li>
<li>jboss-jsfunit-core-1.0.0.GA-SNAPSHOT.jar</li>
<li>junit-3.8.1.jar</li>
<li>nekohtml-1.9.9.jar</li>
<li>sac-1.3.jar</li>
<li>xalan-2.7.0.jar</li>
<li>xercesImpl-2.8.1.jar</li>
<li>xml-apis-1.0.b2.jar</li>
</ul>
<p><strong>JSFUnitStartupTest.java</strong></p>
<pre class="brush: java; title: ; notranslate">package net.javabeat.jsfunit.articles.startup;

import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlForm;
import javax.faces.component.html.HtmlOutputText;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.cactus.ServletTestCase;
import org.jboss.jsfunit.jsfsession.JSFClientSession;
import org.jboss.jsfunit.jsfsession.JSFServerSession;
import org.jboss.jsfunit.jsfsession.JSFSession;

public class JSFUnitStartupTest extends ServletTestCase{

	private JSFClientSession client;
	private JSFServerSession server;

	@Override
	public void setUp() throws IOException{
		JSFSession jsfSession = new JSFSession(&quot;/index.faces&quot;);
		client = jsfSession.getJSFClientSession();
		server = jsfSession.getJSFServerSession();
	}

	public static Test suite(){
		return new TestSuite( JSFUnitStartupTest.class );
	}

	public void testGetCurrentViewId() throws IOException{
		assertEquals(&quot;/index.jsp&quot;, server.getCurrentViewID());
	}

	public void testTitleComponent() throws IOException{

		UIComponent titleComponent = server.findComponent(&quot;title&quot;);
		assertNotNull(titleComponent);

		Object componentValue = server.getComponentValue(&quot;title&quot;);
		assertNotNull(componentValue);

		if (componentValue instanceof String){

		String strValue = (String)componentValue;
			assertEquals(&quot;JSFUnit HelloJSF Demo Application&quot;, strValue);
		}else{
			assertTrue(&quot;Value of title component is not an instance of String&quot;, false);
		}
	}

	public void testFormComponent() throws IOException{

		UIComponent formComponent = server.findComponent(&quot;startupForm&quot;);
		assertNotNull(formComponent);
		assertTrue(formComponent instanceof HtmlForm);

		UIComponent textComponent = server.findComponent(&quot;startupForm:test&quot;);
		assertNotNull(textComponent);
		assertTrue(textComponent instanceof HtmlOutputText);

		Object componentValue = server.getComponentValue(&quot;startupForm:test&quot;);
		assertNotNull(componentValue);

		if (componentValue instanceof String){
			String strValue = (String)componentValue;
			assertEquals(&quot;JSF application is running&quot;, strValue);
		}else{
			assertTrue(&quot;Value of test component is not an instance of String&quot;, false);
		}
	}
}</pre>
<p align="justify">The very first thing to note is all the test case classes should extend <strong><em>org.apache.cactus.ServetTestCase</em></strong> so that the Servlet Runner can run the test case class within a web application. In the setup() method we have tried to establish a session to a JSF page through <strong><em>JSFSession API</em></strong>. Through this JSFSession, one can have a client side session as well as a server side session by calling the methods <strong><em>getJSFClientSession()</em></strong> and <strong><em>getJSFServerSession()</em></strong>. Note that the argument we have given is the &#8220;/index.faces&#8221; and we have configured the web application&#8217;s deployment descriptor to map this to &#8220;/index.jsp&#8221;.</p>
<p align="justify">The test method testGetCurrentViewId() is used to test the identifier of the current view. Note that even though we have established a session to &#8220;/index.faces&#8221;, the final view displayed will be &#8220;/index.jsp&#8221; and we have asserted whether the view identifier is correct. In the example JSF page, we have displayed two label components with the help of outputText tag, one within the form and one outside the form tag. The test method testTitleComponent() is used to test whether the component is rendered and if rendered making sure the text displayed in the component is correct. One can use the method findComponent() method to identify a component displayed in the page. If the framework is able to find the component it will return a valid <strong>UIComponent</strong> reference and the value for the component can be obtained by calling <strong>getComponentValue()</strong>. Note that the test method makes appropriate assertions before checking for the existence and the value rendered in the component.</p>
<p align="justify">For identifying components within a form, the identifier &#8220;formId:componentId&#8221; can be used. For example if the form id is &#8220;testFormId&#8221; and the id of a component displayed in a form is &#8220;testComponentId&#8221;, then for identifying this component &#8220;testFormId:testComponentId&#8221; should be passed to the method <strong>findComponent()</strong> for proper identification and the third test case method just does that.</p>
<h3>Running the Application</h3>
<p align="justify">In this section, we will see how to run the JSF application and also how to invoke the test cases that test the page integrity from the browser.</p>
<p align="justify">Running the <strong>JSF application</strong> is simple. Assuming that the application is running locally on the port number 8080 and with the given context root &#8216;JSFUnit-Startup&#8217;, then the URL &#8220;http://localhost:8080/JSFUnit-Startup/index.faces&#8221; can be used to access the <strong>JSF</strong> page.</p>
<p align="justify">For running the test-cases and to see the test results on the browser, we have to make use of <strong><em>Servlet Test Case runner</em></strong>. The Servlet Test Case Runner class expects the test case class name in the parameter &#8216;suite&#8217; and the xs file name for formatting the test results in the parameter &#8216;xsl&#8217;. Note that the <strong>xsl file</strong> that is used for formatting the test results is included in the source code in the name &#8216;cactus-report.xsl&#8217;</p>
<p align="justify">The combined query string now becomes &#8220;ServletTestRunner?suite=net.javabeat.jsfunit.articles.startup.JSFUnitStartupTest&amp;xsl=cactus-report.xsl&#8221;. This query string has to be appended with the application&#8217;s context root, in our case, the application&#8217;s context root is http://localhost:8080/JSFUnit-Startup. So the URL &#8220;http://localhost:8080/JSFUnit-Startup/ServletTestRunner?suite=net.javabeat.jsfunit.articles.startup.JSFUnitStartupTest&amp;xsl=cactus-report.xsl&#8221; can be used to run the test cases and the results will get displayed in the browser. The following screen shot captures the test results,</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2010/09/1.jpg"><img class="aligncenter size-medium wp-image-963" title="1" alt="" src="http://www.javabeat.net/wp-content/uploads/2010/09/1-300x151.jpg" width="300" height="151" /></a></p>
<p><em>Test results for the jsf unit startup application.</em></p>
<h2>Exploring JSFUnit API</h2>
<p align="justify">In this example we will try to explore the client side API that <strong>JSFUnit</strong> framework supports. For illustrating this, we will develop a traditional login application which prompts for the username and a password during application startup. If the username and the password combination is correct, the application redirects to a successful page and when the password is incorrect, an error page will be returned. To make things interesting, we will redirect to a different page if the username is invaid.</p>
<h3>Login JSF Page</h3>
<p align="justify">Below is the login <strong>JSF</strong> page. This page displays the input components for accepting the username and password through the <strong>inputText</strong> and the <strong>inputSecret</strong> tags. Note that to validate the user information, when the login button is clicked, the control is forwarded to User managed bean&#8217;s login method which will be discussed in the forth coming section. Note that we have explicitly specified the identifier to each of the components.</p>
<p><strong>login.jsp</strong></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot; %&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %&gt;

&lt;HTML&gt;

&lt;f:view&gt;

	&lt;h1&gt;&lt;h:outputText value=&quot;Enter username and pasword&quot; id=&quot;infoText&quot;/&gt;&lt;/h1&gt;

	&lt;h:form id=&quot;startupForm&quot;&gt;

		&lt;h:outputText id = &quot;usernameLabel&quot; value = &quot;Username&quot; /&gt;
		&lt;h:inputText id = &quot;usernameText&quot; value =&quot;#{user.username}&quot;/&gt;

		&lt;br/&gt;
		&lt;h:outputText id = &quot;passwordLabel&quot; value = &quot;Password&quot; /&gt;
		&lt;h:inputSecret id = &quot;passwordText&quot; value =&quot;#{user.password}&quot;/&gt;

		&lt;br/&gt;&lt;br/&gt;
		&lt;h:commandButton id = &quot;loginButton&quot; action = &quot;#{user.login}&quot; value = &quot;Login&quot;/&gt;

	&lt;/h:form&gt;

&lt;/f:view&gt;

&lt;/HTML&gt;
</pre>
<h3>Welcome JSF Page</h3>
<p align="justify">Given below is the welcome page that will be displayed to the user when the username and the password are correct.</p>
<p><strong>welcome.jsp</strong></p>
<pre class="brush: java; title: ; notranslate">
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot; %&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %&gt;

&lt;f:loadBundle basename = &quot;net.javabeat.articles.jsfunit.login.messages&quot; var = &quot;message&quot;/&gt;
&lt;HTML&gt;

&lt;f:view&gt;

	&lt;h1&gt;&lt;h:outputText value=&quot;Welcome #{user.username}.&quot; id=&quot;infoText&quot;/&gt;&lt;/h1&gt;

&lt;/f:view&gt;

&lt;/HTML&gt;

</pre>
<h1></h1>
<h3>Invalid User JSF Page</h3>
<p align="justify">Have a look at the following invalid user <strong>JSF</strong> page.</p>
<p><strong>invalid-user.jsp</strong></p>
<pre class="brush: java; title: ; notranslate">
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot; %&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %&gt;

&lt;HTML&gt;

&lt;f:view&gt;

	&lt;h1&gt;&lt;h:outputText value=&quot;Invalid user #{user.username}. Please try again.&quot; id=&quot;infoText&quot;/&gt;&lt;/h1&gt;

&lt;/f:view&gt;

&lt;/HTML&gt;
</pre>
<p align="justify">The above page will be displayed when the username is invalid. Note that for testing purpose, we have hard-coded the username as &#8220;admin&#8221;.</p>
<h3>Error page</h3>
<p align="justify">This page will be displayed when the password is incorrect for a valid username. For testing purposes, we have hard-coded the username and password to &#8220;admin&#8221; and &#8220;admin&#8221;.</p>
<p><strong>error.jsp</strong></p>
<pre class="brush: java; title: ; notranslate">
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot; %&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot; %&gt;

&lt;HTML&gt;

&lt;f:view&gt;

	&lt;h1&gt;&lt;h:outputText value=&quot;Invalid password for the username #{user.username}. Please try again.&quot; id=&quot;infoText&quot;/&gt;&lt;/h1&gt;

&lt;/f:view&gt;

&lt;/HTML&gt;
</pre>
<h3>User Managed bean</h3>
<p align="justify">The following class which represents the managed bean for the login application does two things. At first, it encapsulates the username and password properties. Secondly, the validation of username and password is done within the implementation of this class in the method login().</p>
<p><strong>User.java</strong></p>
<pre class="brush: java; title: ; notranslate">package net.javabeat.articles.jsfunit.login;

public class User {

	private String username;
	private String password;

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String login(){

		if (username.equals(&quot;admin&quot;)){
			if (password.equals(&quot;admin&quot;)){
				return &quot;welcome&quot;;
			}else{
				return &quot;invalid-password&quot;;
			}
		}else{
			return &quot;error&quot;;
		}
	}
}</pre>
<p align="justify">Note that as part of validation in the login() method, if the user specifies correct username and password, a return value &#8220;welcome&#8221; is returned. Later on we will see how this return value maps to the view welcome.jsp. Similarly for the incorrect username and incorrect password, the views returned are error.jsp and invalid-password.jsp</p>
<h3>Faces Configuration</h3>
<p align="justify">In the below faces configuration file, we have configured the class User as a managed bean and have given the scope as session. Note that the return value view mapping during login process is modeled as navigation rules and navigation cases.</p>
<p><strong>faces-config.xml</strong></p>
<pre class="brush: java; title: ; notranslate">
&lt;?xml version='1.0' encoding='UTF-8'?&gt;
&lt;!DOCTYPE faces-config PUBLIC
  &quot;-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN&quot;
  &quot;http://java.sun.com/dtd/web-facesconfig_1_1.dtd&quot;&gt;

&lt;faces-config&gt;

	&lt;managed-bean&gt;
		&lt;managed-bean-name&gt;user&lt;/managed-bean-name&gt;
		&lt;managed-bean-class&gt;net.javabeat.articles.jsfunit.login.User&lt;/managed-bean-class&gt;
		&lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;
	&lt;/managed-bean&gt;

	&lt;navigation-rule&gt;
		&lt;from-view-id&gt;/login.jsp&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;welcome&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/welcome.jsp&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;

	&lt;navigation-rule&gt;
		&lt;from-view-id&gt;/login.jsp&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;error&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/error.jsp&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;

	&lt;navigation-rule&gt;
		&lt;from-view-id&gt;/login.jsp&lt;/from-view-id&gt;
		&lt;navigation-case&gt;
			&lt;from-outcome&gt;invalid-password&lt;/from-outcome&gt;
			&lt;to-view-id&gt;/invalid-password.jsp&lt;/to-view-id&gt;
		&lt;/navigation-case&gt;
	&lt;/navigation-rule&gt;

&lt;/faces-config&gt;
</pre>
<h3>JSF Test Cases</h3>
<p align="justify">In the following test class, we will discuss three testing scenarios, one when the username and password given by the user is correct, the second being the scenario when the username is correct and the password is wrong, and finally for the username being incorrect. As part of the discussion we will also be seeing the usage of the class <strong>JSFClientSession</strong>.</p>
<p><strong>LoginAppTest.java</strong></p>
<pre class="brush: java; title: ; notranslate">package net.javabeat.articles.jsfunit.login;

import java.io.IOException;
import javax.faces.component.UIComponent;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.cactus.ServletTestCase;
import org.jboss.jsfunit.jsfsession.JSFClientSession;
import org.jboss.jsfunit.jsfsession.JSFServerSession;
import org.jboss.jsfunit.jsfsession.JSFSession;

public class LoginAppTest extends ServletTestCase{

	private JSFClientSession client;
	private JSFServerSession server;

	@Override
	public void setUp() throws IOException{
		JSFSession jsfSession = new JSFSession(&quot;/login.faces&quot;);
		client = jsfSession.getJSFClientSession();
		server = jsfSession.getJSFServerSession();
	}

	public static Test suite(){
		return new TestSuite( LoginAppTest.class );
	}

	public void testCorrectUsernameAndPassword() throws IOException{

		UIComponent buttonComponent = server.findComponent(&quot;loginButton&quot;);
		assertNotNull(buttonComponent);

		String username = &quot;admin&quot;;

		client.setValue(&quot;usernameText&quot;, username);
		client.setValue(&quot;passwordText&quot;, &quot;admin&quot;);

		client.click(&quot;loginButton&quot;);

		String pageText = client.getPageAsText();
		assertNotNull(pageText);

		assertTrue(pageText.contains(&quot;Welcome &quot; + username + &quot;.&quot;));
	}

	public void testCorrectUsernameAndIncorrectPassword() throws IOException{

		UIComponent buttonComponent = server.findComponent(&quot;loginButton&quot;);
		assertNotNull(buttonComponent);

		String username = &quot;admin&quot;;

		client.setValue(&quot;usernameText&quot;, username);
		client.setValue(&quot;passwordText&quot;, &quot;1234&quot;);

		client.click(&quot;loginButton&quot;);

		String pageText = client.getPageAsText();
		assertNotNull(pageText);

		assertTrue(pageText.contains(&quot;Invalid password for the username &quot; + username + &quot;. Please try again.&quot;));
	}

	public void testIncorrectUsername() throws IOException{

		UIComponent buttonComponent = server.findComponent(&quot;loginButton&quot;);
		assertNotNull(buttonComponent);

		String username = &quot;admin123&quot;;

		client.setValue(&quot;usernameText&quot;, username);
		client.setValue(&quot;passwordText&quot;, &quot;admin&quot;);

		client.click(&quot;loginButton&quot;);

		String pageText = client.getPageAsText();
		assertNotNull(pageText);

		assertTrue(pageText.contains(&quot;Invalid user &quot; + username + &quot;. Please try again.&quot;));
	}
}</pre>
<p align="justify">As part of the regular process, the setup() method is overridden for acquiring a session to the application&#8217;s startup page – which is &#8220;/login.faces&#8221;. Now the application is displaying the login page and in the first test case, we have made of the <strong><em>JSFClientSession API</em></strong> for setting the username and password parameters by calling setValue(paramName, paramValue). Note that this will simulate as if the user is typing the values for the username and the password fields. Finally the request submission is simulated by calling the method click() defined on the <strong><em>JSFClientSession</em></strong> object. Note that argument passed to click() is the identifier for the button. As soon as the request is submitted and the response is received, the client can call the method getPageAsText() which will return a raw HTML page text. And finally the page content is validated for correctness by comparing it with the return value from getPageAsText() method. Similarly the second and the third test cases deals with incorrect username and incorrect password combination.</p>
<h3>Running the application</h3>
<p align="justify">The application can be invoked through the URL &#8220;http://localhost:8080/JSFUnit-Login/login.faces&#8221;. And for invoking the test cases, the URL &#8220;http://localhost:8080/JSFUnit-Login/ServletTestRunner?suite=net.javabeat.articles.jsfunit.login.LoginAppTest&amp;xsl=cactus-report.xsl&#8221;. Given below is the screen shot of the test results for the login application,</p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2010/09/2.jpg"><img class="aligncenter size-medium wp-image-961" title="2" alt="" src="http://www.javabeat.net/wp-content/uploads/2010/09/2-300x151.jpg" width="300" height="151" /></a></p>
<p><em>Test results for the jsf unit login application.</em></p>
<h2>Miscellaneous</h2>
<p align="justify">In this miscellaneous section, we will further dig into the API support on JSFUnit framework.</p>
<h3>Adding Request Listener</h3>
<p align="justify">A <strong><em>Request Listener</em></strong> object can be used to intercept client request and customizations can be injected before and after the invocation of client request. For example, the following code adds a simple Request Listener,</p>
<pre class="brush: java; title: ; notranslate">public void testRequestListener(){

	WebClientSpec specification = new WebClientSpec(&quot;/login.faces&quot;);
	WebConnection webConnection = specification.getWebClient().getWebConnection();

	if (webConnection instanceof JSFUnitWebConnection){
		JSFUnitWebConnection jsfConnection = (JSFUnitWebConnection)webConnection;
		MyRequestListener listener = new MyRequestListener();
		jsfConnection.addListener(listener);
	}
}

class MyRequestListener implements RequestListener{

	public void beforeRequest(WebRequestSettings settings) {
		System.out.println(&quot;Before Request&quot;);
		throw new UnsupportedOperationException(&quot;Not supported yet.&quot;);
	}

	public void afterRequest(WebResponse settings) {
		System.out.println(&quot;After Request&quot;);
	}

}</pre>
<h3>Testing Faces Messages</h3>
<p align="justify">An application can emit faces messages which can be warning, information or an error. <strong>JSFUnit</strong> framework provides support for iterating over the faces messages upon response completion for validating its contents. For example,</p>
<pre class="brush: java; title: ; notranslate">public void testGetFacesMessages(){

	Iterator iterator = server.getFacesMessages(&quot;someComponentId&quot;);
	while (iterator.hasNext()){

		FacesMessage facesMessage = iterator.next();
		// Validate the facesMessage object.
	}
}</pre>
<h3>Testing Managed Bean states</h3>
<p align="justify">The state of managed beans will keep changing in an application&#8217;s workflow and the framework adds capabilities for testing the value of a managed bean&#8217;s state giving an <strong>EL expression</strong>. Consider the following code snippet the gets the state of username and password for the Managed bean User.</p>
<pre class="brush: java; title: ; notranslate">public void testManagedBeans(){

	String username = (String)server.getManagedBeanValue(&quot;${user.username}&quot;);
	assertEquals(&quot;admin&quot;, username);

	String password = (String)server.getManagedBeanValue(&quot;${user.password}&quot;);
	assertEquals(&quot;admin&quot;, password);
}</pre>
<h3>Dumping Client Ids</h3>
<p align="justify">Sometimes, as part of debugging, it will be essential for dumping the client id information pertaining the current page.</p>
<pre class="brush: java; title: ; notranslate">public void testClientId(){

	ClientIDs clienIds = server.getClientIDs();
	clienIds.dumpAllIDs();
}</pre>
<p align="justify">The method dumpAllIDs() will print all the Client IDs to the console.</p>
<h2>Conclusion</h2>
<p align="justify">This article provided step by step process in setting up the environment for facilitating testing for <strong>JSF applications</strong>. Detailed discussions were given with respect to configuring and running test cases within a web application. The article also focused on explaining the essential APIs like <strong><em>JSFSession</em></strong>, <strong><em>JSFServerSession</em></strong>, <strong><em>JSFClientSession</em></strong>. Finally the article provided the miscellaneous capabitiies like checking the state of managed beans, adding request listeners, testing faces messages etc.</p>
<ul>
<li><a title="Permanent Link to Introduction to Java Server Faces" href="http://www.javabeat.net/2009/02/jsf-interview-questions/" rel="bookmark">JSF Interview Questions</a></li>
<li><a href="http://www.javabeat.net/jsf-framework-books/">JSF books</a></li>
<li><a title="Building JSF application with Exadel IDE" href="http://www.javabeat.net/2007/04/building-jsf-application-with-exadel-ide/" rel="bookmark">Building JSF application with Exadel IDE</a></li>
</ul>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/09/introduction-to-jsfunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating JSF and JPA</title>
		<link>http://www.javabeat.net/2010/07/integrating-jsf-and-jpa/</link>
		<comments>http://www.javabeat.net/2010/07/integrating-jsf-and-jpa/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 00:22:44 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=437</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Introduction MVC architecture has become the default choice for developing web applications. It has become a tradition to develop web applications using multi-tier architecture and hence involving one or more Frameworks. A Framework ensures faster development cycle and guarantees the usage of proven design patterns and architecture. There are various Frameworks available for each layer; [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h1>Introduction</h1>
<p>MVC architecture has become the default choice for developing web applications. It has become a tradition to develop web applications using multi-tier architecture and hence involving one or more Frameworks. A Framework ensures faster development cycle and guarantees the usage of proven design patterns and architecture. There are various Frameworks available for each layer; be it presentation tier, business tier or persistence tier.</p>
<p>The architects can decide upon the choice of the frameworks for different tier based on the requirement. This article is to demonstrate how to integrate the presentation tier using JSF with the persistence tier using JPA. <strong>JSF and JPA</strong> are two popular frameworks used to develop Java EE applications.</p>
<blockquote><p><span style="text-decoration: underline;"><strong>also read:</strong></span></p>
<ul>
<li><a title="Permanent Link to Introduction to Java Server Faces" href="http://www.javabeat.net/2007/05/introduction-to-java-server-faces/" rel="bookmark">Introduction to Java Server Faces</a></li>
<li><a title="Permanent Link to Request Processing Lifecycle phases in JSF" href="http://www.javabeat.net/2007/11/request-processing-lifecycle-phases-in-jsf/" rel="bookmark">Request Processing Lifecycle phases in JSF</a></li>
<li><a title="Permanent Link to Accessing Web Services from JSF applications" href="http://www.javabeat.net/2007/11/accessing-web-services-from-jsf-applications/" rel="bookmark">Accessing Web Services from JSF applications</a></li>
<li><a title="Permanent Link to Navigation model in JSF" href="http://www.javabeat.net/2007/11/navigation-model-in-jsf/" rel="bookmark">Navigation model in JSF</a></li>
</ul>
</blockquote>
<h1>Problem Statement</h1>
<p>In this article, a scenario of generating report on employee details is considered and has been explained with the corresponding code. The module will display the details of the particular employee chosen from a drop down list box. The application starts with a home page (Home.jsp) which has a hyperlink to the report page (EmloyeeHome.jsp). The EmployeeHome.jsp has a drop down with the employee numbers populated dynamically from the database through JPA. Upon selecting a particular employee number the details of the employee will be displayed in the same page.</p>
<h1>Raising the application</h1>
<p>Step1:</p>
<ul>
<li>Create a dynamic web application in a workspace in Eclipse</li>
<li>For using JPA, add the required project facet.</li>
<ul>
<li>Right click on the project and select properties -&gt; Project Facets. Select<br />
the checkbox for Java Persistence and click on the “further configuration<br />
available&#8230;”</li>
<li>By clicking the link “further configuration available…” “JPA Facet”<br />
window will be displayed. Click on “OK” button and come to “Project<br />
Facet window”. Click on “OK” button in “Project Facet” window. This<br />
will complete the configuration required in Eclipse IDE</li>
</ul>
</ul>
<p>Step2:</p>
<ul>
<li>The classes12.jar, hibernate-entitymanager.jar, javaee.jar, jboss-faces.jar,<br />
jsf-api.jar, jsf-impl.jar, standard.jar, jstl.jar, toplink-essentials.jar,<br />
toplink-essentials-agen.jar archive files should be added on to the project<br />
to enable JPA and JSF framework in the application. Copy these jar files<br />
into the lib folder (Project -&gt; WebContent -&gt; WEB-INF -&gt; lib)</li>
</ul>
<p>Step3:</p>
<ul>
<li>Create a Home.jsp with a hyperlink to EmployeeHome.jsp</li>
<li>Sample code (Home.jsp)</li>
</ul>
<pre class="brush: java; title: ; notranslate">
&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html;
charset=ISO-8859-1&quot; pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;%@ taglib prefix=&quot;f&quot; uri=&quot;http://java.sun.com/jsf/core&quot;%&gt;
&lt;%@ taglib prefix=&quot;h&quot; uri=&quot;http://java.sun.com/jsf/html&quot;%&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
&quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
	&lt;title&gt;Home page&lt;/title&gt;
&lt;/head&gt;
  &lt;body&gt;
	&lt;f:view&gt;
		&lt;h3&gt;
		&lt;center&gt;
		&lt;h:outputLabel&gt;Welcome to the Home Page&lt;/h:outputLabel&gt;
		&lt;/center&gt;
		&lt;h:outputLink value=&quot;EmployeeHome.jsp&quot;&gt;Employee Details&lt;/h:outputLink&gt;
        	&lt;/h3&gt;
	&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>Sample Screen Shot</strong></p>
<p><a href="http://www.javabeat.net/wp-content/uploads/2010/07/1.jpg"><img class="aligncenter size-medium wp-image-959" title="1" src="http://www.javabeat.net/wp-content/uploads/2010/07/1-300x115.jpg" alt="" width="300" height="115" /></a><br />
Step4:</p>
<ol type="a">
<ol type="a">
<li>When the <em>Employee Details</em> hyperlink is clicked, Employee Home page is displayed.</li>
<li>Create EmployeeHome.jsp</li>
<li>Sample Code (EmployeeHome.jsp)</li>
</ol>
</ol>
<pre class="brush: java; title: ; notranslate">
&lt;%@ page language=&quot;java&quot;
contentType=&quot;text/html; charset=ISO-8859-1&quot;
	pageEncoding=&quot;ISO-8859-1&quot;%&gt;
&lt;%@ taglib prefix=&quot;f&quot; uri=&quot;http://java.sun.com/jsf/core&quot;%&gt;
&lt;%@ taglib prefix=&quot;h&quot; uri=&quot;http://java.sun.com/jsf/html&quot;%&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;
	&quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
	&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
	&lt;title&gt;Employee Details&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;f:view&gt;
	&lt;h3&gt;
        	&lt;center&gt;Welcome to Employee Home Page&lt;/center&gt;
	&lt;/h3&gt;
	&lt;br&gt;&lt;br&gt;
	&lt;h:form&gt;
	&lt;h3&gt;
		Select an Employee Number from the drop down:
	&lt;/h3&gt;
	&lt;br&gt;&lt;br&gt;
	&lt;h:selectOneMenu id=&quot;selEmpNo&quot;
		alueChangeListener=&quot;#{employee.employeeReport}&quot;
		onchange=&quot;submit()&quot;&gt;
		&lt;f:selectItem itemLabel=&quot;select&quot; /&gt;
	&lt;f:selectItems value=&quot;#{employee.empNoList}&quot; id=&quot;emp&quot;/&gt;
	&lt;/h:selectOneMenu&gt;
	&lt;/h:form&gt;
	&lt;br&gt;&lt;br&gt;
	&lt;h3&gt;
	&lt;h:outputText value=&quot;Employee Name: &quot;&gt;&lt;/h:outputText&gt;
	&lt;h:outputText value=&quot;#{employee.empName}&quot;/&gt;
	&lt;br&gt;&lt;br&gt;
	&lt;h:outputText value=&quot;Employee Number: &quot;/&gt;
	&lt;h:outputText value=&quot;#{employee.empNo}&quot;/&gt;
	&lt;br&gt;&lt;br&gt;
	&lt;h:outputText value=&quot;Name of the IBU: &quot;/&gt;
	&lt;h:outputText value=&quot;#{employee.ibu}&quot;/&gt;
	&lt;br&gt;&lt;br&gt;
	&lt;h:outputText value=&quot;Designation: &quot;/&gt;
	&lt;h:outputText value=&quot;#{employee.designation}&quot;/&gt;
&lt;/h3&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<ol type="a">
<li>Sample Screen shot</li>
</ol>
<p><a href="http://www.javabeat.net/wp-content/uploads/2010/07/2.jpg"><img class="aligncenter size-medium wp-image-960" title="2" src="http://www.javabeat.net/wp-content/uploads/2010/07/2-300x99.jpg" alt="" width="300" height="99" /></a><br />
<a href="http://www.javabeat.net/wp-content/uploads/2010/07/3.jpg"><img class="aligncenter size-medium wp-image-958" title="3" src="http://www.javabeat.net/wp-content/uploads/2010/07/3-300x115.jpg" alt="" width="300" height="115" /></a><br />
<span style="text-decoration: underline;"><strong>Note:</strong></span> In EmployeeHome.jsp, &lt;f:selectItems&gt; is used to dynamically populate the<br />
drop down with employee number from the corresponding managed bean. When a particular employee number is selected from the drop down, the corresponding employee details should be displayed. In order to implement this functionality,<br />
implement ValueChangeEventListener in the corresponding managed bean and bound the UI component to it. The employeeReport(ValueChangeEvent event) of the EmployeeBean managed bean is the value change even listener in this<br />
implementation. . Since value change event will not submit the request, some mechanism (E.g., JavaScript function) is required to submit the request after selecting the employee number from the drop down. (In EmployeeHome.jsp,<br />
“submit() is assigned to “onChange” attribute of &lt;h:selectOneMenu&gt; tag. Hence no need to write any explicit java script function to submit the form.)</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>Step5:</p>
<ul>
<ul>
<li>Create a package “employee” under the project</li>
<li>Create a bean EmployeeBean which is a managed bean (the configuration of the managed bean is available in faces-congig.xml file which is given latter). The attributes of this bean is bound to various UI Components used in EmployeeHome.jsp</li>
<li>Sample Code (EmployeeBean.java)</li>
</ul>
</ul>
<pre class="brush: java; title: ; notranslate">package employee;

	import java.util.ArrayList;
	import java.util.Iterator;
	import java.util.List;
	import javax.faces.event.ValueChangeEvent;
	import javax.faces.model.SelectItem;

	public class EmployeeBean {
		private String empName;
		private String ibu;
		private String designation;
		private int empNo;

		//This is used to dynamically populate the drop down with employee numbers
		List&lt;SelectItem&gt;empNoList;

		public EmployeeBean(){
			this.empNoList = new ArrayList&lt;SelectItem&gt;();
			/*Populating Employee Number in the drop down - Dynamic */
			List&lt;EmployeeEntity&gt;empList = new
				EmployeeService().getEmployeeList();
			Iterator&lt;EmployeeEntity&gt;iterator = empList.iterator();
			while(iterator.hasNext()){
				EmployeeEntity employee = iterator.next();
				SelectItem item = new SelectItem(employee.getEmpNo());
				empNoList.add(item);
			}
		}
		public String getEmpName() {
			return empName;
		}
		public void setEmpName(String empName) {
			this.empName = empName;
		}
		public String getIbu() {
			return ibu;
		}
		public void setIbu(String ibu) {
			this.ibu = ibu;
		}
		public String getDesignation() {
			return designation;
		}
		public void setDesignation(String designation) {
			this.designation = designation;
		}
		public int getEmpNo() {
			return empNo;
		}
		public void setEmpNo(int empNo) {
			this.empNo = empNo;
		}
		public List&lt;SelectItem&gt; getEmpNoList() {
			return empNoList;
		}
		public void setEmpNoList(List&lt;SelectItem&gt; empNoList) {
			this.empNoList = empNoList;
		}
		public List&lt;EmployeeEntity&gt; getEmpList() {
			return empList;
		}
		public void setEmpList(List&lt;EmployeeEntity&gt; empList) {
			this.empList = empList;
		}
		/*Eventlistener - for fetching an employee record based on the selection of employee
			number from the drop down*/
		public void employeeReport(ValueChangeEvent event){
			int empNo = Integer.parseInt((String)event.getNewValue());
			EmployeeEntity employee = new
				EmployeeService().getEmployee(empNo);
			this.empNo = employee.getEmpNo();
			this.empName = employee.getEmpName();
			this.ibu = employee.getIbu();
			this.designation = employee.getDesignation();
		}
	}
</pre>
<p><span style="text-decoration: underline;"><strong>Note:</strong></span> After selecting the employee number from the drop down, to fetch the data from the table, a service class called “EmployeeService” (code is given later) is used which makes use of JPA to fetch the required record from the<br />
table.</p>
<p>Step6:</p>
<ol type="a">
<ol type="a">
<li>Inside the package “employee”, create an entity class called “EmployeeEntity.java” which is mapped to an “employee” table</li>
<li>Sample Code (EmployeeEntity.java)</li>
</ol>
</ol>
<pre class="brush: java; title: ; notranslate">package employe;
	import javax.persistence.Entity;
	import javax.persistence.Id;
	import javax.persistence.Table;

	@Entity
	@Table(name=&quot;employee&quot;)
	public class EmployeeEntity {
		@Id
		private int empNo;
		private String empName;
		private String ibu;
		private String designation;
		public int getEmpNo() {
			return empNo;
		}
		public void setEmpNo(int empNo) {
			this.empNo = empNo;
		}
		public String getEmpName() {
			return empName;
		}
		public void setEmpName(String empName) {
			this.empName = empName;
		}
		public String getIbu() {
			return ibu;
		}
		public void setIbu(String ibu) {
			this.ibu = ibu;
		}
		public String getDesignation() {
			return designation;
		}
		public void setDesignation(String designation) {
			this.designation = designation;
		}
	}
</pre>
<p>Step7:</p>
<ol type="a">
<ol type="a">
<li>Inside the package “employee”, create a class called “EmployeeService.java”. This class will interact with the database to fetch the required details</li>
<li>Sample Code (EmployeeService.java)</li>
</ol>
</ol>
<pre class="brush: java; title: ; notranslate">package employee;
	import java.util.ArrayList;
	import java.util.List;
	import javax.persistence.EntityManager;
	import javax.persistence.EntityManagerFactory;
	import javax.persistence.EntityTransaction;
	import javax.persistence.Persistence;
	import javax.persistence.Query;

	public class EmployeeService {
		public List&lt;EmployeeEntity&gt; getEmployeeList(){
			List&lt;EmployeeEntity&gt; empList = new ArrayList&lt;EmployeeEntity&gt;();
			EntityManager em = null;
			try{
				EntityManagerFactory emf =
						Persistence.createEntityManagerFactory(&quot;Employee-
						Details&quot;);
				em = emf.createEntityManager();
				EntityTransaction et = em.getTransaction();
				et.begin();
				Query query = em.createQuery(&quot;select e from EmployeeEntitye&quot;);
				empList = query.getResultList();
			}
			catch(Exception e){
				//log the exception
			}
			return empList;
		}
		public EmployeeEntity getEmployee(int empNo){
			EmployeeEntity employee = new EmployeeEntity();
			EntityManager em = null;
			try{
				EntityManagerFactory emf =
					Persistence.createEntityManagerFactory(&quot;Employee-
					Details&quot;);
				em = emf.createEntityManager();
				EntityTransaction et = em.getTransaction();
				employee = em.find(myPackage.EmployeeEntity.class, empNo);
			}
			catch(Exception e){
				//log the exception
			}
			finally{
				if( em != null){
					em.clear();
				}
			}
			return employee;
		}
	}
</pre>
<p>Step8:</p>
<ol type="a">
<ol type="a">
<li>Create “persistence.xml” file and keep it inside META-INF folder</li>
<li>Sample Code (persistence.xml)</li>
</ol>
</ol>
<pre class="brush: java; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
	&lt;persistence version=&quot;1.0&quot; xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;
		xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
		xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence

http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;&gt;

		&lt;persistence-unit name=&quot;Employee-Details&quot;&gt;
			&lt;provider&gt;oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider&lt;/provider&gt;
			&lt;class&gt;.EmployeeEntity&lt;/class&gt;
			&lt;properties&gt;
				&lt;property name=&quot;toplink.jdbc.url&quot; value=&quot;
					jdbc:oracle:thin:@localhost:1521:nr&quot;/&gt;
				&lt;property name=&quot;toplink.jdbc.user&quot; value=&quot;scott&quot;/&gt;
				&lt;property name=&quot;toplink.jdbc.driver&quot;
					value=&quot;oracle.jdbc.driver.OracleDriver&quot;/&gt;
				&lt;property name=&quot;toplink.jdbc.password&quot; value=&quot;tiger&quot;/&gt;
				&lt;property name=&quot;toplink.ddl-generation&quot; value=&quot;update-tables&quot;/&gt;
			&lt;/properties&gt;
		&lt;/persistence-unit&gt;
&lt;/persistence&gt;</pre>
<p><span style="text-decoration: underline;"><strong>Note:</strong></span> Persistence.xml file is configured for Oracle database. You have to<br />
configure according to the database which you want to use and give the<br />
values accordingly.</p>
<p>Step9:</p>
<ol type="a">
<ol type="a">
<ol type="a">
<li>Create “faces-congig.xml” file which contains information about<br />
navigation rule and managed bean. Place the file inside WEB-INF<br />
folder</li>
<li>Sample Code (faces-config.xml)</li>
</ol>
</ol>
</ol>
<pre class="brush: java; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
	&lt;faces-config
		xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
		xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
		xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd&quot;

			version=&quot;1.2&quot;&gt;
		&lt;navigation-rule&gt;
			&lt;from-view-id&gt;/Home.jsp&lt;/from-view-id&gt;
		&lt;/navigation-rule&gt;
		&lt;managed-bean&gt;
			&lt;managed-bean-name&gt;employee&lt;/managed-bean-name&gt;
			&lt;managed-bean-class&gt;employee.EmployeeBean
			&lt;/managed-bean-class&gt;
			&lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;
		&lt;/managed-bean&gt;
	&lt;/faces-config&gt;</pre>
<h1>Conclusion</h1>
<p>This article demonstrates how to integrate <strong>JSF and JPA</strong> while developing a web application. Apart from this, the article also illustrates how to use drop down (dynamic) in a JSF enabled JSP and how to make use of value change event listener.</p>
<h1>Acknowledgement</h1>
<p>I would like to thank my manager Mr. Rajagopalan P, Principal, Education and Research Department, Infosys for the guidance and continuous support. I would like to thank Mr. Satheesha B N, Associate Vice-President, Education<br />
and Research Department, Infosys for motivating me to write this article. I would like to thank Mrs. Yuvarani, Lead, Education and Research Department, Infosys for giving valuable suggestions.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/07/integrating-jsf-and-jpa/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JSF 2.0 &#8211; Images, CSS and Java Script</title>
		<link>http://www.javabeat.net/2010/07/jsf-2-0-images-css-and-java-script/</link>
		<comments>http://www.javabeat.net/2010/07/jsf-2-0-images-css-and-java-script/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 00:06:45 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=1877</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>JSF 2.0 Cookbook This book will cover all the important aspects involved in developing JSF applications. It provides clear instructions for getting the most out of JSF and offers many exercises to build impressive desktop-style interfaces for your web applications. You will learn to develop JSF applications starting with simple recipes and gradually moving on [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><H1><CENTER><b>JSF 2.0</b> Cookbook</CENTER></H1><br />
<P>This book will cover all the important aspects involved in developing JSF applications. It<br />
provides clear instructions for getting the most out of JSF and offers many exercises to<br />
build impressive desktop-style interfaces for your web applications. You will learn to<br />
develop JSF applications starting with simple recipes and gradually moving on to<br />
complex recipes.</P><br />
<P>We start off with the simple concepts of converters, validators, and file management. We<br />
then work our way through various resources such as CSS, JavaScript, and images to<br />
improve your web applications. You will learn to build simple and complex custom<br />
components to suit your needs. Next, you get to exploit AJAX as well as implement<br />
internationalization and localization for your JSF applications. We then look into<br />
ensuring security for your applications and performing testing of your applications. You<br />
also get to learn all about Facelets and explore the newest <b>JSF 2.0</b> features. Finally, you<br />
get to learn a few integrations such as JSTL with JSF, Spring with JSF, and Hibernate<br />
with JSF. All these concepts are presented in the form of easy-to-follow recipes.</P><br />
<P>Each chapter discusses separate types of recipes and they are presented with an<br />
increasing level of complexity from simple to advanced. All of these recipes can be used<br />
with JSF 1.2 as well as <b>JSF 2.0</b>.</P></p>
<h1>JSF Articles</h1>
<ul>
<li><a href="http://www.javabeat.net/articles/jsf/1/">JSF Articles</a></li>
<li><a href="http://www.javabeat.net/articles/57-accessing-web-services-from-jsf-applications-1.html">Accessing Web Services from JSF applications</a></li>
<li><a href="http://www.javabeat.net/articles/11-introduction-to-java-server-faces-1.html">Introduction to Java Server Faces</a></li>
<li><a href="http://www.javabeat.net/articles/15-introduction-to-jsf-core-tags-library-1.html">Introduction to JSF Core Tags Library</a></li>
<li><a href="http://www.javabeat.net/articles/17-introduction-to-java-server-facesjsf-html-tags-1.html">Introduction to Java Server Faces(JSF) HTML Tags </a></li>
<li><a href="http://www.javabeat.net/articles/21-ajax-support-in-struts-20-1.html">AJAX Support in Struts 2.0</a></li>
<li><a href="http://www.javabeat.net/articles/53-using-converters-in-jsf-1.html">Using Converters in JSF</a></li>
<li><a href="http://www.javabeat.net/articles/54-request-processing-lifecycle-phases-in-jsf-1.html">Request Processing Lifecycle phases in JSF</a></li>
</ul>
<p><H1>What This Book Covers</H1><br />
<P><I>Chapter 1, Using Standard and Custom Converters in JSF</I> covers the standard and<br />
custom converters in JSF. We start with implicit and explicit conversion examples, then<br />
move on to creating and using custom converters, and we end up with client-side<br />
converters using MyFaces Trinidad.</P><br />
<P><I>Chapter 2, Using Standard and Custom Validators in JSF</I> continues with standard and<br />
custom validators. We see how to use a standard validator, how to create and use custom<br />
validators, and how to use RichFaces and Apache MyFaces validators. We also present<br />
the new <b>JSF 2.0</b> validators, such as f:validateRegex and<br />
f:validateRequired.</P><br />
<P><I>Chapter 3, File Management</I> discusses file management issues. You will see different<br />
methods for downloading and uploading files, learn how to use JSF Core, RichFaces,<br />
PrimeFaces, and Apache Tomahawk. In addition, you will see how to export data to PDF<br />
and Excel, and how to extract data from an uploaded CSV file.</P><br />
<P><I>Chapter 4, Security</I> covers some security issues. You will see how to use the JSF<br />
Security project without JAAS Roles, use secured managed beans with JSF Security, and<br />
use Acegi/Spring security in JSF applications.</P><br />
<P><I>Chapter 5, Custom Components</I> discusses custom components in JSF. You will see how<br />
to build different kinds of custom components in <b>JSF 2.0</b>, Archetypes for Maven, JSF and<br />
Dojo and more.</P><br />
<P><I>Chapter 6, AJAX in JSF</I> starts with the f:ajax tag, continues with Dynamic Faces,<br />
RichFaces, ajax4jsf, and ends up with PrimeFaces and learning to write reusable AJAX<br />
components.</P><br />
<P><I>Chapter 7, Internationalization and Localization</I> covers internationalization and<br />
localization. We will see how to load message resource bundles on JSF pages and how to<br />
use locales and message resource bundles. We then move on to parameterized messages,<br />
learning how to display Arabic, Chinese, Russian, and so on and how to select time zones<br />
in <b>JSF 2.0</b>.</P><br />
<P><I>Chapter 8, JSF, Images, CSS, and JS</I> discusses JSF with images, CSS, JS, and RSS. We<br />
will integrate JS with JSF, pass values between JS and JSF, crop images, work with<br />
dynamic images, work with pop-up windows, RSS support, and so on.</P><br />
<P><I>Chapter 9, JSF—Managing and Testing</I> starts with Faces Console, and moves on to<br />
JSFUnit and JMeter.</P><br />
<P><I>Chapter 10, Facelets</I> covers Facelets recipes. You will see how to work with aliasing<br />
components, templates, composition components, passing actions, and sub-elements to<br />
composition components.</P><br />
<P><I>Chapter 11, <b>JSF 2.0</b> Features</I> presents some of the most relevant <b>JSF 2.0</b> features, such<br />
as annotations, exception handling mechanism, declarative event handling, URLs based<br />
on specified navigation outcome, JSF view parameters, <b>JSF 2.0</b>, and navigation cases.</P><br />
<P><I>Chapter 12, Mixing JSF with Other Technologies</I> discusses mixing JSF with other<br />
important technologies, such as Spring, Seam, JSTL, Hibernate, and EJB (JPA).</P><br />
<P><I>Appendix, Configuring JSF-related Technologies</I> talks about the issues when a JSFrelated<br />
technology gets into the equation. You need to add some specific configuration,<br />
you have to create a &#8220;bridge&#8221; between JSF and the technology used. This appendix<br />
contains the configurations for a few technologies.</P></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<ul>
<li>Explore all the new features of JSF 2.0 that has numerous advantages over JSF 1.2</li>
<li>Work with standard and custom JSF converters and validators</li>
<li>Learn to upload and download with JSF, RichFaces and MyFaces</li>
<li>Work with resources such as CSS, JavaScript and images</li>
<li>Develop sophisticated applications using standard and custom components</li>
<li>Explore AJAX in JSF and related frameworks</li>
<li>Enhance your applications with internationalization and localization</li>
<li>Exploit all of the security tasks in JSF and perform thorough testing of your applications</li>
<li>Get to grips with JSFUnit, JMeter and JXIsight</li>
<li>Integrate JSF with JSTL, Spring and Hibernate</li>
</ul>
<p><H1><CENTER>JSF, Images, CSS, and JS</CENTER></H1><br />
<P>In this chapter, we will cover:</P><br />
<UL><br />
<LI><b>Injecting CSS in JSF</b></LI><br />
<LI><b>JSF, CSS, and tables</b></LI><br />
<LI><b>JSF and dynamic CSS</b></LI><br />
<LI><b>Integrating JavaScript and JSF</b></LI><br />
<LI><b>Getting a JSF inputText value from JavaScript</b></LI><br />
<LI><b>Working with JSF hidden fields from JavaScript</b></LI><br />
<LI><b>Passing parameters from JS to JSF (client to server)</b></LI><br />
<LI><b>Passing parameters from JSF to JS (server to client)</b></LI><br />
<LI><b>Opening a pop-up window using JSF and JS</b></LI><br />
<LI><b>Passing parameters with HTTP GET within the URL</b></LI><br />
<LI><b>Communicating between parent pop-up windows</b></LI><br />
<LI><b>Populating a JS load function with JSF values</b></LI><br />
<LI><b>Dynamic images with PrimeFaces</b></LI><br />
<LI><b>Cropping images with PrimeFaces</b></LI><br />
<LI><b>Working with rss4jsf project</b></LI><br />
<LI><b>Using resource handlers</b></LI><br />
</UL><br />
<H1>Injecting CSS in JSF</H1><br />
<P>In this recipe, you will see how to add CSS styles to JSF tags. It is a simple solution, but it has<br />
the advantage that it can be applied to almost all JSF tags that render text, images, and so on.</P><br />
<H2>Getting ready</H2><br />
<P>We have developed this recipe with NetBeans 6.8, <b>JSF 2.0</b>, and GlassFish v3. The <b>JSF 2.0</b><br />
classes were obtained from the NetBeans <b>JSF 2.0</b> bundled library.</P><br />
<H2>How to do it&#8230;</H2><br />
<P>When you need a simple and classic solution to integrate CSS in JSF it is important to know<br />
that JSF components support the styleClass and style attributes. The styleClass<br />
attribute is used when you are working with CSS classes, while the style attribute allows you<br />
to place CSS code directly in place between quotes.</P><br />
<P>You can see in the following code snippet how this works with the h:outputText component:</P><br />
<P><PRE><CODE><br />
	&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;UTF-8&#8242; ?&gt;<br />
	&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;<br />
		&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;<br />
	&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;<br />
		xmlns:ui=&#8221;http://java.sun.com/jsf/facelets&#8221;<br />
		xmlns:h=&#8221;http://java.sun.com/jsf/html&#8221;<br />
		xmlns:f=&#8221;http://java.sun.com/jsf/core&#8221;&gt;<br />
		&lt;h:head&gt;<br />
			&lt;title&gt;JSF and CSS example&lt;/title&gt;<br />
			&lt;style type=&#8221;text/css&#8221;&gt;<br />
				.message { text-align: left;<br />
					letter-spacing:5px;<br />
					color:#000099<br />
				}<br />
				.message-overline { text-decoration:overline;<br />
				}<br />
				.message-font { font-family:georgia,garamond,serif;<br />
					font-size:20px;<br />
					font-style:italic;<br />
				}<br />
			&lt;/style&gt;<br />
		&lt;/h:head&gt;<br />
		&lt;h:body&gt;<br />
			&lt;h:outputText styleClass=&#8221;message&#8221;<br />
				value=&#8221;This text is CSS formated by &#8216;message&#8217; class!&#8221;/&gt;<br />
			&lt;br /&gt;&lt;br /&gt;<br />
			&lt;h:outputText styleClass=&#8221;message message-overline&#8221;<br />
				value=&#8221;This text is CSS formated by &#8216;message&#8217; and<br />
				&#8216;message-overline&#8217; classes!&#8221;/&gt;<br />
			&lt;br /&gt;&lt;br /&gt;<br />
			&lt;h:outputText styleClass=&#8221;message message-overline message-font&#8221;<br />
				value=&#8221;This text is CSS formated by &#8216;message&#8217;,<br />
				&#8216;message-overline&#8217; and &#8216;message-font&#8217; classes!&#8221;/&gt;<br />
			&lt;br /&gt;&lt;br /&gt;<br />
			&lt;h:outputText style=&#8221;text-align: left;letter-spacing:5px;<br />
				color:#000099&#8243; value=&#8221;This text is CSS formated<br />
				using the &#8216;style&#8217; attribute instead of &#8216;message&#8217; class!&#8221;/&gt;<br />
			&lt;br /&gt;&lt;br /&gt;<br />
			&lt;h:outputText style=&#8221;text-align: left;letter-spacing:5px;<br />
				color:#000099;text-decoration:overline;&#8221;<br />
				value=&#8221;This text is CSS formated using the<br />
				&#8216;style&#8217; attribute instead of &#8216;message&#8217;<br />
				and &#8216;message-overline&#8217; classes!&#8221;/&gt;<br />
			&lt;br /&gt;&lt;br /&gt;<br />
			&lt;h:outputText style=&#8221;text-align: left;letter-spacing:5px;<br />
				color:#000099;text-decoration:overline;<br />
				font-family:georgia,garamond,serif;<br />
				font-size:20px;font-style:italic;<br />
				&#8221; value=&#8221;This text is CSS formated using the<br />
				&#8216;style&#8217; attribute instead of &#8216;message&#8217;,<br />
				&#8216;message-overline&#8217; and &#8216;message-font&#8217; classes!&#8221;/&gt;<br />
			&lt;br /&gt;&lt;br /&gt;<br />
		&lt;/h:body&gt;<br />
	&lt;/html&gt;<br />
</CODE></PRE></P><br />
<P>Notice that when you need to specify more CSS classes under the same styleClass you<br />
need to separate their names by space.</P><br />
<H2>How it works&#8230;</H2><br />
<P>As you can see the JSF – CSS construction looks similar to HTML – CSS usage. The interaction<br />
between JSF – CSS imitates HTML – CSS interaction, but, as you will see in the next recipes,<br />
JSF is more fl exible and supports more kinds of attributes for injecting CSS code in JSF pages.</P><br />
<H2>See also</H2><br />
<P>The code bundled with this book contains a complete example of this recipe. The project can<br />
be opened with NetBeans 6.8 and it is named: Injecting_CSS_in_JSF.</P><br />
<H1>JSF, CSS, and tables</H1><br />
<P>There are two kinds of grids (tables) that are very often used in JSF, h:panelGrid and<br />
h:dataTable. Both of them can be styled with CSS in detail using a set of dedicated<br />
attributes. In this recipe you will see these attributes at work for h:panelGrid, but it<br />
is very simple to extrapolate this to h:dataTable .</P><br />
<H2>Getting ready</H2><br />
<P>We have developed this recipe with NetBeans 6.8, <b>JSF 2.0</b>, and GlassFish v3. The <b>JSF 2.0</b><br />
classes were obtained from the NetBeans <b>JSF 2.0</b> bundled library.</P><br />
<H2>How to do it&#8230;</H2><br />
<P>Suppose that we have an h:panelGrid. We can &#8220;populate&#8221; it with CSS styles, using the<br />
following set of attributes:</P><br />
<P><CENTER><IMG SRC="images/2010/07/JSF/1.jpg"/></CENTER></P><br />
<P>Knowing these attributes, we build a JSF page to show you how to use them in practice<br />
(notice where we have placed the attributes):</P><br />
<P><PRE><CODE><br />
	&lt;?xml version=&#8217;1.0&#8242; encoding=&#8217;UTF-8&#8242; ?&gt;<br />
	&lt;!DOCTYPE html PUBLIC &#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;<br />
		&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;<br />
	&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;<br />
		xmlns:ui=&#8221;http://java.sun.com/jsf/facelets&#8221;<br />
		xmlns:h=&#8221;http://java.sun.com/jsf/html&#8221;<br />
		xmlns:f=&#8221;http://java.sun.com/jsf/core&#8221;&gt;<br />
		&lt;h:head&gt;<br />
			&lt;title&gt;JSF and CSS example&lt;/title&gt;<br />
			&lt;style type=&#8221;text/css&#8221;&gt;<br />
				.message { text-align: left;<br />
					letter-spacing:5px;<br />
					color:#000099<br />
				}<br />
				.message-font { font-family:georgia,garamond,serif;<br />
					font-size:20px;<br />
					font-style:italic;<br />
				}<br />
				.odd { background-color: blue }<br />
				.even { background-color: red }<br />
			&lt;/style&gt;<br />
		&lt;/h:head&gt;<br />
		&lt;h:body&gt;<br />
			&lt;h:form&gt;<br />
				&lt;h:panelGrid columns=&#8221;3&#8243; border=&#8221;1&#8243; footerClass=&#8221;message&#8221;<br />
					headerClass=&#8221;message-font&#8221; rowClasses=&#8221;odd, even&#8221;<br />
					title=&#8221;PanelGrid and CSS&#8221;&gt;<br />
					&lt;f:facet name=&#8221;header&#8221;&gt;<br />
						&lt;h:outputText value=&#8221;Fill Names Below&#8221;/&gt;<br />
					&lt;/f:facet&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
					&lt;h:inputText/&gt;<br />
						&lt;f:facet name=&#8221;footer&#8221;&gt;<br />
							&lt;h:outputText value=&#8221;The End&#8221;/&gt;<br />
						&lt;/f:facet&gt;<br />
				&lt;/h:panelGrid&gt;<br />
			&lt;/h:form&gt;<br />
		&lt;/h:body&gt;<br />
	&lt;/html&gt;<br />
</CODE></PRE></P><br />
<H2>How it works&#8230;</H2><br />
<P>Since we have an attribute for each part of a grid, we can easily specify CSS styles to<br />
customize the design of each of these parts. JSF will combine the specified CSS styles to<br />
render a cool grid to the user.</P><br />
<H2>There&#8217;s more&#8230;</H2><br />
<P>The h:dataTable allows you to use the same CSS attributes for table header, footer,<br />
and so on.</P><br />
<H2>See also</H2><br />
<P>The code bundled with this book contains a complete example of this recipe. The project can<br />
be opened with NetBeans 6.8 and it is named: JSF_CSS_and_tables</P></p>
<h1>JSF Articles</h1>
<ul>
<li><a href="http://www.javabeat.net/articles/jsf/1/">JSF Articles</a></li>
<li><a href="http://www.javabeat.net/articles/57-accessing-web-services-from-jsf-applications-1.html">Accessing Web Services from JSF applications</a></li>
<li><a href="http://www.javabeat.net/articles/11-introduction-to-java-server-faces-1.html">Introduction to Java Server Faces</a></li>
<li><a href="http://www.javabeat.net/articles/15-introduction-to-jsf-core-tags-library-1.html">Introduction to JSF Core Tags Library</a></li>
<li><a href="http://www.javabeat.net/articles/17-introduction-to-java-server-facesjsf-html-tags-1.html">Introduction to Java Server Faces(JSF) HTML Tags </a></li>
<li><a href="http://www.javabeat.net/articles/21-ajax-support-in-struts-20-1.html">AJAX Support in Struts 2.0</a></li>
<li><a href="http://www.javabeat.net/articles/53-using-converters-in-jsf-1.html">Using Converters in JSF</a></li>
<li><a href="http://www.javabeat.net/articles/54-request-processing-lifecycle-phases-in-jsf-1.html">Request Processing Lifecycle phases in JSF</a></li>
</ul>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/07/jsf-2-0-images-css-and-java-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache MyFaces 1.2</title>
		<link>http://www.javabeat.net/2010/06/apache-myfaces-1-2/</link>
		<comments>http://www.javabeat.net/2010/06/apache-myfaces-1-2/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 00:26:24 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=1950</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Apache MyFaces 1.2 Web Application Development Hypes and trends (such as Web 2.0) cause a change in the requirements for user interfaces every now and then. Although a lot of frameworks are capable of meeting these changing requirements, they often mean that you, as a developer, need in-depth knowledge of web standards, such as XHTML [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><H1><CENTER>Apache <b>MyFaces</b> 1.2</CENTER></H1><br />
<H1><CENTER>Web Application Development</CENTER></H1><br />
<P>Hypes and trends (such as Web 2.0) cause a change in the requirements for user<br />
interfaces every now and then. Although a lot of frameworks are capable of meeting<br />
these changing requirements, they often mean that you, as a developer, need in-depth<br />
knowledge of web standards, such as XHTML and JavaScript. Apache <b>MyFaces</b> hides all<br />
of the details of how the page is rendered at the client, and at the same time offers a rich<br />
set of tools and building blocks. This can save you a lot of time not only when you’re<br />
building a brand-new application, but also when you’re adapting an existing application<br />
to meet new user interface requirements.</P><br />
<P>This book will teach you everything that you need to know in order to build appealing<br />
web interfaces with Apache <b>MyFaces</b>, and to maintain your code in a pragmatic way. It<br />
describes all of the steps that are involved in building a user interface with Apache<br />
<b>MyFaces</b>. This includes building templates and composition components with Facelets,<br />
and using all sorts of specialized components from the Tomahawk and Trinidad<br />
component sets. Adding validation with <b>MyFaces</b> Extensions Validator as well as using<br />
<b>MyFaces</b> Orchestra to manage transactions in a page fl ow, are also covered.</P><br />
<P>Unlike comparable books, this book not only introduces Facelets as an alternative to JSP,<br />
but actually uses Facelets in all the examples throughout this book. This makes the book<br />
a valuable resource for Facelets examples. The book also shows how various components<br />
of the <b>MyFaces</b> project can be used together, in order to deliver the functionality of the<br />
new <b><b>JSF</b> 2.0</b> standard, in current projects, without the need to upgrade<br />
your project to <b><b>JSF</b> 2.0</b>.</P><br />
<P>This book uses a step-by-step approach, and contains a lot of tips based on experience of<br />
the <b>MyFaces</b> libraries in real-world projects. Throughout the book, an example scenario<br />
is used to work towards a fully-functional application by the end of this book.</P><br />
<P>This step-by-step guide will help you to build a fully-functional and powerful application.</P><br />
<H1>What This Book Covers</H1><br />
<P>Chapter 1, <I>Introduction</I>, introduces the Apache <b>MyFaces</b> project and all of its<br />
subprojects. Forward references to other chapters are given wherever applicable.</P><br />
<P>Chapter 2, <I>Getting Started</I>, discusses downloading and installing the <b>MyFaces</b> libraries.<br />
The set-up of two specific IDEs is discussed, as well as the set-up of an application<br />
server for testing. This chapter also covers the use of Maven and the Maven artifacts that<br />
are provided by the <b>MyFaces</b> project.</P><br />
<P>Chapter 3, <I>Facelets</I>, covers the installation of Facelets into our project. It discusses the<br />
benefits of Facelets over JavaServer Pages as a view technology for JavaServer Faces.<br />
This chapter also introduces the most important features of Facelets. By the end of the<br />
chapter, we have created a layout template that we can use throughout the book, when<br />
developing our application. We will also have learned the basic Facelets techniques that<br />
we will use in all examples throughout the book.</P><br />
<P>Chapter 4, <I>Tomahawk</I>, looks at the Tomahawk component set that is a part of <b>MyFaces</b>.<br />
Some of the most important components from the set are covered, and we will learn how<br />
we can use these in an optimal way, in combination with Facelets. This chapter gives us<br />
enough information to build fully-functional <b>JSF</b> pages by using Tomahawk components.</P><br />
<P>Chapter 5, <I>Trinidad—the Basics</I>, is the first of three chapters covering <b>MyFaces</b><br />
Trinidad. This chapter introduces a lot of Trinidad components, including the data input<br />
and output components. Special attention is given to the many layout components that are<br />
available in the Trinidad library. As with Tomahawk, we will see how we can get the<br />
most out of the combination of Trinidad and Facelets.</P><br />
<P>Chapter 6, <I>Advanced Trinidad</I>, introduces some more advanced features of the Trinidad<br />
library. This includes the charting component that can be used to easily create nice<br />
looking charts. Also, Trinidad’s page fl ow scope feature, which enables us to create page<br />
fl ows more easily, is introduced. This chapter also discusses the AJAX or Partial Page<br />
Rendering capabilities of Trinidad, including client-side validation and conversion. The<br />
Trinidad dialog framework is also covered.</P><br />
<P>Chapter 7, <I>Trinidad Skinning and Tuning</I>, is an introduction to the advanced skinning<br />
framework that is a part of Trinidad. This chapter also discusses the most important<br />
tuning parameters of Trinidad.</P><br />
<P>Chapter 8, <I>Integrating with the Backend</I>, discusses how we can integrate the frontend that<br />
we created with some backend system, in a standard way. This chapter gives us some<br />
basic knowledge about the Model-View-Controller architecture, and about important<br />
standards such as Enterprise Java Beans (EJB) and the Java Persistence API (JPA). We<br />
will use the knowledge and examples from this chapter as a starting point for the more<br />
advanced integration topics discussed in the subsequent chapters.</P><br />
<P>Chapter 9, <I><b>MyFaces</b> Orchestra</I>, introduces the <b>MyFaces</b> Orchestra library. This chapter<br />
starts with a very brief introduction to the Spring framework, as Orchestra is based on<br />
parts of that framework. We see how we can create a Spring application context and then<br />
how we should use such a context in combination with Orchestra. Some key concepts of<br />
Orchestra are introduced, such as the Orchestra ViewController concept and the concept<br />
of conversations. This chapter concludes with a quick view of Orchestra’s DynaForm<br />
component.</P><br />
<P>Chapter 10, <I>Extensions Validator</I>, is about one of the latest additions to the <b>MyFaces</b><br />
project: the Extensions Validator, or ExtVal for short. This chapter starts by teaching us<br />
how to configure our project to use ExtVal. We see how JPA annotations can be used to<br />
automatically generate <b>JSF</b> validations. This chapter also shows us the extra annotations<br />
that ExtVal offers to complement the JPA annotations. This chapter also shows how we<br />
can use Bean Validation (JSR 303) annotations as an alternative to JPA and ExtVal<br />
annotations. As a whole, this chapter is a good introduction to this very fl exible and<br />
versatile member of the <b>MyFaces</b> family.</P><br />
<P>Chapter 11, <I>Best Practices</I>, is the last chapter of this book. It discusses some best<br />
practices with <b>JSF</b> in general and <b>MyFaces</b> in particular. This chapter describes a way to<br />
prevent direct access to page definitions, as well as a way to enable container-based<br />
security in our <b>JSF</b> application. This chapter also shows how to create a login page by<br />
using <b>JSF</b> components, and discusses how to use component bindings wisely. This<br />
chapter concludes by discussing how to save the state of request-scoped components in<br />
an elegant way.</P><br />
<P>Appendix A, <I>XHTML Entities</I>, lists all of the numeric entities that can be used in XML<br />
documents. This list may be needed because Facelets files must be valid, plain XML<br />
files, and can’t contain named entities that can be used in normal XHTML files.</P><br />
<P>Appendix B, <I>Trinidad Tags</I>, gives a list of all of the tags from the Trinidad library. This<br />
can be referred to if you forget the exact name of one of the many tags. It can also be<br />
used to determine if a certain Trinidad tag is a naming container.</P><br />
<P>Appendix C, <I>Trinidad Text Keys</I>, lists the keys that Trinidad uses to lookup the default<br />
texts that are displayed on components. These keys can be used to customize or translate<br />
the default texts.</P><br />
<P>Appendix D, <I>Default <b>JSF</b> Error Messages</I>, gives an overview of the default error messages<br />
that are defined in the <b>JSF</b> standard. This list can be used if you want to customize or<br />
translate the default messages. This may also be useful in combination with the <b>MyFaces</b><br />
Extensions Validator.</P><br />
<P>Appendix E, <I>ExtVal Default Error Messages</I>, contains a list of the default error messages<br />
that are defined by the Extensions Validator for use with its custom validation<br />
annotations. This can be useful if you want to override the default messages.<br />
<H1><CENTER>Extensions Validator</CENTER></H1><br />
<P>A common problem with the <B>Model-View-Controller pattern (MVC)</B> is that often<br />
the <B>Don’t Repeat Yourself (DRY)</B> principle is violated when it comes to validation<br />
of data. The “single source of truth” with regards to validation is often either the<br />
Model layer or the underlying database. But to be able to give the user usable,<br />
easy-to-understand error messages, and to give those in a timely manner, we<br />
often need to repeat a lot of validation in the View layer.</P><br />
<P>This often leads to inconsistencies in applications when the validation code in the<br />
Model and View layers gets out of sync. This can happen because of a changed<br />
business rule that is implemented in the Model, but the View is not updated<br />
accordingly. Or if the View is redesigned, unintentional changes in the validation<br />
can occur. Even when Model and View are created at the same time but by different<br />
engineers, crippled communication between those engineers can lead to validation<br />
code that is out of sync.</P><br />
<P>Repeating validation logic in the View layer also breaks the DRY principle at another<br />
level. Often, information from a certain bean can be edited in different pages in the<br />
user interface. This means that the validation has to be repeated in all of those UI<br />
pages. So we can end up repeating the same validation logic in different pages.</P><br />
<P>Wouldn’t it be better if we didn’t have to repeat our validation code in the View<br />
layer while keeping usable error messages, and having the validation still taking<br />
place on the client side? This is the main reason that the <B>“Extensions Validator”</B><br />
project was added to <b>MyFaces</b>. The word “Extensions” refers to the fact that this<br />
project is not about <b>JSF</b> components, but rather has to be seen as an extension to the<br />
<b>JSF</b> Framework. The idea is that more projects can be added in the future, as further<br />
extensions. However, for now, Validator is the only project under the “MyFaces<br />
Extensions” umbrella that has released any software yet. As “Extensions Validator”<br />
is a long name, the project is most of the time referred to as <B>“ExtVal”</B>. We’ll use this<br />
short name throughout this chapter.</P><br />
<P>After reading this chapter, you will be able to:</P><br />
<UL><br />
<LI>Set up a project to use ExtVal</LI><br />
<LI>Use ExtVal to generate validation based on JPA annotations</LI><br />
<LI>Use ExtVal’s added annotations for additional validation</LI><br />
<LI>Implement cross validation using ExtVal’s annotations</LI><br />
<LI>Use ExtVal with custom <b>JSF</b> validators</LI><br />
<LI>Create custom error messages for ExtVal validations</LI><br />
<LI>Override and extend ExtVal’s default behavior</LI><br />
<LI>Use Bean Validation (JSR 303) annotations in combination with ExtVal</LI><br />
<LI>Use metadata to set the severity level of constraints</LI><br />
</UL><br />
<H1>Setting up ExtVal</H1><br />
<P>As with all other libraries, we start by downloading ExtVal and installing it in our<br />
project. As with many other <b>JSF</b> libraries, the ExtVal project has different branches<br />
for <b>JSF</b> 1.1 and 1.2. The first two digits of ExtVal’s version number are the <b>JSF</b> version<br />
they are made for. So ExtVal 1.1.x is the xth version of ExtVal for <b>JSF</b> 1.1, whereas<br />
ExtVal 1.2.x is the xth version for <b>JSF</b> 1.2. Versions of ExtVal are not released very<br />
often. At the time of writing this book, only two official releases have been published<br />
for each branch. According to the lead developer of ExtVal, a third release (1.1.3 and<br />
1.2.3) is in the works for both branches, as well as a first release from the new <b><b>JSF</b> 2.0</b><br />
branch.</P><br />
<P>Apart from stable releases, ExtVal offers snapshot builds that are created on a regular<br />
basis. The snapshots are created manually, which gives some guarantees about the<br />
quality compared to automatically-created daily releases. No snapshots with major<br />
bugs will be created. According to the lead developer of ExtVal, the snapshot builds<br />
have “milestone quality”.</P><br />
<P>Because of some issues and limitations in ExtVal 1.2.2, a snapshot build of ExtVal<br />
1.2.3 was used while writing this chapter. A stable release of ExtVal 1.2.3 is expected<br />
to be available soon after the publishing date of this book. Stable releases can be<br />
downloaded from the ExtVal download site at http://myfaces.apache.org/<br />
extensions/validator/download.html. The downloaded ZIP file will contain all<br />
of the ExtVal modules, as listed in the next table. Note that more modules may be<br />
added to ExtVal in future releases. It is also possible that additional support modules<br />
will be provided by others. For example, a <b>JSF</b> component project may create a<br />
support module to get the most out of its components with ExtVal.</P><br />
<P>Regarding component support modules, it is also worth mentioning the “Sandbox<br />
890” project, which provides proof of concept implementations of support modules<br />
for some non-MyFaces component libraries. Currently, proofs of concept are<br />
available for IceFaces, PrimeFaces, RichFaces, and OpenFaces. The source code for<br />
the proofs of concept can be found at http://code.google.com/p/sandbox890/<br />
source/browse/#svn/trunk/component-support. Ready-to-use JARs can be<br />
downloaded from http://code.google.com/p/os890-m2-repository/source/<br />
browse/#svn/trunk/sandbox890/sandbox890/extensions/validator/<br />
component-support-modules.</P><br />
<P><CENTER><IMG SRC="images/2010/06/ApacheMyFaces/1.jpg"/></CENTER></P><br />
<P><CENTER><IMG SRC="images/2010/06/ApacheMyFaces/2.jpg"/></CENTER></P><br />
<P>Snapshot builds of ExtVal can be downloaded from ExtVal’s Maven snapshot<br />
repository, which can be found at http://people.apache.org/maven-snapshotrepository/<br />
org/apache/myfaces/extensions/validator/. In the case<br />
of snapshot builds, no single ZIP file is available, and each module has to be<br />
downloaded separately as a JAR file. Note that if Maven is used, there is no need<br />
to manually download the snapshots. In that case, we only have to change the<br />
version number in the pom.xml file to a snapshot version number, and Maven will<br />
automatically download the latest snapshot. The following table lists the URLs<br />
within the Maven repository from where the modules can be downloaded:</P><br />
<P><CENTER><IMG SRC="images/2010/06/ApacheMyFaces/3.jpg"/></CENTER></P><br />
<P>URLs in this table are relative to the URL of the Maven repository that we just<br />
saw. After each URL, 1.2.x-SNAPSHOT/ has to be appended, where 1.2.x has to<br />
be replaced by the appropriate version number.</P><br />
<P>Once we’ve finished downloading, we can start adding the JARs to our project.<br />
ExtVal differs in one thing from other libraries—it needs to access our Model and<br />
View project. So we have to add the ExtVal libraries to the lib directory of the EAR,<br />
instead of the WAR or the JAR with the entities. Some libraries that ExtVal uses have<br />
to be moved there as well. If we don’t do this, we’ll end up with all sorts of weird<br />
exceptions related to class-loading errors.?</P><br />
<P>Libraries that are added to the lib directory of an EAR are automatically available to<br />
all contained WAR and JAR files. However, depending on the IDE and build system<br />
that we are using, we may have to take some additional steps to be able to build the<br />
WAR and JAR with dependencies to the libraries in the EAR’s lib directory.</P><br />
<P><CENTER><IMG SRC="images/2010/06/ApacheMyFaces/4.jpg"/></CENTER></P><br />
<P>This image shows a simplified structure of the EAR with ExtVal’s libraries added<br />
to it. Note that the <B><b>MyFaces</b> ExtVal and dependencies</B> node in the image actually<br />
represents multiple JAR files. It is important to verify that none of the libraries<br />
that are in the lib directory of the EAR are included in either the WAR or the<br />
entities JAR. Otherwise, we could still encounter class-loading confl icts. The<br />
following table lists all of the libraries that have to be moved into the EAR to<br />
avoid these class-loading confl icts:</P><br />
<P><CENTER><IMG SRC="images/2010/06/ApacheMyFaces/5.jpg"/></CENTER></P><br />
<P><PRE><CODE><br />
	Note that the aforementioned changes in our project structure are<br />
	necessary only because we chose to have our Model layer in a separate<br />
	JAR file. In smaller projects, it is often the case that the whole project<br />
	is deployed as a single WAR file without enclosing it in an EAR. If we<br />
	had chosen that strategy, no changes to the structure would have been<br />
	necessary and we could have added all of the libraries to the WAR file,<br />
	as we would do with any other library.<br />
</CODE></PRE></P><br />
<P>Other than including the necessary libraries as discussed before, no configuration is<br />
needed to get started with ExtVal. ExtVal uses the <B>convention over configuration</B><br />
pattern extensively. That means, a lot of sensible defaults are chosen, and as long as<br />
we’re satisfied with the defaults, no configuration is needed. The next section will get<br />
us started with some basic ExtVal usage.</P><br />
<P><PRE><CODE><br />
	<B>Bug with Trinidad tables</B><br />
	There’s a bug in ExtVal that can cause some weird behavior in Trinidad’s<br />
	&lt;tr:table&gt; component. Only the first row will be populated with<br />
	data, and other rows will not show any data. This happens only when a<br />
	Facelets composite component is used to add the columns to the table—<br />
	exactly what we do in our example application. The bug can be found<br />
	in the JIRA bug tracker for ExtVal at https://issues.apache.org/<br />
	jira/browse/EXTVAL-77. There’s a workaround for the bug that we<br />
	can use until it gets fixed. Be warned that this workaround may have<br />
	other side effects.<br />
	This workaround is shown in the following code snippet, in which we<br />
	have created a class called DevStartupListener:<br />
	public class DevStartupListener extends<br />
		AbstractStartupListener {<br />
			@Override<br />
			protected void init() {<br />
				ExtValContext.getContext()<br />
					.addGlobalProperty(ExtValRendererProxy.KEY,<br />
						null, true);<br />
			}<br />
		}<br />
	The required imports are in the org.apache.myfaces.extensions.<br />
	validator.core package and subpackages. Register this class as a<br />
	phase listener in the faces-config.xml file:<br />
		&lt;lifecycle&gt;<br />
			&lt;phase-listener&gt;<br />
				inc.monsters.mias.workaround.DevStartupListener<br />
			&lt;/phase-listener&gt;<br />
		&lt;/lifecycle&gt;<br />
	You’re all set, and the &lt;tr:table&gt; will now act as expected. Don’t<br />
	forget to remove this workaround if the bug gets fixed in a future release<br />
	of ExtVal.<br />
</code></pre>
</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><H1>Basic usage</H1><br />
<P>After setting up ExtVal, the basic usage is very simple. Let’s explore a simple<br />
example in our MIAS application. In our Kid.java entity, we have some JPA<br />
annotations that map the properties of the Kid bean to a database table. Let’s take a<br />
closer look at the lastName property of our Kid bean:</P><br />
<P><PRE><CODE><br />
	@Column(name = "LAST_NAME", nullable = false, length = 30)<br />
	private String lastName;<br />
</CODE></PRE></P><br />
<P>The @Column annotation maps the lastName property to the LAST_NAME column in<br />
the database. It also shows some information that is derived from the table definition<br />
in the database. nullable = false means the database won’t accept an empty value<br />
in this field, and length = 30 means that no more than 30 characters can be stored in<br />
the corresponding database column. This information could be used for validation in<br />
our View layer. If we hadn’t used ExtVal, we would have added a required="true"<br />
attribute to the input element in our EditKid.xhtml page. We also would have<br />
added a &lt;tr:validateLength&gt; component to the input component, or we could<br />
have set the maximumLength attribute. But all of these things would have been a<br />
duplication of information and logic, and would thus break the DRY principle.</P><br />
<P>With ExtVal, we don’t have to duplicate this information anymore. Whenever ExtVal<br />
encounters a nullable = false setting, it will automatically add a required="true"<br />
attribute to the corresponding input element. In the same way, it will translate<br />
the length = 30 from the @Column annotation into a maximumLength attribute on<br />
the input component. The next screenshot shows ExtVal in action. (Note that all<br />
validators, and the required and maximumLength attributes were removed from the<br />
<b>JSF</b> code before the screenshot was taken.) The really nice thing about this example<br />
is that the validations created by ExtVal make use of Trinidad’s client-side validation<br />
capabilities. In other words, the error message is created within the user’s web<br />
browser before any input is sent to the server.</P></p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/06/apache-myfaces-1-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tags and Tag Attributes in Apache MyFaces Trinidad 1.2</title>
		<link>http://www.javabeat.net/2009/11/apache-myfaces-trinidad-1-2/</link>
		<comments>http://www.javabeat.net/2009/11/apache-myfaces-trinidad-1-2/#comments</comments>
		<pubDate>Sat, 21 Nov 2009 00:43:45 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Java Server Faces (JSF)]]></category>
		<category><![CDATA[MyFaces Trinidad 1.2]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=1970</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Apache MyFaces Trinidad 1.2In this book, you will learn how Facelets and Seam are used to get the most out of JSF. You start out by learning where Trinidad comes from and what its aims are. Additionally, you will also learn the often occurring tag attributes and, in particular, Trinidad&#8217;s Ajax technology. You will implement login, authorization, navigation, [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><center><strong>Apache MyFaces Trinidad 1.2</strong></center>In this book, you will learn how Facelets and Seam are used to get the most out of JSF. You start out by learning where Trinidad comes from and what its aims are. Additionally, you will also learn the often occurring tag attributes and, in particular, Trinidad&#8217;s Ajax technology. You will implement login, authorization, navigation, internationalization, polling and browser issues with the help of these technologies. You will then use Seamgen for deployment.</p>
<p>As you move through the book, you will develop a web application example where a series of selected Trinidad components are applied and their capabilities explored.Finally, you will master the Trinidad dialog framework, a Trinidad key technology that allows the application of dialogs.</p>
<p><strong>What This Book Covers</strong></p>
<p><i>Chapter 1, Introducing Trinidad,</i> introduces you to the Trinidad component library. We give a general idea of this component library, the areas covered by its components, and compare it to other libraries. Finally, the integration of Trinidad and Seam is discussed.</p>
<p><i>Chapter 2, Structuring and Building Pages with Facelets,</i> explains Facelets as a basic means to structure and build pages using Facelet page composition, Facelet composition components, and JSTL.</p>
<p><i>Chapter 3, Most Wanted Tags and Tag Attributes,</i> discusses the Trinidad tags and theirattributes in a structured approach. You will gain an insight into the design of Trinidad allowing you to draw an efficient mental map of the library and make an effective selection and application of tags.</p>
<p><i>Chapter 4, Rendering Pages Partially,</i> introduces you to the Trinidad&#8217;s Ajax technology called PPR (Partial Page Rendering). PPR is inspected from two points of view—the pure tag-based partial rendering and the pure Java-side partial rendering techniques.</p>
<p><i>Chapter 5, Web Application Groundwork,</i> teaches you how to develop the basic parts of the web application that serves as our Trinidad example. We present using Seam-gen to rapidly deploy after each change of any file.</p>
<p><i>Chapter 6, Building a Panel-based Content,</i> deals with Trinidad&#8217;s panelAccordion and showDetailItem components to show how they can be combined to build panel-based, panel-wise collapsible content.</p>
<p><i>Chapter 7, Building a Form,</i> discusses the combinination of Trinidad&#8217;s tags to Facelet composition components to build highly flexible and well-formatted forms, including messaging support.</p>
<p><i>Chapter 8, Growing a Tree,</i> deals with Trinidad&#8217;s tree components and models and exemplify their application. We present an effective shortcut that makes Trinidad&#8217;s tree support an easy, and yet powerful, technology.</p>
<p><i>Chapter 9, The table and treeTable Components,</i> gives an insight to Trinidad&#8217;s table and treeTable components and exemplifies their application. We apply the components in an increasingly refined way, revealing most of their features one at a time.</p>
<p><i>Chapter 10, The Chart Component,</i> deals with Trinidad&#8217;s chart component and shows its application. You will learn to competently set up representation parameters, effectively achieving the intended representation focus and thus graphically materializing hidden<br />
information in an appropriate way.</p>
<p><i>Chapter 11, Building a Wizard,</i> deals with Trinidad&#8217;s components to implement a wizard and show their application. We present a solution to avoid an existing Facelet problem.</p>
<p><i>Chapter 12, Dialogs—Pop Up Your Web Application,</i> discusses Trinidad&#8217;s pop-up window techniques. We revisit Seam conversations to address the specific necessities for pop-up dialogs in Trinidad and Seam. We enhance the web application with a couple of pop-up windows including wizard pop-up support.</p>
<p><i>Appendix, References,</i> provides us with useful references and links related to Apache MyFaces Trinidad.</p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #000080; text-decoration: underline;">Most Wanted Tags and Tag Attributes</span></span></h2>
<p>This chapter discusses the Trinidad tags and their attributes in a structured approach. The reader will gain an insight into the design of Trinidad allowing them to draw an efficient mental map of the library and an effective selection and application of tags. More concretely, the following topics are covered:</p>
<ul>
<ul>
<li>An overview of the XHTML-focused Trinidad namespace trh</li>
</ul>
</ul>
<ul>
<ul>
<li>An overview of the central Trinidad namespace tr</li>
</ul>
</ul>
<ul>
<ul>
<li>An orientation and classification on the attributes supported by Trinidad</li>
</ul>
</ul>
<h2>Component library structure</h2>
<p>Trinidad&#8217;s approach to web technology is comprehensive: Aimed at full control of all the bits and pieces that make up a web application, little should be left that needs to be added. So based on such a closed world, Trinidad presents itself with a wealth of components and tags that even include very basic XHTML tags as replacements for the real XHTML originals. This is no radical replacement approach, rather it enables Trinidad to remain in full control of mechanisms such as partial-page rendering (PPR, also generally known as Ajax) that otherwise would need to deal with potentially incompatible libraries externally (refer to Chapter 1, <i>Introducing Trinidad</i>, for further discussion).</p>
<p>The following image provides an outline of Trinidad&#8217;s structural package design:</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2009/11/myFaces-trinidad-1.jpg"><img class="aligncenter  wp-image-6617" alt="myFaces-trinidad-1" src="http://www.javabeat.net/wp-content/uploads/2009/11/myFaces-trinidad-1.jpg" width="458" height="201" /></a></center>Trinidad is divided into the following two namespaces:</p>
<ul>
<ul>
<li>tr: It is the usual tag library id that references Trinidad&#8217;s core library tags. It&#8217;s a large library of over 100 components ranging from layout components and navigational components, to special viewer components that all implicitly support skinning, partial-page rendering, popup dialogs, error or info messaging, and so on.</li>
</ul>
</ul>
<ul>
<ul>
<li>trh: It is the usual tag library id that references Trinidad&#8217;s XHTML supportlibrary tags, a small companion that offers alternatives for those XHTML tags that are usually applied to build XHTML structures, for example, XHTML tables.</li>
</ul>
</ul>
<p>Let us take a closer look at both namespaces. The upcoming image shows the core API&#8217;s hierarchical structure. The tags are backed by two types of Trinidad classes—UIX* classes that deal with the JSF component requirements to implement specific JSF lifecycle processing methods, and Core* classes that deal with the specific properties (getters or setters).</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2009/11/myFaces-trinidad-2.jpg"><img class="aligncenter  wp-image-6618" alt="myFaces-trinidad-2" src="http://www.javabeat.net/wp-content/uploads/2009/11/myFaces-trinidad-2.jpg" width="401" height="338" /></a></center></p>
<h2>Trinidad’s XHTML tag library namespace (trh)</h2>
<p>Two groups can be distinguished from the trh namespace. The first one deals with the definition of an XHTML page and provides the developer with the following tags:</p>
<ul>
<ul>
<li>&lt;trh:html&gt;: It is used to define the whole XHTML page, analogous to &lt;html&gt;</li>
</ul>
</ul>
<ul>
<ul>
<li>&lt;trh:head&gt;: It is used to define the header, analogous to &lt;head&gt;</li>
</ul>
</ul>
<ul>
<ul>
<li>&lt;trh:body&gt;: It is used to define the main contents, analogous to &lt;body&gt;</li>
</ul>
</ul>
<ul>
<ul>
<li>&lt;trh:script&gt;: It is used to define a JavaScript to be executed, analogous to &lt;script&gt;</li>
</ul>
</ul>
<p>The second group deals with the layout of an XHTML table:</p>
<ul>
<ul>
<li>&lt;trh:tableLayout&gt;: It is used to define an XHTML table.</li>
</ul>
</ul>
<ul>
<ul>
<li>&lt;trh:rowLayout&gt;: It is used to define an XHTML table line, analogous to &lt;tr&gt;; note that it can also be used to display an arbitrary line, particularly when elements need to be kept in one and the same line. Alternatively, it is particularly interesting to look at the tr namespace as it provides some less heavy structures free from table constructions, for instance panelGroupLayout with a layout set to vertical or a panelBorderLayout, both generating div structures instead.</li>
</ul>
</ul>
<ul>
<ul>
<li>&lt;trh:cellFormat&gt;: It is used to define an XHTML table cell as part of an XHTML table.</li>
</ul>
</ul>
<pre><code>	The attributes of each tag are defined in a most consistent, and thus
	recognizable, way that will be seen in detail later in this book. By
	the way, there are also tags for the construction of framesets such as
	trh:frame in case anyone still wants to make use of framesets </code></pre>
<p>However, before we deal with the attributes let us conclude this structural over view by a look at the organization of the functionality of the core tag library.</p>
<h2>Trinidad’s core tag library namespace (tr)</h2>
<p>The following groups can be functionally distinguished which is also refl ected in the packages structure of Trinidad&#8217;s API (all beginning with org.apache.myfaces. trinidad.component; which has been left out here to avoid repetition). Note that, for completeness, we will also include information on the pure Java side as well as information on the few components that stem from the trh namespace:</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<ul>
<ul>
<li>Basic document composition tags from the core API: document, stylesheet, form, subform. poll also appears here although it is not a composition tag.</li>
</ul>
</ul>
<ul>
<ul>
<li>Form input and display tags, components from the core.input API: inputText, inputDate, inputListOfValues, and so on.</li>
</ul>
</ul>
<ul>
<ul>
<li>Command or navigation tags from core.nav that includes two tag types:</li>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>One that is focused on command tags that assumes a given form, presupposing the use of form and display tags from the foregoing group—commandButton, commandLink, goButton, goLink, and so on.</li>
</ul>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>The other deals exclusively with navigation: navigationTree, navigationPane, breadCrumbs, and so on.</li>
</ul>
</ul>
</ul>
<ul>
<ul>
<li>Large input and output component tags from core.data, for example, table, tree, and treeTable components.</li>
</ul>
</ul>
<ul>
<ul>
<li>Layout component tags from core.layout, for example, all the swinglike panel tags, such as panelBorderLayout, panelHorizontalLayout, panelAccordion, showDetail, showDetailItem, and so on.</li>
</ul>
</ul>
<ul>
<ul>
<li>Basic output components from core.output that are almost always used in a web application, for example, messages, outputText, outputLabel, spacer, statusIndicator, and so on.</li>
</ul>
</ul>
<ul>
<ul>
<li>Model objects from core.model devised for various tags ; they provide the corresponding view models for their tag viewer counterparts, for example, SortableModel CollectionModeland RowKeySet for tr:table,ChildPropertyTreeModel for tr:tree and ChartModel for tr:chart.</li>
</ul>
</ul>
<ul>
<ul>
<li>A couple of converter components from trinidad.convert equip JSF and Trinidad input components with powerful JSF conversion, that is, convertNumber and convertDateTime.</li>
</ul>
</ul>
<ul>
<ul>
<li>Validator components from trinidad.validator equip JSF and Trinidad input components with powerful JSF validation such as range validation (validateDateTimeRange) and validation by regular expression match (validateRegExp).</li>
</ul>
</ul>
<ul>
<ul>
<li>Events and event listeners from trinidad.event add new event types and listeners specific for Trinidad components such as those that support Trinidad&#8217;s dialog framework, for example, commandButton to launch a popup dialogue using LaunchEvent, ReturnEvent, and ReturnListener. It provides only a few tags, but these can be very utile, for example, fileDownloadActionListener, resetActionListener, returnActionListener, and setActionListener.</li>
</ul>
</ul>
<p>There is a lot more to be found on the pure Java API side that either surfaces indirectly on the tag library as attributes, or is used implicitly by the tags themselves. Furthermore, there are utility classes and context support classes—RequestContext being probably the most prominent one because it offers a lot of functionality, for example, PPR from the server side. This is described in the upcoming chapter.</p>
<p>The following figure illustrates the Java side of things (it shows what the structure of some of the classes behind core.input look like):</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2009/11/myFaces-trinidad-3.jpg"><img class="aligncenter  wp-image-6619" alt="myFaces-trinidad-3" src="http://www.javabeat.net/wp-content/uploads/2009/11/myFaces-trinidad-3.jpg" width="370" height="390" /></a></center>The preceding figure is an outline of the core.input API hierarchy. Again, we can see the typical UIX* and Core* structure.</p>
<p>Finally, let us take a closer look at the tag attributes.</p>
<h2>Standard tag attributes</h2>
<p>We begin by taking a closer look at the attributes that practically always occur, no matter which tag is actually involved.</p>
<pre><code>	As mentioned before, this occurrence is because of Trinidad's
	design which is noted by its consequent application of attributes
	that are shared by many different tags.</code></pre>
<p>The following attributes occur almost always:</p>
<ul>
<ul>
<li>id: As it is already known from JSF itself, it ought to be set in most cases as it is used by Trinidad itself to identify the component. However, if it is not set by the developer, Trinidad sets up arbitrary, but not very legible, IDs.</li>
</ul>
</ul>
<ul>
<ul>
<li>rendered: Typical for JSF; it is a Boolean attribute that allows setting if the component is to become part of the page sent to the client—in other words if it is considered by the Trinidad renderer.</li>
</ul>
</ul>
<ul>
<ul>
<li>binding, attributeChangeListener: These are attributes that are practically never used because binding is an architecturally questionable JSF attribute as it incurs a traffic-intense, tight coupling between view and server-side model and is therefore not supported by Seam. On the other hand, attributeChangeListener is rather an internal Trinidad attribute to tell a Trinidad to re-render itself if renderer attributes of some other component have changed.</li>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, ondblclick, onclick: These are the usual<br />
JavaScript mouse event listeners, onclick is typically used to implement simple JavaScript confirm dialogues &#8220;Are you sure (Y or N)?&#8221;.</li>
</ul>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>onkeydown, onkeypress, onkeyup: These are the usual JavaScript keyboard, single key event listeners and may<br />
be of interest although the attributes accessKey and textAccessKey are usually more practical.</li>
</ul>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>shortDesc: This attribute serves to set a short tool tip that is displayed when the user hovers with the mouse on the<br />
respective component.</li>
</ul>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>inlineStyle and styleClass: The former attribute is very practical because it allows explicitly setting the style and<br />
overriding default style settings. However, it is cleaner to use styleClass, which is analogous to the XHTML style<br />
attribute, and define this explicit setup as a style sheet class in the style sheet (note that there are a couple of less<br />
frequent style attributes geared towards Trinidad-specific contents of component parts: contentStyle, labelStyle,<br />
listStyle, dateStyle, timeStyle, warnStyle, infoStyle, fatalStyle, errorStyle, defaultStyle,stateStyle, userStyle).</li>
</ul>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>partialTriggers: This attribute serves to state the IDs of the components (separated by single spaces) that trigger<br />
a <b>partial page refresh (PPR)</b> which is discussed in the upcoming chapter.</li>
</ul>
</ul>
</ul>
<h2>Standard tag attributes in tag groups</h2>
<p>Let&#8217;s take a look at the attributes that almost always occur in certain tag groups(mentioned in the beginning of this chapter):</p>
<h2>Attributes that occur in form and display tags</h2>
<p>This relates to the second tag group we learned in the earlier section named <i>Trinidad&#8217;s core tag library namespace (tr)</i>. The following Trinidad-specific attributes occur there:</p>
<ul>
<ul>
<li>label: This attribute serves to set the label of an input field; note that Trinidad support label indication, along with the respective input field, is also used for error or info messaging, for example, in the messages component.</li>
</ul>
</ul>
<ul>
<ul>
<li>accessKey, labelAndAccessKey: Both attributes allow keyboard shortcuts for an input field, but labelAndAccessKey allows you to indicate the shortcut as part of the label. For example, label=&#8221;&amp;9: date&#8221; activates the 9 key as keyboard shortcut for the respective input field (e.g. pressing Alt + Shift + 9 in Firefox). Note that, its analogon, textAndAccessKey in the command area.</li>
</ul>
</ul>
<ul>
<ul>
<li>contentStyle: This attribute is used to set the style of the tag&#8217;s content area,for example, the style used within input text&#8217;s box.</li>
</ul>
</ul>
<ul>
<ul>
<li>disabled, readOnly: These are Boolean attributes that both deactivate input fields, but disabled differs in its look by keeping the frame around the box.</li>
</ul>
</ul>
<ul>
<ul>
<li>autoSubmit: If &#8220;true&#8221;, it sends the enclosing form when this Boolean attribute&#8217;s field is somehow manipulated, for example, by changing its entry and pressing tab or return. Note that this attribute must be &#8220;true&#8221; if partial page rendering is started from this attribute&#8217;s field (refer to the upcoming chapter for detailed information).</li>
</ul>
</ul>
<ul>
<ul>
<li>required, requiredMessageDetail, showRequired: The attribute required is a Boolean attribute to indicate if an input field entry must be provided by the user, and when it is not provided, it is allowed to indicate a custom message (requiredMessageDetail) and display a missing symbol (showRequired=&#8221;true&#8221;).</li>
</ul>
</ul>
<ul>
<ul>
<li>simple: This is a Boolean attribute to control if Trinidad&#8217;s label and messaging support is used. It also appears in the table tag.</li>
</ul>
</ul>
<p>A series of attributes in this group are those that stem from the core JSF tag libraries:</p>
<ul>
<ul>
<li>immediate: This is a JSF attribute and serves to have the respective input field converted, and validated before the process validator phase of the JSF lifecycle so that its possible server request may directly follow (apply request phase). For example, this occurs when using action listeners, which is a common practice.</li>
</ul>
</ul>
<ul>
<ul>
<li>onblur, onfocus, onchange: These attributes expect the usual JavaScript handlers to be assigned.</li>
</ul>
</ul>
<ul>
<ul>
<li>validator, converter: Both attributes serve to reference JSF&#8217;s usual conversion and validation mechanisms, but validator differs in expecting a method call instead of a class. This is somewhat confusing, but JSF&#8217;s core library supports the tag &lt;f:validator validatorId=&#8221;aValidatorClass&#8221;/&gt; which can be very practically used inside of any Trinidad input field tag.</li>
</ul>
</ul>
<ul>
<ul>
<li>value: This is JSF&#8217;s standard attribute to assign the model behind the respective tag, for example, a view model or a real domain object.</li>
</ul>
</ul>
<p>Finally, in this group are listener attributes which come both from pure JSF and Trinidad:</p>
<ul>
<ul>
<li>actionListener: This attribute is based on the ActionEvent</li>
</ul>
</ul>
<ul>
<ul>
<li>valueChangeListener: This attribute is based on the ValueChangeEvent</li>
</ul>
</ul>
<ul>
<ul>
<li>returnListener: A Trinidad-specific listener called returnListener,is supported, and is used to indicate a listener method for a Trinidad Return Event when control returns from a Trinidad dialog (see respective dialogs chapter)</li>
</ul>
</ul>
<h2>Attributes that occur in command and navigation components</h2>
<p>These are attributes that occur in the third tag group. We have learned about the command and navigation tags, to which these attributes are related, in the earlier section. Here we can see their attributes:</p>
<ul>
<ul>
<li>launchListener: This attribute serves to indicate a listener method that is called just before a Trinidad dialogue is displayed.</li>
</ul>
</ul>
<ul>
<ul>
<li>partialSubmit: This is a Boolean attribute, which when set to &#8220;true&#8221; has the effect that its tag acts as a partial page rendering source (refer to the upcoming chapter for details).</li>
</ul>
</ul>
<ul>
<ul>
<li>blocking: This is a Boolean attribute that, when true lets Trinidad block any other user input while the respective request is ongoing.</li>
</ul>
</ul>
<ul>
<ul>
<li>textAndAccessKey: T his is, as mentioned earlier, an attribute that allows assigning a keyboard shortcut. Note that its the power of Trinidad&#8217;s consistent support of the keyboard that makes it a framework for all applications that heavily support keyboard users with minimal mouse activity.</li>
</ul>
</ul>
<ul>
<ul>
<li>useWindow, windowHeight, windowWidth: These attributes are used to setup a Trinidad dialogue popup (useWindow=&#8221;true&#8221;) and its window size.</li>
</ul>
</ul>
<h2>Attributes that occur in large input and output components</h2>
<p>These attributes come from the fourth tag group, the rather heavyweight input and output components as described in the beginning section. They can be further grouped into the following attribute categories:</p>
<ul>
<ul>
<li>component attributes specific for table, treeTable, and tree</li>
</ul>
</ul>
<ul>
<ul>
<li>attributes specific for table and treeTable components only</li>
</ul>
</ul>
<ul>
<ul>
<li>attributes specific for tree and treeTable components only</li>
</ul>
</ul>
<ul>
<ul>
<li>attributes specific for the treeTable component only</li>
</ul>
</ul>
<ul>
<ul>
<li>attributes specific for the table component only</li>
</ul>
</ul>
<p>In the following section, we will give an overview of each of the above attribute categories.</p>
<h2>The tag attributes for table, treeTable, and tree</h2>
<p>First, we come across a couple of listeners that deal with selection and disclosure:</p>
<ul>
<ul>
<li>A Trinidad-specific selectionListener serves to handle a SelectionEvent that is raised when the user selects a row</li>
</ul>
</ul>
<ul>
<ul>
<li>A Trinidad-specific rowDisclosureListener to handle a RowDisclosureEvent that is raised when the users clicks on a detail item or any other node that is closed</li>
</ul>
</ul>
<p>Next, follow the row-specific attributes:</p>
<ul>
<ul>
<li>selectedRowKeys: This is the set of all rows (or row indices) that are selected</li>
</ul>
</ul>
<ul>
<ul>
<li>disclosedRowKeys: This is the set of all open nodes and rows</li>
</ul>
</ul>
<ul>
<ul>
<li>var, varStatus: As known from JSF; note that varStatus serves to set if a model-based reference is used, for example, when returning a selected row or if an index is preferred</li>
</ul>
</ul>
<h2>The tag attributes for table and treeTable</h2>
<p>A series of facets are supported that deal with the inclusion of developer own parts in certain areas of the views:</p>
<ul>
<ul>
<li>actions: This attribute is used to indicate any other action areas that are to be shown on the same line as Trinidad&#8217;s built-in table or treeTable actions</li>
</ul>
</ul>
<ul>
<ul>
<li>footer: This serves to setup anything in the footer area</li>
</ul>
</ul>
<ul>
<ul>
<li>header: This is to setup anything in the header area</li>
</ul>
</ul>
<p>A couple of specific listeners are provided to deal with sorting and range change:</p>
<ul>
<ul>
<li>A Trinidad-specific sortListener is provided to allow handling any SortEvent that occurs when the user clicks on the label of a column that has sorting activated</li>
</ul>
</ul>
<ul>
<ul>
<li>A rangeChangeListener is supported to handle any RangeChangeEvent that occurs when the user thumbs through the data when it is displayed page-wise</li>
</ul>
</ul>
<p>In connection with the sortListener table and treeTable, we need to provide the following attribute for setting up a selection mode:</p>
<ul>
<ul>
<li>rowSelection: This attribute serves to indicate if any selection at all is to be supported (&#8220;none&#8221;), and if so which type (&#8220;multiple&#8221; or &#8220;single&#8221;)</li>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>autoSubmit: This is to enable partial page rendering which also sends the enclosing form</li>
</ul>
</ul>
</ul>
<ul>
<ul>
<ul>
<li>emptyText: This is used to indicate any text that is displayed when there is no data to be obtained from the model</li>
</ul>
</ul>
</ul>
<p>The following series of attributes deal with the general view setup:</p>
<ul>
<ul>
<li>rows: This is the number of lines to be displayed at once</li>
</ul>
</ul>
<ul>
<ul>
<li>summary: This is used to indicate the purpose and structure of this component (only useful for non-visual output)</li>
</ul>
</ul>
<ul>
<ul>
<li>rowBandingInterval, columnBandingInterval: These attributes serve to setup band style for easier reading and in particular, to indicate when which (horizontal, vertical, or both) band is changed (for example, every two lines)</li>
</ul>
</ul>
<ul>
<ul>
<li>horizontalGridVisible, verticalGridVisible: These Boolean attributes are used to display a horizontal grid, vertical grid, or both</li>
</ul>
</ul>
<ul>
<ul>
<li>width: This attribute serves to define the overall width of this component</li>
</ul>
</ul>
<h2>The tag attributes for tree and treeTable</h2>
<p>There are just three attributes that are specific for both tree and treeTable:</p>
<ul>
<ul>
<li>nodeStamp: This facet allows to build the tree nodes by specifying a single looped node that allows us to build a tree in a highly dynamic way using an implicit loop (see the tree chapter for details)</li>
</ul>
</ul>
<ul>
<ul>
<li>focusListener, focusRowKey: These attributes allow handling the focus when it is on a node, which raises a FocusEvent that may be handled by the indicated focusListener and that is accessible in the object indicated as focusRowKey</li>
</ul>
</ul>
<ul>
<ul>
<li>initiallyExpanded: This is used to set if the component shows all the nodes when shown for the first time</li>
</ul>
</ul>
<h2>The tag attributes for treeTable</h2>
<p>The treeTable tag is exclusively supported by the following attributes:</p>
<ul>
<ul>
<li>rowsByDepth: This allows us to set the maximum size of displayed nodes depending on the actual level(depth) by passing an array of integers for the depths that the developer wants to specify (for more details refer to Chapter 8, <i>Growing a Tree</i>)</li>
</ul>
</ul>
<ul>
<ul>
<li>rootNoteRendered: This is used to set if the root is rendered at all</li>
</ul>
</ul>
<h2>The tag attributes for tree</h2>
<p>Actually, there is only one attribute here that exclusively supports this tag:</p>
<ul>
<ul>
<li>allDetailsEnabled: This serves to set if the detail feature of a table is to be used, thereby allowing to display additional detail information per line</li>
</ul>
</ul>
<h2>Summary</h2>
<p>We have seen what Trinidad is all about with regards to its component set. More concretely, we have first looked at the XHTML-focused Trinidad namespace trh that basically contains a component set for XHTML layout.</p>
<p>Furthermore, we looked at Trinidad&#8217;s core namespace which is its tr JSF tag library. It contains a large component set with various types of components for basic document composition, form input and display, command and navigation, large and basic input and output, layout, models, converters, validators, events, and event listeners.</p>
<p>Finally, we looked at the attributes of all those tags and found out that a straight-forward orientation along tag groups is possible. This is thanks to Trinidad&#8217;s framework character.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/11/apache-myfaces-trinidad-1-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
