<?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; JSF</title> <atom:link href="http://ocpsoft.com/tags/jsf/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 1.2 Components (Book Review)</title><link>http://ocpsoft.com/opensource/jsf-1-2-components-book-review/</link> <comments>http://ocpsoft.com/opensource/jsf-1-2-components-book-review/#comments</comments> <pubDate>Wed, 20 Jan 2010 06:56:21 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF2]]></category> <category><![CDATA[OpenSource]]></category> <category><![CDATA[Technology]]></category> <category><![CDATA[JSF]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=983</guid> <description><![CDATA[As a vocal blogger, I feel responsible for promoting and sharing the good work of others, whether that be technology, creative work, or in this case: a book. I will take no exception to that philosophy when it comes to the JavaServer Faces framework. For a quick read, try the summary. If you are intrigued, [...]]]></description> <content:encoded><![CDATA[<p>As a vocal blogger, I feel responsible for promoting and sharing the good work of others, whether that be technology, creative work, or in this case: a book. I will take no exception to that philosophy when it comes to the <a
target="_blank" href="http://www.javaserverfaces.org">JavaServer Faces</a> framework. For a quick read, try the summary. If you are intrigued, read on! I hope you find this review valuable.<br
/> <span
id="more-983"></span></p><p><strong>In summary:</strong> I would recommend buying this reference if you are a consumer, designer, UI-developer who is working with existing component libraries, Facelets or JSF 2.0, and not so much focused on creating custom Java-components of your own. I don&#8217;t, for every-day web-site components, see why you would need much more than what is featured between the covers of this book. Ian Hlavats does a fantastic job of making bringing JSF to the everyday development setting.<br
/> <br/></p><table><tr><td><a
target="_blank" href="http://www.packtpub.com/jsf-1-2-components-develop-advanced-ajax-enabled-applications/book?utm_source=ocpsoft.com&#038;utm_medium=bookrev&#038;utm_content=blog&#038;utm_campaign=mdb_002041"><img
src="http://ecx.images-amazon.com/images/I/51zwgyza8HL._SL500_AA240_.jpg"></img></a></td><td><h4><a
target="_blank" href="http://www.packtpub.com/jsf-1-2-components-develop-advanced-ajax-enabled-applications/book?utm_source=ocpsoft.com&#038;utm_medium=bookrev&#038;utm_content=blog&#038;utm_campaign=mdb_002041">JSF 1.2 Components</a></h4><p>By Ian Hlavats<br
/> <br/><br
/> Download Chapter 2: <a
target="_blank" href="http://www.packtpub.com/files/7627-developing-jsf-components-sample-chapter-2-facelets-components.pdf">Facelets Components</a> as a PDF</td></tr></table><p><br/></p><h3>In detail:</h3><p>Initially hesitant to buy a reference on components, I have to admit that I was surprised to learn so much by reading through this book. As a member of the JavaServer Faces 2.0 expert group, and a full-time software engineer, components are not my strong-suit. If you&#8217;re at all like me, then you&#8217;re probably asking yourself the same question I did:</p><p>&#8220;What can I learn in this book that I can&#8217;t find on Google? JavaServer Faces has a huge online community, and there&#8217;s a lot of information available already.&#8221;</p><p>It&#8217;s a valid question, but you should keep reading because this book offers something important that I rarely find in blog entries or wikis: &#8220;features you wouldn&#8217;t think to look for; features that you wish you&#8217;d thought of, or don&#8217;t know how to make yourself.&#8221; I wish I had found this book when I started using JSF, because I&#8217;d probably have been more comfortable, and much more productive with our component side of the life-cycle, so to speak; I discovered features of the framework, and pre-made UI-tools that I wish I&#8217;d known about years ago.</p><h5>Things you&#8217;ll learn about:</h5><p>Modal windows, menus, wizards and workflows, AJAX anything with Ajax4JSF, i18n and localization, gCal-like schedules with Apache Tomahawk, multi-field validation, calendars, charts and graphs, file-uploads, user permissions/security, skinning, styling, and all major component libraries are covered in this book (save PrimeFaces, which gets a mere mention.)</p><p>If you think you&#8217;re looking at &#8220;Just another book on JSF component writing,&#8221; that&#8217;s not entirely the case. This book provides real solutions, real examples on how to get started writing JSF applications using existing component libraries and plug-ins. There are two types of chapters in this book: tutorials and references. The tutorials will get you up and running with a quick example, while the reference sections go in depth on usage of individual components within each library.</p><p>You&#8217;ll also (as a bonus, in my opinion) get some appetite-whetting information on the JBoss Seam framework, which is a user-friendly and business-oriented extension to the Java EE technologies. I didn&#8217;t get a very good picture of all of the concepts until I actually looked at the code samples (downloadable here, or just follow the link in the preface,) but that&#8217;s hardly a strong criticism; though, it may have helped if the code samples were more explicitly, frequently referenced.</p><h5>In the end &#8220;The title doesn&#8217;t lie&#8221;:</h5><ul><li>I haven&#8217;t seen a more comprehensive book on component libraries and component writing made available to date.</li><li>JSF2 component writing has been simplified, but if you want to supplement your app with everyday things like in-place editing, accordions, and more, you&#8217;re going to want good examples; this book provides examples in abundance (even examples of JSF2 EzComp, which is a dream to use. UI like it was meant to be)</li><li>Even if components and UI design are not your strong-point, that is exactly why you should read this book; it makes component-based design easy to understand, and easy to implement.</li></ul><p>The author covers many of the advancements in component writing and simplified configuration that are provided by JSF 2.0, but I would have liked to hear some information on the component behaviors model, and mention of integration with frameworks like CDI (JSR-299) and Spring; however, this is not entirely relevant to component writing, and plenty of information exists on sites like <a
target="_blank" href="http://www.javaserverfaces.org">www.javaserverfaces.org</a> or Google.</p><p>My one complaint is that for a book titled &#8220;JSF 1.2 Components,&#8221; it did not explain, or teach me how to create custom Java-based components, which are essential for complex behavior and interaction at some level. JSF 2.0 has done a good job of making Java-based components unnecessary, but this book is titled JSF 1.2 components, thus, I would have liked to see how to write a Java-based component in JSF 1.2.</p><div
class="featured" style="text-align: center;"> <a
target="_blank" href="http://www.packtpub.com/jsf-1-2-components-develop-advanced-ajax-enabled-applications/book?utm_source=ocpsoft.com&#038;utm_medium=bookrev&#038;utm_content=blog&#038;utm_campaign=mdb_002041">JSF 1.2 Components</a> on Packt Publishing<br
/> Download Chapter 2: <a
target="_blank" href="http://www.packtpub.com/files/7627-developing-jsf-components-sample-chapter-2-facelets-components.pdf">Facelets Components</a> as a PDF</div><h3>End notes:</h3><p> Make sure you check out <a
target="_blank" href="http://www.javaserverfaces.org">www.javaserverfaces.org</a>. It&#8217;s a great starting point and reference for JSF that you will undoubtably bookmark if doing a lot of work, and doing the work with this book. Also check out <a
href="http://ocpsoft.com/prettyfaces/">http://ocpsoft.com/prettyfaces/</a> for more information on Pretty URLs in JSF, and building client-facing JSF web applications.</p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/opensource/jsf-1-2-components-book-review/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <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>Please! Tell your developers to call facesContext.release()</title><link>http://ocpsoft.com/java/jsf-java/please-tell-your-developers-to-call-facescontextrelease/</link> <comments>http://ocpsoft.com/java/jsf-java/please-tell-your-developers-to-call-facescontextrelease/#comments</comments> <pubDate>Fri, 24 Jul 2009 21:28:54 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[Best Practices]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=66</guid> <description><![CDATA[If you are manipulating any FacesContext when doing any kind of Sevlet Forwards &#8211; such as from a filter &#8211; you MUST release() any FacesContext you’ve created. The consequences of forgetting this are potentially dire. You may even want to go so far as to completely UN-set the FacesContext from the current thread. We would [...]]]></description> <content:encoded><![CDATA[<p>If you are manipulating any FacesContext when doing any kind of Sevlet Forwards &#8211; such as <a
href="http://ocpsoft.com/java/jsf-java/jsf-20-extension-development-accessing-facescontext-in-a-filter/" target="_blank">from a filter</a> &#8211; you MUST release() any FacesContext you’ve created. The consequences of forgetting this are potentially dire.<span
id="more-66"></span></p><p>You may even want to go so far as to completely UN-set the FacesContext from the current thread. We would do this by calling FacesContextBuilder.removeFacesContext()</p><h2>Call FacesContext.release() when you are done!</h2><p> </p><h4>FacesContextBuilder.java</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> FacesContextBuilder
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> FacesContext getFacesContext<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ServletRequest request, <span style="color: #000000; font-weight: bold;">final</span> ServletResponse response<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        FacesContext facesContext <span style="color: #339933;">=</span> FacesContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>facesContext <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">return</span> facesContext<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        FacesContextFactory contextFactory <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>FacesContextFactory<span style="color: #009900;">&#41;</span> FactoryFinder
                .<span style="color: #006633;">getFactory</span><span style="color: #009900;">&#40;</span>FactoryFinder.<span style="color: #006633;">FACES_CONTEXT_FACTORY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        LifecycleFactory lifecycleFactory <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>LifecycleFactory<span style="color: #009900;">&#41;</span> FactoryFinder
                .<span style="color: #006633;">getFactory</span><span style="color: #009900;">&#40;</span>FactoryFinder.<span style="color: #006633;">LIFECYCLE_FACTORY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Lifecycle lifecycle <span style="color: #339933;">=</span> lifecycleFactory.<span style="color: #006633;">getLifecycle</span><span style="color: #009900;">&#40;</span>LifecycleFactory.<span style="color: #006633;">DEFAULT_LIFECYCLE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        ServletContext servletContext <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletRequest<span style="color: #009900;">&#41;</span> request<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getServletContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        facesContext <span style="color: #339933;">=</span> contextFactory.<span style="color: #006633;">getFacesContext</span><span style="color: #009900;">&#40;</span>servletContext, request, response, lifecycle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        InnerFacesContext.<span style="color: #006633;">setFacesContextAsCurrentInstance</span><span style="color: #009900;">&#40;</span>facesContext<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">return</span> facesContext<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> removeFacesContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        InnerFacesContext.<span style="color: #006633;">setFacesContextAsCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span><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;">private</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> InnerFacesContext <span style="color: #000000; font-weight: bold;">extends</span> FacesContext
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> setFacesContextAsCurrentInstance<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> FacesContext facesContext<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            FacesContext.<span style="color: #006633;">setCurrentInstance</span><span style="color: #009900;">&#40;</span>facesContext<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: #009900;">&#125;</span></pre></div></div><p> <br
/> FacesContext wraps the HttpServletRequest with its own RequestWrapper, and when attempting to hold on to references to any response through a Servlet Forward (via <a
href="http://java.sun.com/javaee/5/docs/api/javax/servlet/RequestDispatcher.html" target="_blank">RequestDispatcher</a>), bad things will happen.</p><h4>For example:</h4><p>When using the <a
title="PrettyFaces URL Rewriting and Bookmarking" href="http://ocpsoft.com/prettyfaces">PrettyFaces URL bookmarking/rewriting</a> utility (who’s PrettyFilter relies on Servlet forwards) any FacesContext created before this forward occurs will be left open, and sporadic NullPointerExceptions will occur depending on Request thread timing in the Servlet container.<br
/>  </p><div
class="wp_syntax"><div
class="code"><pre class="java" style="font-family:monospace;">Caused by<span style="color: #339933;">:</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">NullPointerException</span>
at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">connector</span>.<span style="color: #003399;">Request</span>.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Request</span>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1424</span><span style="color: #009900;">&#41;</span>
at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">connector</span>.<span style="color: #006633;">RequestFacade</span>.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span>RequestFacade.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">503</span><span style="color: #009900;">&#41;</span>
at javax.<span style="color: #006633;">servlet</span>.<span style="color: #006633;">ServletRequestWrapper</span>.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span>ServletRequestWrapper.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">284</span><span style="color: #009900;">&#41;</span>
at com.<span style="color: #006633;">ocpsoft</span>.<span style="color: #006633;">pretty</span>.<span style="color: #006633;">PrettyContext</span>.<span style="color: #006633;">setCurrentInstance</span><span style="color: #009900;">&#40;</span>PrettyContext.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">93</span><span style="color: #009900;">&#41;</span>
at com.<span style="color: #006633;">ocpsoft</span>.<span style="color: #006633;">pretty</span>.<span style="color: #006633;">PrettyContext</span>.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span>PrettyContext.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">84</span><span style="color: #009900;">&#41;</span>
at com.<span style="color: #006633;">ocpsoft</span>.<span style="color: #006633;">pretty</span>.<span style="color: #006633;">PrettyFilter</span>.<span style="color: #006633;">doFilter</span><span style="color: #009900;">&#40;</span>PrettyFilter.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">58</span><span style="color: #009900;">&#41;</span>
at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">ApplicationFilterChain</span>.<span style="color: #006633;">internalDoFilter</span><span style="color: #009900;">&#40;</span>ApplicationFilterChain.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">235</span><span style="color: #009900;">&#41;</span>
at org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">core</span>.<span style="color: #006633;">ApplicationFilterChain</span>.<span style="color: #006633;">doFilter</span><span style="color: #009900;">&#40;</span>ApplicationFilterChain.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">206</span><span style="color: #009900;">&#41;</span>
...</pre></div></div><p> <br
/> Or sometimes request attributes will be missing entirely, even if the request is accessible.<br
/>  <br
/> In order to safely navigate FacesContext in a ServletFilter, make absolutely sure that you release() and remove the context when you are done with it. Then you get happy applications working together with other frameworks!<br
/>  <br
/> Cheers, happy developing! <img
src='http://ocpsoft.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/jsf-java/please-tell-your-developers-to-call-facescontextrelease/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Spring Security &#8211; What happens after /you/ log in?</title><link>http://ocpsoft.com/java/jsf-java/spring-security-what-happens-after-you-log-in/</link> <comments>http://ocpsoft.com/java/jsf-java/spring-security-what-happens-after-you-log-in/#comments</comments> <pubDate>Fri, 24 Jul 2009 02:23:59 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[Spring]]></category> <category><![CDATA[Security]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=64</guid> <description><![CDATA[So you&#8217;ve got Spring Security up and running. Great! Now you&#8217;ve got a login page, and you just added a form on the global page menu to allow users to Login from any public page. There&#8217;s just one problem. When they log-in from a public page, they’re redirected to the default-login-url! Your users will have [...]]]></description> <content:encoded><![CDATA[<p>So you&#8217;ve got Spring Security up and running. Great! Now you&#8217;ve got a login page, and you just added a form on the global page menu to allow users to Login from any public page. There&#8217;s just one problem. When they log-in from a public page, they’re redirected to the default-login-url! Your users will have to re-navigate to the page they were already viewing when they logged in, or maybe they&#8217;ll just use the much dreaded &#8220;Back&#8221; button. That&#8217;s not a good interaction, but we have a solution. <span
id="more-64"></span></p><p><strong>UPDATE:</strong> There is a simpler, but less complete solution built in. (<a
href="http://forum.springsource.org/showthread.php?t=65123">See here</a>.) This means appending &#8220;?spring-security-redirect=/your/target/url&#8221; to your redirect to the Spring Security Filter chain.</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><p>If you have not already completed <a
href=http://ocpsoft.com/java/acegi-spring-security-jsf-login-page/ id=ornu title="integrating Spring Security and JSF">integrating Spring Security and JSF</a>, please consider it, as this article depends on having a working JSF login page and managed bean.<br
/>  <br
/> <strong>Note:</strong> This approach will not work if you are invalidating/re-creating the session after a successful authentication (see <a
target="_blank" href="http://static.springsource.org/spring-security/site/docs/3.0.x/reference/ns-config.html#ns-session-fixation">Session Fixation attacks</a>). Supporting session invalidation would take some extra work that will not be in the scope of this article.<p/><h2>The login form</h2><p>Here is a basic JSF/Spring Security login form. It would be nice if we could enable or disable the redirect functionality, so we’ll add a hidden form field that is only rendered on demand (here we use Facelets <a
target="_blank" href="https://javaserverfaces.dev.java.net/nonav/docs/2.0/pdldocs/facelets/ui/param.html">ui:param</a> functionality for our on-off switch.)<br
/>  </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:form</span> <span style="color: #000066;">prependId</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;c:if</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;#{redirect == 'true'}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;redirect&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/c:if<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;j_username&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;h:outputText</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Username:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;ocp:message</span></span>
<span style="color: #009900;">        <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;j_username&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:inputText</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;j_username&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{loginBean.username}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&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;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></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>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;j_password&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;h:outputText</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Password:&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;ocp:message</span></span>
<span style="color: #009900;">        <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;j_password&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:inputSecret</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;j_password&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{loginBean.password}&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&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;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></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>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;_spring_security_remember_me&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;h:outputText</span></span>
<span style="color: #009900;">        <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Remember me&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:selectBooleanCheckbox</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;_spring_security_remember_me&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{loginBean.rememberMe}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></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>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:commandButton</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;login&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#{loginBean.doLogin}&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Login&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;h:commandButton</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">styleClass</span>=<span style="color: #ff0000;">&quot;faded&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;cancel&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#{loginBean.doCancel}&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Cancel&quot;</span> <span style="color: #000066;">immediate</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></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>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><p/><h2>The login action method</h2><p>First, check to make sure that we actually want to do a redirect after login. Do this by testing for the existence of our hidden form parameter.<br
/>  <br
/> Find the full LoginBean code <a
target="_blank" href="http://ocpsoft.com/java/acegi-spring-security-jsf-login-page/">here</a>.</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: #003399;">String</span> doLogin<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;">IOException</span>, ServletException
<span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">String</span> redirect <span style="color: #339933;">=</span> FacesUtils.<span style="color: #006633;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;redirect&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>redirect <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>redirect.<span style="color: #006633;">isEmpty</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>
        redirect <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;">getOriginalRequestUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Map<span style="color: #339933;">&lt;</span>String, Object<span style="color: #339933;">&gt;</span> sessionMap <span style="color: #339933;">=</span> FacesContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSessionMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        sessionMap.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>LoginRedirectFilter.<span style="color: #006633;">LAST_URL_REDIRECT_KEY</span>, redirect<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    FacesUtils.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">dispatch</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/j_spring_security_check&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    FacesUtils.<span style="color: #006633;">getFacesContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">responseComplete</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p> <br
/> Before forwarding to the Spring Security /j_security_login_check intercepting filter chain, we’ll need to set the current URL into a Session attribute: “LoginRedirectFilter.LAST_URL_REDIRECT_KEY”.<br
/>  <br
/> This will be used in our custom filter after the user successfully authenticates with Spring Security.</p><p/><h2>The login filter</h2><p>Here is where we’ll check for the existence of our session attribute: “LAST_URL_REDIRECT_KEY”. If this key contains a value, then we should redirect the user to that URL. If the key does not contain a value, then we should not perform any redirect, and continue as normal.<br
/>  <br
/> One other concern is: what if authentication failed? Let&#8217;s assume that Spring Security will redirect the user to the Login Page if they send invalid credentials. We don&#8217;t want to trigger a redirect as they try to access the login page, so we also check to make sure we have a successfully authenticated user before redirecting.<br
/>  </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;">java.io.IOException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.Filter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.FilterChain</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.FilterConfig</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpSession</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.authentication.AnonymousAuthenticationToken</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.core.Authentication</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.core.context.SecurityContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.core.context.SecurityContextHolder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.stereotype.Component</span><span style="color: #339933;">;</span>
&nbsp;
@<span style="color: #003399;">Component</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> LoginRedirectFilter <span style="color: #000000; font-weight: bold;">implements</span> Filter
<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: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> LAST_URL_REDIRECT_KEY <span style="color: #339933;">=</span> LoginRedirectFilter.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;LAST_URL_REDIRECT_KEY&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> destroy<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doFilter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> ServletRequest request, <span style="color: #000000; font-weight: bold;">final</span> ServletResponse response, <span style="color: #000000; font-weight: bold;">final</span> FilterChain chain<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, ServletException
    <span style="color: #009900;">&#123;</span>
        HttpSession session <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>HttpServletRequest<span style="color: #009900;">&#41;</span> request<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> redirectUrl <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span> session.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span>LAST_URL_REDIRECT_KEY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isAuthenticated<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>redirectUrl <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>redirectUrl.<span style="color: #006633;">isEmpty</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>
            session.<span style="color: #006633;">removeAttribute</span><span style="color: #009900;">&#40;</span>LAST_URL_REDIRECT_KEY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            HttpServletResponse resp <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HttpServletResponse<span style="color: #009900;">&#41;</span> response<span style="color: #339933;">;</span>
            resp.<span style="color: #006633;">sendRedirect</span><span style="color: #009900;">&#40;</span>redirectUrl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #009900;">&#123;</span>
            chain.<span style="color: #006633;">doFilter</span><span style="color: #009900;">&#40;</span>request, response<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;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> isAuthenticated<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">boolean</span> result <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        SecurityContext context <span style="color: #339933;">=</span> SecurityContextHolder.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>context <span style="color: #000000; font-weight: bold;">instanceof</span> SecurityContext<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            Authentication authentication <span style="color: #339933;">=</span> context.<span style="color: #006633;">getAuthentication</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>authentication <span style="color: #000000; font-weight: bold;">instanceof</span> AnonymousAuthenticationToken<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #666666; font-style: italic;">// not authenticated</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>authentication <span style="color: #000000; font-weight: bold;">instanceof</span> Authentication<span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                result <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> FilterConfig filterConfig<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> ServletException
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div><p> <p/><h2>Web.xml</h2><p>Some specific configuration is required to ensure the proper ordering of our filters. LoginRedirectFilter&#8217;s filter-mapping must be placed after any Spring Security filters &#8211; otherwise we will redirect too soon, and authentication will never occur. You probably want to place it before any filters that apply business logic.</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>loginRedirectFilter<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>org.springframework.web.filter.DelegatingFilterProxy<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>loginRedirectFilter<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;/filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><p/><h2>Putting it all together</h2><p>This sequence diagram describes the entire process, including what Spring Security will be doing after intercepting the /j_security_check forwarded from LoginBean:<br
/> You should now have a functional LoginRedirectFilter configured in tandem with Spring Security. Please feel free to post any suggestions or questions.</p><p/> <a
target="_blank" href='http://ocpsoft.com/wp-content/uploads/2009/07/sequence.png'><img
src="http://ocpsoft.com/wp-content/uploads/2009/07/sequence-300x212.png" alt="Sequence Diagram for LoginRedirectFilter Flow" title="LoginRedirectFilter Sequence" width="300" height="212" class="alignnone size-medium wp-image-65" /></a></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/jsf-java/spring-security-what-happens-after-you-log-in/feed/</wfw:commentRss> <slash:comments>14</slash:comments> </item> <item><title>PrettyFaces 1.2.4_GA and 2.0.1_GA Released</title><link>http://ocpsoft.com/prettyfaces/prettyfaces-124_ga-and-201_ga-released/</link> <comments>http://ocpsoft.com/prettyfaces/prettyfaces-124_ga-and-201_ga-released/#comments</comments> <pubDate>Sat, 13 Jun 2009 17:12:03 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[PrettyFaces]]></category> <category><![CDATA[Releases]]></category> <category><![CDATA[JSF]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=59</guid> <description><![CDATA[PrettyFaces: New versions of PrettyFaces for JSF1.2 and JSF2.0 are now available for download: 1.2.4_GA: jar, src 2.0.1_GA: jar, src Minor Release: 20090613 Fixed non-redirecting faces-navigation integration. Enhanced null handling for mis-configured viewIds Now supports browsers with cookies disabled Subscribe to prettyfaces-users Email:&#160;]]></description> <content:encoded><![CDATA[<h3><a
href="http://ocpsoft.com/prettyfaces">PrettyFaces</a>:</h3><p>New versions of PrettyFaces for JSF1.2 and JSF2.0 are now available for download:<br
/> <span
id="more-59"></span></p><p
style="padding-left: 30px;"><strong>1.2.4_GA:</strong> <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.2.4_GA.jar">jar</a>, <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-1.2.4_GA-sources.jar">src</a></p><p
style="padding-left: 30px;"><strong>2.0.1_GA:</strong> <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-2.0.1_GA.jar">jar</a>, <a
href="http://prettyfaces.googlecode.com/files/ocpsoft-pretty-faces-2.0.1_GA-sources.jar">src</a></p><p>Minor Release: 20090613</p><ol><li>Fixed non-redirecting faces-navigation integration.</li><li>Enhanced null handling for mis-configured viewIds</li><li>Now supports browsers with cookies disabled</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-124_ga-and-201_ga-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>Revisited &#8211; Acegi/Spring Security &amp; JSF Login Page</title><link>http://ocpsoft.com/java/jsf-java/revisited-acegispring-security-jsf-login-page/</link> <comments>http://ocpsoft.com/java/jsf-java/revisited-acegispring-security-jsf-login-page/#comments</comments> <pubDate>Mon, 27 Apr 2009 22:00:07 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[Spring]]></category> <category><![CDATA[Security]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=55</guid> <description><![CDATA[A correction has been made to the post: http://ocpsoft.com/java/acegi-spring-security-jsf-login-page/, fixing an issue where FacesMessages were not being displayed on failed authentications. Because the example had initially used the @PostConstruct annotation to trigger a method to handle the error message, the handleError() method was being called before the actual authentication event had taken place, thus, the [...]]]></description> <content:encoded><![CDATA[<p>A correction has been made to the post: <a
href="http://ocpsoft.com/java/acegi-spring-security-jsf-login-page/" target="_self">http://ocpsoft.com/java/acegi-spring-security-jsf-login-page/</a>, fixing an issue where FacesMessages were not being displayed on failed authentications.<br
/> <span
id="more-55"></span></p><p>Because the example had initially used the @PostConstruct annotation to trigger a method to handle the error message, the handleError() method was being called before the actual authentication event had taken place, thus, the handleError() method was triggering before any BadCredentialsExceptions were stored in the Session.</p><p>Instead of creating an error handling method in the LoginBean itself, instead attach a PhaseListener which will intercept failed logins, and add the new FacesMessage before the RENDER_RESPONSE phase.</p><h3>LoginErrorPhaseListener</h3><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;">javax.faces.context.FacesContext</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.event.PhaseEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.event.PhaseId</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.event.PhaseListener</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.BadCredentialsException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.springframework.security.ui.AbstractProcessingFilter</span><span style="color: #339933;">;</span>
&nbsp;
impot util.<span style="color: #006633;">FacesUtils</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> LoginErrorPhaseListener <span style="color: #000000; font-weight: bold;">implements</span> PhaseListener
<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> <span style="color: #000066; font-weight: bold;">long</span> serialVersionUID <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>1216620620302322995L<span style="color: #339933;">;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> beforePhase<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> PhaseEvent arg0<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Exception</span> e <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span><span style="color: #009900;">&#41;</span> FacesContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSessionMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>
                AbstractProcessingFilter.<span style="color: #006633;">SPRING_SECURITY_LAST_EXCEPTION_KEY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e <span style="color: #000000; font-weight: bold;">instanceof</span> BadCredentialsException<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            FacesContext.<span style="color: #006633;">getCurrentInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSessionMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>
                    AbstractProcessingFilter.<span style="color: #006633;">SPRING_SECURITY_LAST_EXCEPTION_KEY</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            FacesUtils.<span style="color: #006633;">addErrorMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Username or password not valid.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> afterPhase<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> PhaseEvent arg0<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> PhaseId getPhaseId<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> PhaseId.<span style="color: #006633;">RENDER_RESPONSE</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div><h3>faces-config.xml</h3><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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;faces-config</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.2&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span> <span style="color: #000066;">xmlns:xi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XInclude&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 style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.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;lifecycle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phase-listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>login.LoginErrorPhaseListener<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phase-listener<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lifecycle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/faces-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div><h3>Happy developing!</h3> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/jsf-java/revisited-acegispring-security-jsf-login-page/feed/</wfw:commentRss> <slash:comments>0</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> </channel> </rss>
<!-- Served from: ocpsoft.com @ 2010-07-29 17:18:31 by W3 Total Cache -->