<?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>OcpSoft &#187; Java</title> <atom:link href="http://ocpsoft.com/tags/java/feed/" rel="self" type="application/rss+xml" /><link>http://ocpsoft.com</link> <description>&#34;Simple Software&#34;</description> <lastBuildDate>Tue, 27 Jul 2010 15:07:50 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0</generator> <item><title>JSF&#8217;s &lt;h:dataTable&gt; vs &lt;ui:repeat&gt; &#8211; How to get the selected row.</title><link>http://ocpsoft.com/java/jsf-java/jsfs-hdatatable-vs-uirepeat-how-to-get-the-selected-row/</link> <comments>http://ocpsoft.com/java/jsf-java/jsfs-hdatatable-vs-uirepeat-how-to-get-the-selected-row/#comments</comments> <pubDate>Mon, 14 Sep 2009 11:30:42 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[Facelets]]></category> <category><![CDATA[Java]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=67</guid> <description><![CDATA[<ui:repeat> allows iteration over a List of Array[] of items, but it does not provide a method of discovering the "selected" or "actioned" row; there's no way to discover the row the user is interacting with. Or is there?]]></description> <content:encoded><![CDATA[<p>So, a little while ago I was attempting to use JSF&#8217;s Facelets &lt;ui:repeat&gt; tag, as a replacement for &lt;h:dataTable&gt;, but difficulty came when I needed to process actions on individual records of each row.</p><p>&lt;ui:repeat&gt; allows iteration over a List of Array[] of items, but it does not provide a method of discovering the &#8220;selected&#8221; or &#8220;actioned&#8221; row; there&#8217;s no way to discover the row the user is interacting with. Or is there?<br
/> <span
id="more-67"></span><br
/> I&#8217;ve since learned of two ways to deal with this situation:</p><h2>1. Use ListDataModel</h2><p>I asked another JSF Expert, <a
href="http://mojavelinux.com"  target="_blank">Dan Allen</a> (author of Seam in Action) and here&#8217;s what he told me:</p><div
class="featured"><p>Lincoln,</p><p>There is an approach which will work in this case, but it doesn&#8217;t rule out the possibility that refinement is needed. Let me open with the example.</p><p>On the home page, there is a link that will load a feature list and navigate to the list page.</p><p>/home.xhtml<br
/> /list.xhtml</p><p>And finally, the controller:</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;">@ManagedBean
@SessionScoped <span style="color: #666666; font-style: italic;">// chosen for convenience, really it should be view-scoped or conversation-scoped (299)</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> FeatureList
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> DataModel features<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> DataModel getFeatures<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #000000; font-weight: bold;">return</span> features<span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">List</span> l <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		l.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Feature<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;One&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		l.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Feature<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Two&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		features <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ListDataModel<span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> action<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;You clicked on the button in the row with feature &quot;</span> 
			<span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>Feature<span style="color: #009900;">&#41;</span> features.<span style="color: #006633;">getRowData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>Note that the getRowData() method is positioned at the row which received the action during the invocation of any listener. Be careful, though, because it points to the first row if no row is selected. First check if getRowIndex() &gt;= 0 to see if a row received an action.</p><div
class="inside">Lincoln&#8217;s note &#8212; In JSF2, you can call the isRowSelected() method, instead of this check.</div><p>Regardless, this is still a horrible way (IMO) of having to select the row. It is very opaque. This is one area where you really take Seam for granted because you would instead use injection of the selected row:</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;">@DataModelSelection Feature selectedFeature<span style="color: #339933;">;</span></pre></div></div><p>There may be some edge cases where this doesn&#8217;t work. Apply to your use case and report back any gaps.</p><p>-Dan</p></div><p>From Dan&#8217;s email, I learned that you could place a List of objects in a <strong>ListDataModel</strong> wrapper, effectively binding the state of the list to the UI. With that done, you can manipulate the data in an action-method, being able to retrieve the selected row index, object itself, and continue as you would expect with your programming.</p><div
class="featured"><center>Need some <strong>/pretty /urls</strong> in your JSF web-app? Try <a
href="http://ocpsoft.com/prettyfaces/" title="SEO | Dynamic Parameters | Bookmarks | Navigation | JSF | JSF2 | URLRewrite Filter | Open Source">PrettyFaces</a>: URL-rewriting for Java EE and JSF. (Free and <strong>open-source</strong>!)</center></div><h2>2. Upgrade to an advanced EL (EL2) Jar</h2><p>Probably my favorite solution &#8211; you can use EL2 method invocation, provided either by Seam, or Sun&#8217;s reference implementation, and pass the desired objects directly to methods in your JSP/Facelet code. It&#8217;s coming standard in J2EE 6, but why wait?</p><p>This method is simple, intuitive, and enables much more powerful and reusable Beans to handle page code, reducing redundancy in Model classes and business logic.</p><p>Note how I pass the current <em>var</em> object directly to the method via EL:</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:commandButton</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;add&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Add Task&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#{itemController.addItemNote(currentItemBean.item, addNoteBean.newNote)}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span></pre></div></div><p>And here&#8217;s the Backing Bean code:</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;">@ManagedBean
@RequestScoped
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ItemController
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> addTask<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Item item, <span style="color: #000000; font-weight: bold;">final</span> Note note<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        ItemService.<span style="color: #006633;">addNote</span><span style="color: #009900;">&#40;</span>item, note<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;pretty:viewItem&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// this return statement is a PrettyFaces JSF bookmarking navigation id</span>
    <span style="color: #009900;">&#125;</span></pre></div></div><h3>For instructions on how to: <a
href="http://ocpsoft.com/java/jsf2-java/jsf2-how-to-add-the-magic-of-el-el2-to-jsf/">include EL2 in a JSF project</a> go <a
href="http://ocpsoft.com/java/jsf2-java/jsf2-how-to-add-the-magic-of-el-el2-to-jsf/">here</a>.</h3><p>For more information on JSF SEO and Bookmarking, take a look at <a
href="http://ocpsoft.com/prettyfaces">PrettyFaces: URL rewriting extension for JSF</a>.</p><p>If you are at all confused by these examples, feel free to leave a comment, and I&#8217;ll do my best to help.</p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/jsf-java/jsfs-hdatatable-vs-uirepeat-how-to-get-the-selected-row/feed/</wfw:commentRss> <slash:comments>9</slash:comments> </item> <item><title>Calling All PrettyFaces Users!</title><link>http://ocpsoft.com/prettyfaces/calling-all-prettyfaces-users/</link> <comments>http://ocpsoft.com/prettyfaces/calling-all-prettyfaces-users/#comments</comments> <pubDate>Sun, 30 Aug 2009 16:41:17 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[PrettyFaces]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JSF]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=70</guid> <description><![CDATA[Are you using PrettyFaces on a project you can share about? Looking for real-world experiences: How has PrettyFaces helped you or your team? What would you change if you could (you can)? If you would like to share, show us your work of art! Email to: lincoln@ocpsoft.com Thank you! PS &#8211; In addition: If you&#8217;d [...]]]></description> <content:encoded><![CDATA[<h3>Are you using PrettyFaces on a project you can share about?</h3><p>Looking for real-world experiences:</p><ul><li>How has PrettyFaces helped you or your team?</li><li>What would you change if you could (you can)?</li><li>If you would like to share, show us your work of art!</li></ul><p>Email to: lincoln@ocpsoft.com</p><p>Thank you!</p><p>PS &#8211; In addition: If you&#8217;d like to be added to our new &#8220;People using PrettyFaces&#8221; page, also send a logo and a short description of your product or company!</p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/prettyfaces/calling-all-prettyfaces-users/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PrettyFaces JSF1.1 UrlRewriting Support &#8211; Released</title><link>http://ocpsoft.com/prettyfaces/prettyfaces-jsf11-urlrewriting-support-released/</link> <comments>http://ocpsoft.com/prettyfaces/prettyfaces-jsf11-urlrewriting-support-released/#comments</comments> <pubDate>Mon, 24 Aug 2009 22:27:01 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[PrettyFaces]]></category> <category><![CDATA[Releases]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JSF]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=68</guid> <description><![CDATA[PrettyFaces: A new version of PrettyFaces for JSF1.1 (historical support) is now available for download. This version is feature-complete, but we are looking for feedback on compatibility and functionality that may be broken with various implementations, so please post comments! It should be noted that JSF is now on version 2.0, and PrettyFaces 2.0.x should [...]]]></description> <content:encoded><![CDATA[<h3><a
href="http://ocpsoft.com/prettyfaces">PrettyFaces</a>:</h3><p>A new version of PrettyFaces for JSF1.1 (historical support) is now available for download. This version is feature-complete, but we are looking for feedback on compatibility and functionality that may be broken with various implementations, so please post comments!<br
/> <span
id="more-68"></span></p><p>It should be noted that JSF is now on version 2.0, and PrettyFaces 2.0.x should be used. E.g: PrettyFaces 1.2.x should be used with JSF 1.2.</p><p
style="padding-left: 30px;"><strong>1.1.0:</strong> <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.1.0.jar">jar</a>, <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.1.0-sources.jar">src</a></p><div
style="align:center; background:#555; padding:10px"><form
action="http://groups.google.com/group/prettyfaces-users/boxsubscribe"><table
border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td
colspan='2' align="center"><strong>Subscribe to <a
href="http://groups.google.com/group/prettyfaces-users">prettyfaces-users</a></strong></td></tr><tr><td
align="right" width="30%"><label
for="subeml2" style="color:#eee">Email:&nbsp;</label></td><td
align="left"> <input
id="subeml2" name="email" size="18" type="text" /> <input
name="sub" type="submit" value="Subscribe" /></td></tr></tbody></table></form></div><p><br/></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/prettyfaces/prettyfaces-jsf11-urlrewriting-support-released/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Facelets vs. JSF2 &amp; EzComp</title><link>http://ocpsoft.com/java/jsf-java/facelets-vs-jsf2-ezcomp/</link> <comments>http://ocpsoft.com/java/jsf-java/facelets-vs-jsf2-ezcomp/#comments</comments> <pubDate>Tue, 19 May 2009 21:18:00 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[Java]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=56</guid> <description><![CDATA[Several things that make life painful with Facelets are fixed with JSF2 &#38; EzComp. Take a look at some of the nicer things to come: You can pass a value-binding into a component. You can assign a listener to a specific input field/button inside a custom component. You can pass facets into components and use [...]]]></description> <content:encoded><![CDATA[<p>Several things that make life painful with Facelets are fixed with <a
href="https://javaserverfaces.dev.java.net/" target="_blank">JSF2 &amp; EzComp</a>. Take a look at some of the nicer things to come:</p><p><span
id="more-56"></span></p><ul><li> You can pass a value-binding into a component.</li><li> You can assign a listener to a specific input field/button inside a custom component.</li><li> You can pass facets into components and use them conditionally.</li><li> You can attach validators to specific input fields/buttons of components.</li><li> You can pass nested children into components and use them conditionally.</li><li> In EzComp, namespaces are created automatically by convention &#8212; no more taglibs</li><li> You can include CSS or JS files from packaged jars &#8212; a big issue when using shared libraries of components.</li><li> Standard support for Ajax &#8212; no javascript required (&lt;f:ajax /&gt;).</li></ul><p>Without all of this, with JSP or Facelets 1.2, you eventually need to write components in Java, which means a lot of time-consuming work. Having gone down that road, and then experienced EzComp, I&#8217;ve seen a time-saving of about 10x, with a lot more power to create really interactive and rich components through Ajax. Instead of 3-4 files required to make a component, you now have 1 &#8212; the component.</p><p>Moral of the Story: If you are considering an upgrade from JSP, go right to JSF2 &#8212; it&#8217;s stable enough to begin development.</p><p>Also, be sure to check out the developer <em>blags</em> for more updates on JSF2:</p><ul><li><a
href="http://weblogs.java.net/blog/edburns/" target="_blank">Ed Burns</a></li><li><a
href="http://blogs.sun.com/rlubke" target="_blank">Ryan Lubke</a></li><li><a
href="http://weblogs.java.net/blog/driscoll/" target="_blank">Jim Driscoll</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/jsf-java/facelets-vs-jsf2-ezcomp/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>PrettyFaces 1.2.3_GA Released</title><link>http://ocpsoft.com/releases/prettyfaces-123_ga-released/</link> <comments>http://ocpsoft.com/releases/prettyfaces-123_ga-released/#comments</comments> <pubDate>Wed, 15 Apr 2009 04:58:46 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[Releases]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JSF]]></category> <category><![CDATA[OpenSource]]></category> <category><![CDATA[PrettyFaces]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=53</guid> <description><![CDATA[PrettyFaces: Version 1.2.3_GA: binary, source, documentation (stable) Minor Release: 20090415 Added optional &#60;action onPostback=&#8221;false&#8221;&#62; boolean flag to prevent action methods from being called on form postback. Defaults to true; Added optional &#60;query-param decode=&#8221;false&#8221;&#62; to prevent java.net.URLDecode.decode() from being called on a specific managed query-parameter. Defaults to true; Added unit tests for several critical classes. Minor [...]]]></description> <content:encoded><![CDATA[<h3><a
href="http://ocpsoft.com/prettyfaces">PrettyFaces</a>:</h3><p><strong>Version 1.2.3_GA</strong>: <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.2.3_GA.jar">binary</a>, <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.2.3_GA-sources.jar">source</a>, <a
href="http://ocpsoft.com/prettyfaces/v123">documentation</a> (stable)<br
/> Minor Release: 20090415</p><ol><li>Added optional &lt;action onPostback=&#8221;false&#8221;&gt; boolean flag to prevent action methods from being called on form postback. Defaults to true;<li>Added optional &lt;query-param decode=&#8221;false&#8221;&gt; to prevent java.net.URLDecode.decode() from being called on a specific managed query-parameter. Defaults to true;<li>Added unit tests for several critical classes.<li>Minor to moderate refactoring of PrettyFilter/PrettyContext</ol><div
style="align:center; background:#555; padding:10px"><form
action="http://groups.google.com/group/prettyfaces-users/boxsubscribe"><table
border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td
colspan='2' align="center"><strong>Subscribe to <a
href="http://groups.google.com/group/prettyfaces-users">prettyfaces-users</a></strong></td></tr><tr><td
align="right" width="30%"><label
for="subeml2" style="color:#eee">Email:&nbsp;</label></td><td
align="left"> <input
id="subeml2" name="email" size="18" type="text" /> <input
name="sub" type="submit" value="Subscribe" /></td></tr></tbody></table></form></div><p><br/></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/releases/prettyfaces-123_ga-released/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PrettyFaces v1.2.3_RC2 Released</title><link>http://ocpsoft.com/prettyfaces/prettyfaces-v123_rc2-released/</link> <comments>http://ocpsoft.com/prettyfaces/prettyfaces-v123_rc2-released/#comments</comments> <pubDate>Wed, 01 Apr 2009 01:21:25 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[PrettyFaces]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JSF]]></category> <category><![CDATA[OpenSource]]></category> <category><![CDATA[Releases]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=49</guid> <description><![CDATA[PrettyFaces: Version 1.2.3_RC2: binary, source, documentation (stable) Minor Release: 20090331 Servlet forwards are working Subscribe to prettyfaces-users Email:&#160;]]></description> <content:encoded><![CDATA[<h3><a
href="http://ocpsoft.com/prettyfaces">PrettyFaces</a>:</h3><p><strong>Version 1.2.3_RC2</strong>: <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.2.3_RC2.jar">binary</a>, <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.2.3_RC2-sources.jar">source</a>, <a
href="http://ocpsoft.com/prettyfaces/v123">documentation</a> (stable)<br
/> Minor Release: 20090331</p><ol><li>Servlet forwards are working</li></ol><div
style="align:center; background:#555; padding:10px"><form
action="http://groups.google.com/group/prettyfaces-users/boxsubscribe"><table
border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td
colspan='2' align="center"><strong>Subscribe to <a
href="http://groups.google.com/group/prettyfaces-users">prettyfaces-users</a></strong></td></tr><tr><td
align="right" width="30%"><label
for="subeml2" style="color:#eee">Email:&nbsp;</label></td><td
align="left"> <input
id="subeml2" name="email" size="18" type="text" /> <input
name="sub" type="submit" value="Subscribe" /></td></tr></tbody></table></form></div><p><br/></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/prettyfaces/prettyfaces-v123_rc2-released/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PrettyFaces v1.2.3_RC1 Released</title><link>http://ocpsoft.com/releases/prettyfaces-v123_rc1-released/</link> <comments>http://ocpsoft.com/releases/prettyfaces-v123_rc1-released/#comments</comments> <pubDate>Thu, 19 Mar 2009 12:20:00 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[Releases]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JSF]]></category> <category><![CDATA[OpenSource]]></category> <category><![CDATA[PrettyFaces]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=47</guid> <description><![CDATA[PrettyFaces: Version 1.2.3_RC1: binary, source, documentation (stable) Minor Release: 20090319 Managed query-params now accept multiple parameters of the same name: E.g.: String[] names &#8212; would accept a list of parameters (with the same name) from the request Enhanced configuration loading &#8212; PrettyFaces now looks for /META-INF/pretty-config.xml by default, in addition to accepting a comma-separated list [...]]]></description> <content:encoded><![CDATA[<h3><a
href="http://ocpsoft.com/prettyfaces">PrettyFaces</a>:</h3><p><strong>Version 1.2.3_RC1</strong>: <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.2.3_RC1.jar">binary</a>, <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.2.3_RC1-sources.jar">source</a>, <a
href="http://ocpsoft.com/prettyfaces/v123">documentation</a> (stable)<br
/> Minor Release: 20090319</p><ol><li>Managed query-params now accept multiple parameters of the same name: E.g.: String[] names &#8212; would accept a list of parameters (with the same name) from the request</li><li>Enhanced configuration loading &#8212; PrettyFaces now looks for /META-INF/pretty-config.xml by default, in addition to accepting a comma-separated list of user config-files in the web.xml init param: com.ocpsoft.pretty.CONFIG_FILES &#8212; submitted by Aleksei Valikov</li><li>JSP support for standard attributes on the pretty:link tag has been fixed. The pretty link will now accept style=&#8217;mystyle&#8217; and other attributes &#8212; from <a
href="http://ocpsoft.com/about">Derek Hollis at OcpSoft</a></li></ol><div
style="align:center; background:#555; padding:10px"><form
action="http://groups.google.com/group/prettyfaces-users/boxsubscribe"><table
border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td
colspan='2' align="center"><strong>Subscribe to <a
href="http://groups.google.com/group/prettyfaces-users">prettyfaces-users</a></strong></td></tr><tr><td
align="right" width="30%"><label
for="subeml2" style="color:#eee">Email:&nbsp;</label></td><td
align="left"> <input
id="subeml2" name="email" size="18" type="text" /> <input
name="sub" type="submit" value="Subscribe" /></td></tr></tbody></table></form></div><p><br/></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/releases/prettyfaces-v123_rc1-released/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PrettyFaces v1.1.x, v1.2.x, v2.0.x Docs (legacy)</title><link>http://ocpsoft.com/prettyfaces/v123/</link> <comments>http://ocpsoft.com/prettyfaces/v123/#comments</comments> <pubDate>Thu, 19 Mar 2009 04:40:03 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[PrettyFaces]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JSF]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=43</guid> <description><![CDATA[Configuration Setting up PrettyFaces is simple. Configure PrettyFaces Filters in WEB-INF/web.xml Create the WEB-INF/pretty-config.xml file (Steps 1 &#38; 2 are required. Advanced features are optional.) Advanced Features Using dynamic view-ids Using the managed query-parameter facility Wiring navigation into JSF action methods Parsing complex / dynamic-length URLs Accessing PrettyContext through EL Components &#60;pretty:link&#62; &#60;pretty:urlbuffer&#62; Configuring Logging [...]]]></description> <content:encoded><![CDATA[<h1><a
name="configuration"></a>Configuration</h1><p>Setting up PrettyFaces is simple.<br
/> <span
id="more-43"></span></p><div
class="inset"><div
style="margin-left: 10px;"><ol><li><h4><a
href="#filters">Configure PrettyFaces Filters in	WEB-INF/web.xml</a></h4></li><li><h4><a
href="#prettyconfig">Create the WEB-INF/pretty-config.xml file</a></h4><p> (Steps 1 &amp; 2 are required. Advanced features are optional.)</p></li><li><h4><a
href="#application">Advanced Features</a></h4><ul><li><a
href="#dynamicviewid">Using dynamic view-ids</a></li><li><a
href="#queryparams">Using the managed query-parameter facility</a></li><li><a
href="#navigation">Wiring navigation into JSF action methods</a></li><li><a
href="#customparsing">Parsing complex / dynamic-length URLs</a></li><li><a
href="#elaccess">Accessing PrettyContext through EL</a></li></ul></li><li><h4><a
href="#links">Components</a></h4><ul><li><a
href="#prettylink">&lt;pretty:link&gt;</a></li><li><a
href="#urlbuffer">&lt;pretty:urlbuffer&gt;</a></li></ul></li><li><a
href="#logging">Configuring Logging (log4j)</a></li></ol><div
class="clearer"></div></div></div><div
class="featured"><div
class="inside"><p><span
style="color: red">Note:</span> This is not the <a
href="http://ocpsoft.com/prettyfaces/docs">current version</a> of PrettyFaces. This page is valid for the 1.1.0, 1.2.x, and 2.0.2 versions.</p></div></div><h3 style="margin-bottom: 15px;"><a
href="#configuration"><strong>0. Get PrettyFaces.</strong></a></h3><p>This step is pretty straight-forward, right? Extract necessary JAR files into your /WEB-INF/lib directory, or include a maven dependency in your pom.xml</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- For JSF1.1 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.ocpsoft<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ocpsoft-pretty-faces<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.1.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- For JSF1.2 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.ocpsoft<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ocpsoft-pretty-faces<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.2.6_RC1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- For JSF2.0 --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.ocpsoft<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ocpsoft-pretty-faces<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.0.2_GA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><h3 style="margin-bottom: 15px;"><a
name="filters"></a><a
href="#configuration"><strong>1. Add the &lt;filter&gt; and &lt;filter-mapping&gt; to /WEB-INF/web.xml</strong></a></h3><p>PrettyFilter does most of the work. Without it, not much would happen.</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Pretty Filter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.ocpsoft.pretty.PrettyFilter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Pretty Filter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>REQUEST<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FORWARD<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ERROR<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dispatcher<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><h3 style="margin-bottom: 15px;"><a
name="prettyconfig"></a><a
href="#configuration"><strong>2. Create the /WEB-INF/pretty-config.xml file</strong></a></h3><p>This is where you will map URLs to Faces Views. Read on for details.</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pretty-config</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces-xsd&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces-xsd </span>
<span style="color: #009900;">	http://ocpsoft.com/xml/ns/prettyfaces/pretty-1.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;login&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /login <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /faces/login.jsf <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;home&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /home <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;query-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;displayWelcomeMessage&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#{homeBean.displayWelcomeMessage}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/query-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> #{homeBean.getViewPath} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;viewStory&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  /story/#{myBean.currentStoryId}/  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;query-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;commentText&quot;</span> <span style="color: #000066;">decode</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#{myBean.commentText}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/query-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /faces/story/viewStory.jsf <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">onPostback</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#{myBean.loadStory}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;viewComment&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /story/#{myBean.currentStoryId}/#{myBean.commentId} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/faces/story/comment.jsf<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>#{myBean.loadComment}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pretty-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><h3>Url Mappings</h3><p>Each &lt;url-mapping id=&#8221;"&gt; must specify a unique id. And contains the following attributes and elements, in order:</p><ol><li><h4>&lt;pattern&gt;/blog/article/#{someBean.paramName}&lt;/pattern&gt;</h4><p>Specify the pattern for which this URL will be matched. This element is required, and has a multiplicity of 1 (only one)</p><p>Any EL expressions #{someBean.paramName} found within the pattern will be processed as value injections. The URL will be parsed and the value found at the location of the EL expression will be injected into the location specified in that EL expression. <i><span
style="color:red;">Note:</span> EL expressions will not match over the &#8216;/&#8217; character.</i></p><p>The pattern itself is compiled parsed as a <a
href="http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html">regular expression</a>, meaning that the actual URL matching can be as simple or as complex as desired.</p><p>If further custom URL parsing is required, it is recommended to do this manually via an Action Method: See <a
href="#customparsing">custom parsing</a>.</p></li><li><h4>&lt;query-param name=&#8221;key&#8221;&gt;#{someBean.queryParamValue}&lt;/query-param&gt;</h4><p>Defines a managed query parameter of the form http://site.com/url?<b>key=somevalue</b>, where if the parameter exists, the value will be injected into the specified managed bean. <i>This also handles JSF commandLink and AJAX &lt;f:param&gt; values.</i> This element is optional, and has a multiplicity of 0&#8230;N (zero or more)</p><p><i>Attributes:</i></p><ol><li><strong>name</strong> &#8212; String, required. This is the request value key</li><li><strong>decode</strong> &#8212; boolean, optional (default true), if set to false, this query-param will not be URLDecoded (see <a
href="http://java.sun.com/javase/6/docs/api/java/net/URLDecoder.html">java.net.URLDecoder</a>)</li></ol></li><li><h4>&lt;view-id&gt;#{someBean.methodName}&lt;view-id&gt;</h4><p>Specify the JSF ViewId displayed by this mapping, by either calling an el Method (must return an object for which the toString() method will return the view Id) or by returning a literal String value. This element is required, and has a multiplicity of 1 (only one)</p><p>The ViewId may be any resource located within the current Servlet Context: E.g. PrettyFaces can also forward to a non-Faces servlet.</p></li><li><h4>&lt;action&gt;#{someBean.methodName}&lt;/action&gt;</h4><p>Specify an action method to be called after URL parameters have been parsed and assigned into beans. This element has a multiplicity of 0&#8230;N (zero or more)</p><p><i>Attributes:</i></p><ol><li><p><strong>phaseId</strong> &#8212; String, optional (default RESTORE_VIEW) if set to a valid JSF PhaseId, the action will occur immediately before the specified Phase. (see <a
href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/event/PhaseId.html">javax.faces.event.PhaseId</a>)</p><p>Valid values for this attribute are: RESTORE_VIEW, APPLY_REQUEST_VALUES, PROCESS_VALIDATIONS,	UPDATE_MODEL_VALUES, INVOKE_APPLICATION, RENDER_RESPONSE, ANY_PHASE.<p> <strong><span
style="color: red">Note however</span></strong>, that if the phase does not occur, neither will your action method.</p></li><li><p><strong>onPostback</strong> &#8212; boolean, optional (default true), if set to false, this	action method will not occur on form postback. (see <a
href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/api/javax/faces/render/ResponseStateManager.html#isPostback(javax.faces.context.FacesContext)">ResponseStateManager.isPostback()</a>)</p></li></ol></li></ol><h3>Order of processing:</h3><ol><li>URL pattern parsing, query-parameter handling, and value injection into JSF managed beans.</li><li>View-Id calculation (if a view Id is dynamic, the el method	will be called.)</li><li>JSF gains control of the request via RequestDispatcher.forward(&#8220;/context/faces/viewId.jsf&#8221;).</li><li>Action methods are called before RESTORE_VIEW phase, unless the optional phaseId attribute is specified.</li></ol><h3>Config Loading:</h3><p>At application startup time, before any requests are processed, Pretty Faces processes zero or more configuration resources, located according to the following algorithm:</p><ol><li>Search for classpath resources named <span
class="code">META-INF/pretty-config.xml</span><br
/> in the ServletContext resource paths for this web application, and load each as a configuration resource.</li><li>Check for the existence of a context initialization parameter named <span
class="code">com.ocpsoft.pretty.CONFIG_FILES</span>. If it exists, treat it as a comma-delimited list of context relative resource paths (starting with a <span
class="code">/</span>), and load each of the specfied resources.</li><li>Check for the existence of a web application configuration resource named <span
class="code">/WEB-INF/pretty-config.xml</span>, and load it if the resource exists.</li></ol><h3 style="margin-bottom: 15px;"><a
name="application"></a><a
href="#configuration"><strong>3. Advanced Features</strong></a></h3><h4 style="margin-bottom: 15px;"><a
name="dynamicviewid"></a><a
href="#configuration"><strong>3.1 Using Dynamic View ID Capabilities</strong></a></h4><p>Dynamic view IDs allow a mapped URL to display content from any JSF view. This is prevents doing redirects which would otherwise destroy information stored in the URL, and also provides some extra functionality for application design.</p><p>This pretty-config mapping uses a dynamic view-id:</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pretty-config</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces-xsd&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces-xsd </span>
<span style="color: #009900;">	http://ocpsoft.com/xml/ns/prettyfaces/pretty-1.0.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;home&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /home <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;query-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;displayWelcomeMessage&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#{homeBean.displayWelcomeMessage}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/query-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> #{homeBean.getViewPath} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pretty-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><p>The corresponding backing-bean method must return a JSF ViewID, which will proceed with the faces lifecycle (leaving the URL /home), or a pretty:mappingId. In the case when a pretty:mappingId is returned, PrettyFaces will &#8220;switch mappings&#8221; and instead treat the request as if it had been sent to the new mappingId, without issuing a browser redirect.</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ManagedBean
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getViewPath<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// This method returns the path of the JSF view to display</span>
        <span style="color: #666666; font-style: italic;">// when the URL /home is accessed.</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>user.<span style="color: #006633;">isLoggedIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        	<span style="color: #666666; font-style: italic;">// Note: the extension '.jsf' is the mapped faces extension</span>
        	<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;/faces/home.jsf&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// The home page can instead display a different view; return</span>
        <span style="color: #666666; font-style: italic;">// the pretty:mappingId of the view you wish to display.</span>
        <span style="color: #666666; font-style: italic;">// Note that this will not cause a redirect, and will not </span>
        <span style="color: #666666; font-style: italic;">// change the client browser URL.</span>
        <span style="color: #666666; font-style: italic;">// If you wish to issue a redirect, you should use a page</span>
        <span style="color: #666666; font-style: italic;">// load action instead of a dynamic view Id function.</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;pretty:login&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h4 style="margin-bottom: 15px;"><a
name="queryparams"></a><a
href="#configuration"><strong>3.2 Using the Managed Query Parameter facility</strong></a></h4><p>Managed query parameters allow automatic assignment of values into JSF managed bean fields, instead of parsing and URL Decoding the value manually out of the request object. Examining this sample mapping, we can see that the developer has specified two managed query-parameters. The &#8216;sortBy&#8217; and &#8216;itemId&#8217; parameters.</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pretty-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;itemList&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /items/list <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;query-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sortBy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#{itemBean.sortByField}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/query-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;query-param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;itemId&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>#{itemBean.currentItemId}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/query-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /faces/items/list.jsf <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>#{itemBean.loadItems}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pretty-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><h5>The managed bean that accompanies this mapping:</h5><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ItemBean
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> List<span style="color: #339933;">&lt;</span>Item<span style="color: #339933;">&gt;</span> items<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Integer</span> currentItemId<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> sortByField<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> deleteItem<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// currentItemId will be automatically populated by</span>
		<span style="color: #666666; font-style: italic;">// PrettyFaces if the parameter was passed in the request</span>
		<span style="color: #666666; font-style: italic;">// (see example JSF page below)</span>
		ItemManager.<span style="color: #006633;">deleteById</span><span style="color: #009900;">&#40;</span>currentItemId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Redisplay the current page via redirect.</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;pretty:&quot;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> loadItems<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// The sortByField member will be null if the sortBy</span>
		<span style="color: #666666; font-style: italic;">// query-parameter is not found in the request</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">items</span> <span style="color: #339933;">=</span> ItemManager.<span style="color: #006633;">getSortedItems</span><span style="color: #009900;">&#40;</span>sortByField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//... getters and setters...</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h5>Example JSF page: <i>Notice the &lt;f:param&gt; tag.</i></h5><p>This will generate a link that provides the &#8216;itemId&#8217; parameter to the request for PrettyFaces to parse.</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;c:forEach</span> <span style="color: #000066;">var</span>=<span style="color: #ff0000;">&quot;item&quot;</span> <span style="color: #000066;">items</span>=<span style="color: #ff0000;">&quot;${itemBean.items}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:commandLink<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		Delete this item.
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;itemId&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${item.id}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:commandLink<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/c:forEach<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><h4 style="margin-bottom: 15px;"><a
name="navigation"></a><a
href="#configuration"><strong>3.3 Wiring navigation into JSF action methods</strong></a></h4><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PageBean
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> goHome<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// this will tell pretty to redirect the client to the home-page</span>
        <span style="color: #666666; font-style: italic;">// no parameters are mapped, so this is pretty simple</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;pretty:home&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> goHomeAndWelcome<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// this will tell pretty to redirect the client to the home-page</span>
        <span style="color: #666666; font-style: italic;">// since there is a managed query-parameter defined in the mapping,</span>
        <span style="color: #666666; font-style: italic;">// PrettyFaces will generate the URL, and append the mapped param</span>
        <span style="color: #666666; font-style: italic;">// eg: /home?displayWelcome=true </span>
        homeBean.<span style="color: #006633;">displayWelcomeMessage</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;pretty:home&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> goViewStory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// this will tell pretty to redirect the client to the viewStory page</span>
        <span style="color: #666666; font-style: italic;">// PrettyFaces will generate the URL by extracting any values from</span>
        <span style="color: #666666; font-style: italic;">// the mapping beans and using them to inject back into the pattern</span>
        <span style="color: #666666; font-style: italic;">// therefore, navigation can be controlled by placing a value into</span>
        <span style="color: #666666; font-style: italic;">// the mapped field before PrettyFaces extracts it and generates the URL</span>
	<span style="color: #666666; font-style: italic;">// so... /story/#{myBean.currentStoryId}/ ...becomes... /story/12/ </span>
&nbsp;
        viewStoryBean.<span style="color: #006633;">setCurrentStoryId</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;pretty:viewStory&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> doRefreshByRedirect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// using the &quot;pretty:&quot; prefix without a mapping-id will cause a</span>
        <span style="color: #666666; font-style: italic;">// redirect to the current page</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;pretty:&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> doNormalJSFRender<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// returning an value without the &quot;pretty:&quot; prefix will fall back to</span>
        <span style="color: #666666; font-style: italic;">// the default JSF navigation handlers</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;someNavigationCase&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h4 style="margin-bottom: 15px;"><a
name="customparsing"></a><a
href="#configuration"><strong>3.4 Parsing complex / dynamic-length URLs</strong></a></h4><p>Consider the following example configuration and bean: The URL contains many dynamic layers of mysite.com/value/value2/value3/&#8230;/valueN, which cannot be specified using a static URL pattern.</p><p> Since patterns are regexes, we can use a catch-all pattern, and process the values ourselves.</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;dynamicUrl&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> /blog/categories/.* <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> #{urlParsingBean.parseComplexUrl} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><p> Example of a complex URL parser. Remember to URLDecode before using any values from the URL:</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UrlParsingBean
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> parseComplexUrl<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">UnsupportedEncodingException</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">String</span> uri <span style="color: #339933;">=</span> PrettyContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getOriginalUri</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        List<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> categoryChain <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>uri.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> index <span style="color: #339933;">=</span> uri.<span style="color: #006633;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">String</span> value <span style="color: #339933;">=</span> uri.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            categoryChain.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">URLDecoder</span>.<span style="color: #006633;">decode</span><span style="color: #009900;">&#40;</span>value, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            uri <span style="color: #339933;">=</span> uri.<span style="color: #006633;">substring</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//now load the data...</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;/blag/viewArticle.jsf&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h4 style="margin-bottom: 15px;"><a
name="elaccess"></a><a
href="#configuration"><strong>3.5 Accessing PrettyContext through EL</strong></a></h4><p>Since a new PrettyContext is generated on each request, and stored into the requestMap, it is possible to access the context object through EL in a JSP, or Facelet.</p><p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
#{prettyContext.currentInstance} <span style="color: #808080; font-style: italic;">&lt;!-- returns the current PrettyContext --&gt;</span>
#{prettyContext.currentInstance.currentMapping.id} <span style="color: #808080; font-style: italic;">&lt;!-- returns the current UrlMapping Id --&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- And so on... --&gt;</span></pre></div></div><h3 style="margin-bottom: 15px;"><a
name="links"></a><a
href="#configuration"><strong>4. Rendering HTML Links and URLs</strong></a></h3><h4><a
name="prettylink"></a>4.1 The pretty:link component</h4><p>PrettyFaces provides a JSF component to output an HTML link to the page. The link tag requires a mapping-id (specified in the pretty-config.xml,) identifying which link to render.</p><p>If the provided mappingId requires any url-pattern-parameters or managed-query-parameters, they can be passed in via the &lt;f:param&gt; tag.</p><p>Url pattern parameters can be passed individually, as a java.util.List or as an Array. In the latter two cases, toString() will be called on each of the objects in the list/array. If an empty or null list/array is passed, it will be ignored.</p><p>Url pattern parameters do NOT have a name attribute, and are parsed in the order they are passed into the tag. Managed-query-parameters DO have a name attribute, and order is irrelevant.</p><p><strong>For Example:</strong> The viewComment pattern requires:</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- From pretty-config.xml, viewComment mapping-id, above:</span>
<span style="color: #808080; font-style: italic;"> /story/#{myBean.currentStoryId}/#{myBean.commentId}--&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;%@ taglib <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;pretty&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces&quot;</span> %<span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pretty:link</span> <span style="color: #000066;">mappingId</span>=<span style="color: #ff0000;">&quot;comment&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:param</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{myBean.currentStoryId}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:param</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{myBean.commentId}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	Go to Comment. (This is Link Text)
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pretty:link<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><h4><a
name="urlbuffer"></a>4.2 The pretty:urlbuffer component</h4><p>PrettyFaces provides a JSF component to generate a URL for use as a page scoped variable through El. This tag requires a mapping-id (specified in the pretty-config.xml)</p><p>If the provided mappingId requires any url-pattern-parameters or managed-query-parameters, they can be passed in via the &lt;f:param&gt; tag.</p><p>Url pattern parameters can be passed individually, as a java.util.List or as an Array. In the latter two cases, toString() will be called on each of the objects in the list/array. If an empty or null list/array is passed, it will be ignored.</p><p>Url pattern parameters do NOT have a name attribute, and are parsed in the order they are passed into the tag. Managed-query-parameters DO have a name attribute, and order is irrelevant.</p><p><strong>For Example:</strong> The viewItem pattern requires:</p><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- From the managed-query-parameter section above, itemList mapping-id.--&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pretty:urlbuffer</span> <span style="color: #000066;">var</span>=<span style="color: #ff0000;">&quot;itemListUrl&quot;</span> <span style="color: #000066;">mappingId</span>=<span style="color: #ff0000;">&quot;itemList&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;itemId&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;22&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;sortBy&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;price&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pretty:urlbuffer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:outputText</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Generated Url Is: #{requestScope.itemListUrl}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!-- /items/list?itemId=22&amp;sortBy=price --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div><p>This design is intended to reduce complexity and prevent manual manipulation of URLs.</p><h3 style="margin-bottom: 15px;"><a
name="logging"></a><a
href="#configuration"><strong>5. Configuring Logging (log4j)</strong></a></h3><h4>example log4j.properties</h4><div
class="wp_syntax"><div
class="code"><pre class="config" style="font-family:monospace;">### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
&nbsp;
### set log levels - for more verbose logging change 'info' to 'debug' ###
&nbsp;
log4j.rootLogger=warn, stdout
&nbsp;
#this will set PrettyFaces logging level to 'info'
log4j.logger.com.ocpsoft.pretty=info</pre></div></div><h3 style="margin-bottom: 15px;"><strong>Finished. Run your application!</strong></h3><p>You should now have a fully functional PrettyFaces configuration.</p><div
style="align: center; background: #555; padding: 10px"><form
action="http://groups.google.com/group/prettyfaces-users/boxsubscribe"><table
border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td
colspan='2' align="center"><strong>Subscribe to <a
href="http://groups.google.com/group/prettyfaces-users">prettyfaces-users</a></strong></td></tr><tr><td
align="right" width="45%"><label
for="subeml2" style="color: #eee">Email:&nbsp;</label></td><td
align="left"> <input
id="subeml2" name="email" size="18" type="text" /> <input
name="sub" type="submit" value="Subscribe" /></td></tr></tbody></table></form></div><p><br/><br/></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/prettyfaces/v123/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>Getting Started Quickly with Hibernate Annotations</title><link>http://ocpsoft.com/java/getting-started-quickly-with-hibernate-annotations/</link> <comments>http://ocpsoft.com/java/getting-started-quickly-with-hibernate-annotations/#comments</comments> <pubDate>Mon, 26 Jan 2009 14:08:04 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[Hibernate]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Annotations]]></category> <category><![CDATA[ORM]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=5</guid> <description><![CDATA[Tutorial Chapter 1 &#8211; Step By Step Getting started with Hibernate can be tricky, but here&#8217;s a step-by-step tutorial that explains exactly what needs to be done to enable your application for hibernate. This chapter covers very basic mapping and persistence. Download the following archives: (or use this Maven POM) Hibernate Core (3.3.0_CR1) Hibernate Annotations [...]]]></description> <content:encoded><![CDATA[<h2>Tutorial Chapter 1 &#8211; Step By Step</h2><p>Getting started with Hibernate can be tricky, but here&#8217;s a step-by-step tutorial that explains exactly what needs to be done to enable your application for hibernate. This chapter covers very basic mapping and persistence.</p><h3>Download the following archives: (or use <a
href="#comment-259">this Maven POM</a>)</h3><ul><li>Hibernate Core <a
href="http://sourceforge.net/project/showfiles.php?group_id=40712&amp;package_id=127784&amp;release_id=595668" target="_blank">(3.3.0_CR1)</a></li><li>Hibernate Annotations <a
href="http://sourceforge.net/project/showfiles.php?group_id=40712&amp;package_id=139933" target="_blank">(3.4.0_CR1)</a></li><li>HSQLDB (<a
href="http://sourceforge.net/project/showfiles.php?group_id=23316&amp;package_id=16653&amp;release_id=339171" target="_blank">1.8.0.10</a>), a lightweight in-memory RDBMS (or use the database of your choice)</li></ul><p><span
id="more-5"></span></p><h3><a
name="instructions"></a>Instructions:</h3><ul><li>Extract the archives and copy necessary JAR files into your project (or if you are using Maven, this is already taken care for you -> <a
href="#comment-259">example POM</a>):<br
/> <em>It may seem like quite a few jars, it might not, but this is the minimal set to have a working Hibernate Annotations 3.4.0 application. All of the following files should be contained in your downloads.<br
/> </em></li></ul><pre style="padding-left: 90px;"><strong>Hibernate Annotations</strong>
hibernate-annotations.jar
hibernate-commons-annotations.jar
jta.jar (<a href="http://en.wikipedia.org/wiki/Java_Transaction_API" target="_blank">JTA, javax.transaction</a>)

<strong>Hibernate Core</strong>
hibernate-core.jar (or hibernate3.jar)
ejb3-persistence.jar (<a href="http://java.sun.com/developer/technicalArticles/J2EE/jpa/" target="_blank">javax.persistence</a>)
antlr.jar (<a href="http://antlr.org/" target="_blank">2.7.6</a>)
commons-collections.jar (<a href="http://commons.apache.org/collections/" target="_blank">3.1</a>)
dom4j.jar (<a href="http://www.dom4j.org/" target="_blank">1.6.1</a>)
slf4j-api.jar (<a href="http://www.slf4j.org/" target="_blank">1.4.2</a>)
cglib.jar (<a href="http://cglib.sourceforge.net/" target="_blank">v2</a>)
asm.jar (<a href="http://asm.objectweb.org/" target="_blank">v3</a>)

<strong>HSQLDB
</strong>hsqldb.jar</pre><ul><li>Add the JARs to your project&#8217;s classpath.</li><li>Copy and paste the following source files into your project. We&#8217;re going to use some canned configurations in order to get all of this working.</li></ul><div
class="featured"><center>Need some <strong>/pretty /urls</strong> in your JSF web-app? Try <a
href="http://ocpsoft.com/prettyfaces/" title="SEO | Dynamic Parameters | Bookmarks | Navigation | JSF | JSF2 | URLRewrite Filter | Open Source">PrettyFaces</a>: URL-rewriting for Java EE and JSF. (Free and <strong>open-source</strong>!)</center></div><h4>log4j.properties</h4><p>(Optional) Put this file on your classpath, or in your source folder. Hibernate uses log4j to print output, so if we want to see detailed results, you should set this up.</p><div
class="wp_syntax"><div
class="code"><pre class="config" style="font-family:monospace;">log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
&nbsp;
log4j.rootLogger=warn, stdout
log4j.logger.org.hibernate=info
log4j.logger.org.hibernate.type=info
log4j.logger.org.hibernate.tool.hbm2ddl=debug
log4j.logger.org.hibernate.transaction=debug</pre></div></div><h4 style="text-align: center;">&#8212;-</h4><h4>MockObject.java</h4><p>It&#8217;s time to create our first object. Notice that this is a simple POJO with two fields: id and version. The <em>id</em> field is a required field, but before you complain, there is a philosophy of database design that dictates every entity table should have its own <em>id</em> column; some disagree with this, but I&#8217;ve found it a very convenient practice. Try it out before you pass judgment.</p><p>In order to map an object, a few things always need to be done:</p><ul><li>The class must be annotated with <em>@javax.persistence.Entity</em></li><li>The class must have a <em>@javax.persistence.Id </em>column</li><li>The class must have a default (or undefined) constructor method. This means it must have a constructor that has no arguments.</li><li>The <em>@Version</em> column is how Hibernate performs <a
href="http://en.wikipedia.org/wiki/Optimistic_concurrency_control" target="_blank">optimistic locking</a>. If a record has been modified by another transaction, your transaction&#8217;s version will be out of date, and an exception will be thrown.</li><li>By default, all fields in your class will be persisted to the database if possible. If there is a field that should not be recorded in the database, mark that field with the <em>@Transient</em> annotation.</li><li>To add new columns in the database, simply add new fields in your object.</li></ul><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.Serializable</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Column</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Entity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GeneratedValue</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.GenerationType</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Id</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Table</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.persistence.Version</span><span style="color: #339933;">;</span>
&nbsp;
@<span style="color: #003399;">Entity</span>
@Table<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mock_objects&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MockObject <span style="color: #000000; font-weight: bold;">implements</span> <span style="color: #003399;">Serializable</span>
<span style="color: #009900;">&#123;</span>
    @Id
    @GeneratedValue<span style="color: #009900;">&#40;</span>strategy <span style="color: #339933;">=</span> GenerationType.<span style="color: #006633;">AUTO</span><span style="color: #009900;">&#41;</span>
    @Column<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;id&quot;</span>, updatable <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span>, nullable <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Long</span> id <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    @Version
    @Column<span style="color: #009900;">&#40;</span>name <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;version&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> version <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Long</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> id<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getVersion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> version<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h4 style="text-align: center;">&#8212;-</h4><h4>HibernateUtil.java</h4><p>HibernateUtil is a convenience class that automates configuration, and provides your application access to the active Session. This is where you tell Hibernate about your <em>MockObject</em> class, and where you get a handle to an object that will save, update, delete and etc. your objects.</p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.SessionFactory</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.cfg.AnnotationConfiguration</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HibernateUtil
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> SessionFactory sessionFactory<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">static</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span>
        <span style="color: #009900;">&#123;</span>
            AnnotationConfiguration config <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AnnotationConfiguration<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.dialect&quot;</span>, <span style="color: #0000ff;">&quot;org.hibernate.dialect.HSQLDialect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.connection.driver_class&quot;</span>, <span style="color: #0000ff;">&quot;org.hsqldb.jdbcDriver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.connection.url&quot;</span>, <span style="color: #0000ff;">&quot;jdbc:hsqldb:mem:demodb&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.connection.username&quot;</span>, <span style="color: #0000ff;">&quot;sa&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.connection.password&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.connection.pool_size&quot;</span>, <span style="color: #0000ff;">&quot;1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.connection.autocommit&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.cache.provider_class&quot;</span>, <span style="color: #0000ff;">&quot;org.hibernate.cache.NoCacheProvider&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.hbm2ddl.auto&quot;</span>, <span style="color: #0000ff;">&quot;create-drop&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.show_sql&quot;</span>, <span style="color: #0000ff;">&quot;true&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.transaction.factory_class&quot;</span>, <span style="color: #0000ff;">&quot;org.hibernate.transaction.JDBCTransactionFactory&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            config.<span style="color: #006633;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hibernate.current_session_context_class&quot;</span>, <span style="color: #0000ff;">&quot;thread&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Add your mapped classes here:</span>
            config.<span style="color: #006633;">addAnnotatedClass</span><span style="color: #009900;">&#40;</span>MockObject.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            sessionFactory <span style="color: #339933;">=</span> config.<span style="color: #006633;">buildSessionFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Throwable</span> ex<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Initial SessionFactory creation failed.&quot;</span> <span style="color: #339933;">+</span> ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ExceptionInInitializerError</span><span style="color: #009900;">&#40;</span>ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> SessionFactory getSessionFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> sessionFactory<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><h4 style="text-align: center;">&#8212;-</h4><h4>HibernateDemo.java</h4><p>Our driver class is very simple; it does the following things:</p><ul><li>Get a handle to Hibernate Session</li><li>Create and persist two new <em>MockObjects</em></li><li>Print out the generated IDs<em><br
/> </em></li></ul><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.Transaction</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.classic.Session</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HibernateDemo
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        Session session <span style="color: #339933;">=</span> HibernateUtil.<span style="color: #006633;">getSessionFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCurrentSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Transaction transaction <span style="color: #339933;">=</span> session.<span style="color: #006633;">beginTransaction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        MockObject object0 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MockObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        MockObject object1 <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MockObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        session.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>object0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        session.<span style="color: #006633;">save</span><span style="color: #009900;">&#40;</span>object1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        transaction.<span style="color: #006633;">commit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Object 0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Generated ID is: &quot;</span> <span style="color: #339933;">+</span> object0.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Generated Version is: &quot;</span> <span style="color: #339933;">+</span> object0.<span style="color: #006633;">getVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Object 1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Generated ID is: &quot;</span> <span style="color: #339933;">+</span> object1.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Generated Version is: &quot;</span> <span style="color: #339933;">+</span> object1.<span style="color: #006633;">getVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p>And here we are. When you run HibernateDemo, you should have a fully functional Hibernate enabled HSQL database with one table. Play around with adding new fields to your object.</p><p>Your output should look something like this:</p><pre style="padding-left: 60px;">Object 0
Generated ID is: 1
Generated Version is: 0
Object 1
Generated ID is: 2
Generated Version is: 0</pre><h4 style="text-align: center;">&#8212;-</h4><h4>Considering the <a
href="http://en.wikipedia.org/wiki/Pattern_language#Balancing_of_forces" target="_blank">Forces</a>:</h4><p>I&#8217;d like to note, here, that we&#8217;re doing a lot of configuration in the code itself. This is OK if you are relatively sure that you won&#8217;t need to be making changes to your data model or back-end configuration very frequently. However, if you know that this is going to happen, I strongly suggest using <a
href="http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html#tutorial-firstapp-configuration" target="_blank">XML configuration files</a> instead, and you should also consider using traditional Hibernate with XML object-relational mappings. If you build all configuration into your code, every time you change the configuration, you&#8217;ll have to recompile / rebuild parts of your system. It&#8217;s much easier just to edit a file. However, unless you&#8217;re sure, just cross that bridge when you come to it.</p><h4>A few more things to remember:</h4><p>Take your time. Don&#8217;t give up. Ask questions. <em>READ the forums and documentation.</em></p><p>Hibernate is BIG. It&#8217;s a very powerful, very complex tool. It took me a long time to get even a simple object relationship working the way I wanted to. The learning curve is not small, and you will probably be frustrated for a while. I have, however, come to the point where I see so much benefit, that I feel it was completely worth my time to learn.</p><p>Configuration is <strong>everything</strong>. Hibernate can do anything you want: You can use it to tie in to existing database schema; you can use it to run plain SQL queries or stored procedures.</p><p>Good luck.</p><h3>References:</h3><ol><li><a
href="http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html" target="_blank">Hibernate&#8217;s Standard Tutorial</a></li><li><a
href="http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/" target="_blank">Hibernate Annotations Reference</a></li></ol><p>This article is part of a series: <a
href="http://ocpsoft.com/java/guide-to-hibernate-annotations/" target="_self">Guide to Hibernate Annotations</a></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/getting-started-quickly-with-hibernate-annotations/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> <item><title>PrettyFaces 1.1.0 Released</title><link>http://ocpsoft.com/opensource/prettyfaces-110-released/</link> <comments>http://ocpsoft.com/opensource/prettyfaces-110-released/#comments</comments> <pubDate>Tue, 09 Dec 2008 00:00:59 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[OpenSource]]></category> <category><![CDATA[PrettyFaces]]></category> <category><![CDATA[Releases]]></category> <category><![CDATA[Java]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=30</guid> <description><![CDATA[A new release of the PrettyFaces JSF extension for Bookmarkable/Pretty URLs is now availible for download. This release includes several new features. Enhanced internal navigation/redirects. Returning “pretty:” from a JSF action method, or Pretty action method will cause a redirect to the current page. Effectively a refresh. Added the &#60;pretty:link&#62; component. Added attribute to Pretty [...]]]></description> <content:encoded><![CDATA[<p>A new release of the <a
href="http://ocpsoft.com/prettyfaces" target="_self">PrettyFaces</a> JSF extension for Bookmarkable/Pretty URLs is now availible for download. This release includes several new features.<br/><br
/> <span
id="more-30"></span></p><ul><li>Enhanced internal navigation/redirects. Returning “pretty:” from a JSF action method, or Pretty action method will cause a redirect to the current page. Effectively a refresh.</li><li>Added the &lt;pretty:link&gt; component.</li><li>Added attribute to Pretty action method configuration, allowing targeting of action methods to specific JSF phases in the lifecycle.</li></ul><p>View the documentation here, for <a
href="http://ocpsoft.com/prettyfaces#configuration" target="_self">PrettyFaces</a>.</p><p
style="text-align: center;">&#8212;-</p><p>PrettyFaces is an OpenSource JSF extension which enables creation of bookmarkable, pretty URLs made easy. Our goal was to solve this problem as simply as possible, while still enabling a useful set of functions such as: page-load actions, integration with faces navigation, dynamic view-id assignment, and managed parameter parsing. All of this without introducing unnecessary coupling.<br
/> <a
name="mailinglist"></a></p><table
style="padding: 5px;" border="0" cellspacing="0"><tbody><tr><td
style="padding-left: 5px"><strong>Subscribe to prettyfaces-users</strong></td></tr><form
action="http://groups.google.com/group/prettyfaces-users/boxsubscribe"><tr><td
style="padding-left: 5px;">Email:</p> <input
name="email" type="text" /> <input
name="sub" type="submit" value="Subscribe" /></td></tr></form><tr><td
align="right"><a
href="http://groups.google.com/group/prettyfaces-users">Visit this group</a></td></tr></tbody></table> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/opensource/prettyfaces-110-released/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Served from: ocpsoft.com @ 2010-07-29 17:22:43 by W3 Total Cache -->