<?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; Pretty URL</title> <atom:link href="http://ocpsoft.com/tags/pretty-url/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>Make JSF intuitive, with bookmarkable and pretty URLs</title><link>http://ocpsoft.com/uncategorized/jsf-get-bookmarkable-and-pretty-urls/</link> <comments>http://ocpsoft.com/uncategorized/jsf-get-bookmarkable-and-pretty-urls/#comments</comments> <pubDate>Thu, 13 Nov 2008 06:28:01 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[OpenSource]]></category> <category><![CDATA[Uncategorized]]></category> <category><![CDATA[Pretty URL]]></category> <category><![CDATA[PrettyFaces]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=24</guid> <description><![CDATA[What makes Pretty URLs in JSF so hard, and so slow? Speed up development, reduce bandwidth, enhance user experience. This article gives a brief overview of JSF navigation, some of the problems, and potentially how to solve them by enabling bookmarkable, pretty URLs. Put simply&#8230; in my view, out of the box, JSF is a [...]]]></description> <content:encoded><![CDATA[<h2>What makes Pretty URLs in JSF so hard, and so slow?</h2><p>Speed up development, reduce bandwidth, enhance user experience. This article gives a brief overview of JSF navigation, some of the problems, and potentially how to solve them by enabling bookmarkable, pretty URLs. Put simply&#8230; in my view, out of the box, JSF is a web framework designed for web-<em>applications</em>, not designed for web-<em>sites. <a
href="http://ocpsoft.com/prettyfaces/">PrettyFaces</a> addresses most of these issues.<br
/> </em></p><h3>Target audience for this article:</h3><ol><li>The reader is familiar with JSF navigation.</li><li>The reader is attempting to create a JSF app with bookmarkable &#8220;pretty&#8221; URLs. E.g.: &#8230;/mysite/archives/2008/11/11/</li><li>The reader is familiar with HTTP request/response at a basic level.</li></ol><p><span
id="more-24"></span></p><h3>The difference between a web-application / web-site</h3><h4>When I think of a web-site, I think of a group of pages having:</h4><ul><li>Multiple points of entry</li><li>Navigation via &lt;a href&gt; or &lt;form&gt; HTML elements.</li><li>Mostly stateless; the application may care who you are, but usually does not care where you came from, or where you have been.</li></ul><h4>When I think of a web-application, I think of a group of pages having:</h4><ul><li>One or only a few points of entry (login page, etc. No direct links.)</li><li>Navigation via page-flows.</li><li>Mostly stateful; the application cares who you are and where you have been.</li></ul><p>So when I say that JSF was designed for applications, I mean that without extension, normal, mostly-stateless web-behavior can be more difficult to implement than stateful web-behavior. The problem here, however, is that if a web-site is &#8220;stateless,&#8221; JSF forces you to behave in a stateful way. Here&#8217;s why.</p><h3>&lt;h:form&gt; &#8211; the root of the problem</h3><p>Forms in JSF are rendered by the &lt;h:form&gt; component, and each form must post back to the viewId from which it was rendered (aptly named a postback.) Once the form has been submitted back to the requested URL, JSF will determine which page the user should see next, and either render that view, or redirect the client&#8217;s browser to a new URL.</p><ul><li>An example view Id: <em>&#8230;/mysite/faces/articles/viewArchives.jsf</em></li></ul><p>There are a few existing frameworks to get our bookmarkable URLs, but all suffer from a troubling set of problems:</p><ol><li><a
href="https://restfaces.dev.java.net/">Restfaces</a> &#8211; solely intended to manage Pretty/Bookmarkable JSF navigation</li><li><a
href="https://javaserverfaces.dev.java.net/sandbox/components/prettyUrl.html" target="_blank">PrettyUrlPhaseListener</a> &#8211; a small utility provided in the sandbox for Mojarra Scales</li><li><a
href="http://tuckey.org/urlrewrite/">UrlRewriteFilter</a>Cannot process unordered query-parameters reliably: &#8216;?foo=1&#038;bar=2&#8242; vs. &#8216;?bar=2&#038;foo=1&#8242;</li></ol><p>And most serious solutions have heavyweight configurations with a steep learning-curve.</p><h4>Problems:</h4><ul><li>When you submit a form, the JSF view ID is shown in the URL bar instead of the Pretty URL. This occurs for validation and also standard navigation without server-side redirects.</li><li>When form validation occurs, the view ID is again shown in the URL bar. This causes contextual information contained in the URL to be lost. The information must instead be rendered as hidden form input fields, and re-submitted with the form. The developer must now manually process these values and reload them in <em>every</em> action method. The other option is to make your managed beans &#8220;session&#8221; scoped, which causes other problems.</li><li>Mulitple requests to preserve the URL mean wasted bandwidth, longer client wait times, and higher CPU utilization.</li></ul><h2>A proposed solution</h2><p>It&#8217;s simple, really&#8230; Modify JSF to submit the form to the pretty URL<em> (/mapped/page)</em> instead of the view Id <em>(/faces/page.jsf)</em></p><ul><li>An example PrettyFaces URL: <em>&#8230;/mysite/archives/2008/11/11/</em></li></ul><p>(Read through the presentation to see why PrettyFaces, a new OpenSource library by OcpSoft, may be a good alternative)</p><p
style="text-align: center;">&#8212;-</p><h3>How to make JSF bookmarkable like a web-<em>site</em>, not behave like an <em>application</em>.</h3><div
id="__ss_739738" style="width: 425px; text-align: left;"><a
style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" title="Bookmarkable JSF: Pretty4JSF" href="http://www.slideshare.net/lincolnthree/bookmarkable-jsf-pretty4jsf-presentation?type=powerpoint">Bookmarkable JSF: Pretty4JSF</a><object
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param
name="allowFullScreen" value="true" /><param
name="allowScriptAccess" value="always" /><param
name="src" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=prettybookmarkablejsf-1226356164820988-8&amp;rel=0&amp;stripped_title=bookmarkable-jsf-pretty4jsf-presentation" /><embed
type="application/x-shockwave-flash" width="425" height="355" src="http://static.slideshare.net/swf/ssplayer2.swf?doc=prettybookmarkablejsf-1226356164820988-8&amp;rel=0&amp;stripped_title=bookmarkable-jsf-pretty4jsf-presentation" allowscriptaccess="always" allowfullscreen="true"></embed></object></p><div
style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View SlideShare <a
style="text-decoration:underline;" title="View Bookmarkable JSF: Pretty4JSF on SlideShare" href="http://www.slideshare.net/lincolnthree/bookmarkable-jsf-pretty4jsf-presentation?type=powerpoint">presentation</a> or <a
style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a
style="text-decoration:underline;" href="http://slideshare.net/tag/jsf">jsf</a> <a
style="text-decoration:underline;" href="http://slideshare.net/tag/url">url</a>)</div></div><p
style="text-align: center;">&#8212;-</p><h2>Conclusion:</h2><p>When the form is submitted to the pretty URL instead of the JSF view ID, you gain performance, save resources, and make life for the developer easier; parameter values are not lost, and do not need to be coded into the form or session scoped beans.</p><p>Try <a
href="http://ocpsoft.com/prettyfaces/">PrettyFaces</a>, an opensource solution by OcpSoft. (Check the project homepage, <a
href="http://ocpsoft.com/prettyfaces/">here</a>).</p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/uncategorized/jsf-get-bookmarkable-and-pretty-urls/feed/</wfw:commentRss> <slash:comments>16</slash:comments> </item> </channel> </rss>
<!-- Served from: ocpsoft.com @ 2010-07-29 17:10:05 by W3 Total Cache -->