<?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/cat/java/jsf-java/feed/" rel="self" type="application/rss+xml" /><link>http://ocpsoft.com</link> <description>&#34;Simple Software&#34;</description> <lastBuildDate>Tue, 27 Jul 2010 15:07:50 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0</generator> <item><title>One year&#8217;s time</title><link>http://ocpsoft.com/opensource/one-years-time/</link> <comments>http://ocpsoft.com/opensource/one-years-time/#comments</comments> <pubDate>Thu, 28 Jan 2010 17:53:39 +0000</pubDate> <dc:creator>Derek</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[JSF2]]></category> <category><![CDATA[OCPSoft]]></category> <category><![CDATA[OpenSource]]></category> <category><![CDATA[PrettyFaces]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=788</guid> <description><![CDATA[It is amazing what can be done in exactly one year&#8217;s time.  January 17th will have been the 2nd anniversary since Lincoln Baxter and I started OcpSoft.  It&#8217;s been one seriously fun, and wild, ride with JavaServer Faces and the open-source community.  I want to take a moment to talk about my partner&#8217;s success story [...]]]></description> <content:encoded><![CDATA[<p>It is amazing what can be done in exactly one year&#8217;s time.  January 17th will have been the 2nd anniversary since Lincoln Baxter and I started OcpSoft.  It&#8217;s been one seriously fun, and wild, ride with <a
href="http://www.javaserverfaces.org">JavaServer Faces</a> and the open-source community.  I want to take a moment to talk about my partner&#8217;s success story and what he has accomplished in just <em>one</em> short year.</p><p><span
id="more-788"></span></p><h3>The Beginning</h3><p>When we started OcpSoft, we were working on what is now <a
title="ScrumShark" href="http://ocpsoft.com/scrumshark/" target="_blank">ScrumShark</a> &#8211; using JSF 1.2 , Hibernate, and many other technologies.  At first it was very overwhelming, challenging to figure out which technologies to use; though, even after we had chosen our technology stack, we fought with poor documentation, lack of support, and integration as we explored new features of the stack.</p><p>During that time Lincoln saw a need for pretty URLs, because what was currently on the market wasn&#8217;t intuitive, and was painful to work with.  The enhancements we requested weren&#8217;t getting approved or were too slow coming, even providing patches.  So Lincoln set out to do it himself, and as he puts it: &#8220;destroyed Thanksgiving 2008.&#8221;</p><h3>PrettyFaces</h3><p>Thanks to <a
href="http://ocpsoft.com/prettyfaces/">PrettyFaces</a>, Lincoln dug-in to JSF and started to really understand the inner workings of both problem and solution; within a few weeks of releasing version one, we were seeing many supporters.  Soon after, Lincoln was contacted by Dan Allen from JBoss/Red Hat, and started assisting him with an enhancement to JSF&#8217;s navigation system.</p><p>During that same time Lincoln convinced us &#8211; at OcpSoft &#8211; to start using JSF 2 Beta to build ScrumShark.  JSF 2 was undergoing continuous changes at that time, and the specification wasn&#8217;t even public, so we were seeing different results in our application every week.  Lincoln started posting the issues on the JSF 2 mailing list, and quickly became known as the JSF 2 tester, bug-finder.  Without <a
title="ScrumShark" href="http://ocpsoft.com/scrumshark/" target="_blank">ScrumShark</a>, and Lincoln willing to take a chance on a bleeding edge technology, I don&#8217;t think the JSF 2 team would have found and fixed all the bugs as fast as they did.  Not too long after this, he joined the JSF Expert Group and was presenting <a
href="http://ocpsoft.com/prettyfaces/jsfsummit-2009-prettyfaces-makes-an-appearance/" target="_blank">PrettyFaces at JSFSummit</a>.</p><h3>Congratulations Lincoln!</h3><p>He just got a job with <a
target="_blank" href="http://jboss.org">JBoss</a> at <a
target="_blank" href="http://www.redhat.com">Red Hat</a>, as a Senior Software Engineer. I am <em>proud </em>of of what my partner and best friend Lincoln has accomplished.</p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/opensource/one-years-time/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>JSF2 &#8211; Engaging the Community</title><link>http://ocpsoft.com/java/jsf-java/jsf2-engaging-the-community/</link> <comments>http://ocpsoft.com/java/jsf-java/jsf2-engaging-the-community/#comments</comments> <pubDate>Wed, 02 Dec 2009 20:43:57 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[JSF2]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=474</guid> <description><![CDATA[JSF2 is an amazing web-framework, and as part of our initiative to engage the community, Dan Allen, Andy Schwartz, Kito Mann, the rest of the Expert Group, and I have been putting together a &#8220;JSF Root Node&#8221; (as Ed Burns put it.) A website to be the first place people go to when they think [...]]]></description> <content:encoded><![CDATA[<p>JSF2 is an <b>amazing</b> web-framework, and as part of our initiative to engage the community, Dan Allen, Andy Schwartz, Kito Mann, the rest of the Expert Group, and I have been putting together a &#8220;JSF Root Node&#8221; (as Ed Burns put it.) A website to be the first place people go to when they think of JSF.</p><p><span
id="more-474"></span></p><div
class="featured"><center></p><h3><a
href="http://www.javaserverfaces.org" target="_blank">www.javaserverfaces.org</a></h3><p>(note: &#8220;www&#8221;, which is required at this time.)<br
/></center></div><h1>Goals of the site</h1><ul><li>Provide a definitive starting point for users to get involved with JSF.</li><li>Provide information &#8220;About JSF&#8221;, Information about the Spec, &#8220;Getting Started&#8221;, &#8220;Documentation&#8221;, &#8220;FAQ&#8221;, Community Involvement, and anything else that we all think necessary to engage and promote our user-base.</li><li>The site will &#8220;out-link&#8221; as appropriate to additional resources.</li><li>Promote ourselves as a competitive/welcoming solution in the Java-web framework community, both at the corporate and consumer/developer level.</li></ul><h1>Intent:</h1><p>We intend for this site to be comparable to http://php.net and http://grails.org, to look and feel attractive, and to really draw people into the JSF world. There are some resources on the way to help get this shell/stopgap site off of google sites, and on to a real web-server, with real functionality, and a smooth look &#038; feel.</p><p>It&#8217;s my personal goal to get this site written using JSF itself, and to make it the product of all of our ideas put together.</p><p>This site is for all of us, to benefit all of us, and the initial announcement is a little late. But if people ask how they can get started with JSF, we should all be pointing them to the same place: <b>www.javaserverfaces.org</b></p><h1>Why now?</h1><p>Well it&#8217;s simple: Yes, we&#8217;re late, but better late than never. With JSF2 just released, and the <a
href="http://www.jsfsummit.com">JSFSummit Conference</a> under-way, what better time to get people together around JSF2 during these two notable events?</p><p>I won&#8217;t get started about why this wasn&#8217;t taken care of when SUN first released JSF 1.0, but long story short, it&#8217;s getting fixed now.</p><h1>What should we include on this site?</h1><p>This depends on you, the community. Since JSF is the new Java EE 6 standard web-application framework, more and more people are going to be getting involved. What do you want to know? How can we best help you get started? Please let us know, and enjoy <img
src='http://ocpsoft.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> Like I said, JSF2 is a spectacular web framework &#8211; post your comments here and let us know what information you want to see about it.</p><h1>How to get started in 5 minutes:</h1><p>This is so simple, just check it out: <a
href="http://www.javaserverfaces.org/get-started" target="_blank">http://www.javaserverfaces.org/get-started</a></p><p><br/></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/jsf-java/jsf2-engaging-the-community/feed/</wfw:commentRss> <slash:comments>15</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>JSF2: How to Create a Global Ajax Status Indicator</title><link>http://ocpsoft.com/java/jsf-java/jsf2-how-to-create-a-global-ajax-status-indicator/</link> <comments>http://ocpsoft.com/java/jsf-java/jsf2-how-to-create-a-global-ajax-status-indicator/#comments</comments> <pubDate>Thu, 10 Sep 2009 11:28:01 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[Ajax]]></category> <category><![CDATA[JSF2]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=81</guid> <description><![CDATA[So, one of the best ways I know of to tell a user that they should be waiting for something to finish, is by setting the cursor to &#8216;wait&#8217;. It&#8217;s how desktop applications do it. It&#8217;s how the operating system does it&#8230; it&#8217;s how ajax should probably do it (if you want to solve the [...]]]></description> <content:encoded><![CDATA[<p>So, one of the best ways I know of to tell a user that they should be waiting for something to finish, is by setting the cursor to &#8216;wait&#8217;. It&#8217;s how desktop applications do it. It&#8217;s how the operating system does it&#8230; it&#8217;s how ajax should probably do it (if you want to solve the user wait interaction globally.)</p><p>With JSF2, it&#8217;s easy to accomplish!<br
/> <span
id="more-81"></span><br
/> This blog is based on Jim Driscoll&#8217;s blog, &#8220;<a
href="http://weblogs.java.net/blog/driscoll/archive/2009/09/02/busy-status-indicator-jsf-2" target="_blank">Busy status indicator with JSF 2.</a>&#8221; &#8212; for attaching a status to an individual event.</p><h3>In your XHTML page, make sure that you output the JSF2 ajax libraries:</h3><div
class="wp_syntax"><div
class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div><h3>Now, in Javascript:</h3><p>Make sure this javascript is only executed once per page, or you might get conflicting updates.</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * ***************************************
 * Busy Status
 */</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;busystatus&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> busystatus <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
busystatus.<span style="color: #660066;">onStatusChange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> onStatusChange<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">status</span> <span style="color: #339933;">=</span> data.<span style="color: #000066;">status</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajax event triggered&quot;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">status</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;begin&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// turn on busy indicator</span>
		document.<span style="color: #660066;">body</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">cursor</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'wait'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// turn off busy indicator, on either &quot;complete&quot; or &quot;success&quot;</span>
		document.<span style="color: #660066;">body</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">cursor</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'auto'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
jsf.<span style="color: #660066;">ajax</span>.<span style="color: #660066;">addOnEvent</span><span style="color: #009900;">&#40;</span>busystatus.<span style="color: #660066;">onStatusChange</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>And that&#8217;s all there is to it! Your mouse cursor will now change to the hourglass when a user triggers any JSF2 ajax event.</p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/jsf-java/jsf2-how-to-create-a-global-ajax-status-indicator/feed/</wfw:commentRss> <slash:comments>2</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>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>Un-Documented JSF: Reference</title><link>http://ocpsoft.com/java/undocumented-jsf/</link> <comments>http://ocpsoft.com/java/undocumented-jsf/#comments</comments> <pubDate>Mon, 16 Feb 2009 03:44:43 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[Java]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=42</guid> <description><![CDATA[Add a comment with your experience or &#8220;gotcha!&#8221; Java Server Faces is currently full of relatively undocumented features and behavior. As part of the JSF2 release, OcpSoft is working with a few folks at Seam/Redhat to try to address these issues and provide better documentation. If you have used, or currently use JSF, we need [...]]]></description> <content:encoded><![CDATA[<h2>Add a comment with your experience or &#8220;gotcha!&#8221;</h2><p>Java Server Faces is currently full of relatively undocumented features and behavior. As part of the JSF2 release, OcpSoft is working with a few folks at Seam/Redhat to try to address these issues and provide better documentation.<br
/> <span
id="more-42"></span></p><h2>If you have used, or currently use JSF, we need your help.</h2><p>What did you find that was backwards from what you expected? What did you find that you couldn&#8217;t find anything about?</p><p>As we progress, we&#8217;ll compile the QA and make sure it gets preserved here, and on the official documentation site when it arrives, so that others don&#8217;t get lost on the same issues. It might even make it into the JSF2 specification if it needs to be fixed!</p><h3>We&#8217;ll start it out:</h3><p>&#8220;I used the JSF DateTimeConverter to format an input field into a Date, but the dates were sometimes one day behind. Why?&#8221;</p><h3>You need to specify the timezone in <em>each</em> converter:</h3><p>JSF1.x uses UTC by default. It does not use the server timezone!</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;f:convertDateTime</span> <span style="color: #000066;">timeZone</span>=<span style="color: #ff0000;">&quot;America/New_York&quot;</span>  ... <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
--or using a bean to specify the timezone based on the current user--
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:convertDateTime</span> <span style="color: #000066;">timeZone</span>=<span style="color: #ff0000;">&quot;#{settingsBean.userTimezone}&quot;</span>  ... <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div><p>JSF2 will be addressing this issue at a configuration level, so adding timezones to each converter will no longer be necessary, but until then, you may want to think about <a
href="http://www.javabeat.net/tips/147-custom-datetimeconverter-in-jsf.html">writing a custom converter</a> yourself.</p><h3>If you need to use XML markup in your comment, please <a
href="http://www.string-functions.com/htmlencode.aspx">encode it first</a>!</h3><p>Otherwise it will disappear completely <img
src='http://ocpsoft.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br
/> <br/></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/undocumented-jsf/feed/</wfw:commentRss> <slash:comments>27</slash:comments> </item> <item><title>Java Server Faces 2.0 is in Good Hands</title><link>http://ocpsoft.com/java/jsf2-in-good-hands/</link> <comments>http://ocpsoft.com/java/jsf2-in-good-hands/#comments</comments> <pubDate>Tue, 10 Feb 2009 23:44:39 +0000</pubDate> <dc:creator>Lincoln</dc:creator> <category><![CDATA[JSF]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JSF 2.0]]></category> <category><![CDATA[OpenSource]]></category> <category><![CDATA[PrettyFaces]]></category><guid
isPermaLink="false">http://ocpsoft.com/?p=41</guid> <description><![CDATA[&#8220;The community was speaking, but until recently, nobody was listening.&#8221; A lot has changed since May 15, 2001, when the first ballot review of the JSF 1.0 framework was just beginning. To this day, Sun&#8217;s flagship web-application framwork has been an uncompromising box of tricks and gotchas, with little community adoption. This has been mostly [...]]]></description> <content:encoded><![CDATA[<blockquote><h2 style="text-align: center;">&#8220;The community was speaking, but until recently, nobody was listening.&#8221;</h2></blockquote><p>A lot has changed since May 15, 2001, when the first ballot review of the JSF 1.0 framework was just beginning. To this day, Sun&#8217;s flagship web-application framwork has been an uncompromising box of tricks and gotchas, with little community adoption. This has been mostly due to its relatively developer-unfriendly nature; however, the second phase is coming, and with JSF2.0 peeking out from the edge of its nest, a new life is beginning to show.</p><p><span
id="more-41"></span></p><p>From the start, JSF had mixed support from the community, with opposition from major players like IBM, HP, and the Apache Foundation. Apache voiced strong concerns because of &#8220;Sun&#8217;s current position that JSRs may not be independently implemented under an open source license.&#8221; In addition, they saw, &#8220;little value in recreating a technology [Struts] in a closed environment that is already available in an open environment.&#8221;<a
name="sdfootnote1anc" href="#sdfootnote1sym"><sup>1</sup></a></p><p>Apache&#8217;s concerns drew several other players to vote against JSF, but the final vote still passed with a 10-5 margin (Accenture abstained from voting.) With the voting complete a short two weeks later, the first JSF expert group was formed.</p><p>Three months after the formation of the expert group, the first JCP community review was complete, and Sun&#8217;s new star web-framework was on its way to reality. On the side of the box was a label, which read, &#8220;Final release, May 2004: Warranty Void if Removed&#8221; It was done, and their hands were off.</p><blockquote><h2 style="text-align: center;">But <em>some things that should not have been forgotten, were lost.</em></h2></blockquote><p>Since JSF was engineered by companies like IBM and Oracle, major contractors in the industry, most of the emphasis was placed on creating a modular architecture that could be &#8216;easily extended&#8217; and broken down into components. While technically sound, and well designed for large companies where developers are part of an assembly line, the community at large found JSF hard to use.</p><p>JSF lacked life-cycle extension; there are six defined phases, and if you need to add another one, you&#8217;re out of luck. Also lacking was easy component creation &#8212; Creating a component in JSF today requires modification of no fewer than four separate files, even more if you use a separate renderer class. You were on your own if you wanted to validate multiple form fields against each other.</p><p>Navigation rules were ungainly, and difficult to follow logically without a visual editor. Community documentation was almost a joke. Sun&#8217;s mailing list and <a
href="http://forums.sun.com/forum.jspa?forumID=427&amp;start=0">forum</a> are still the best places to find help. There are some very knowledgeable people, but nowhere to be found is what most developers find most useful: a central, persistent resource for documentation. I like <a
href="http://www.php.net/manual/en/control-structures.foreach.php">PHP&#8217;s model</a> &#8211; official documentation with community feedback in comments below.</p><p>The lack of bookmarking support is one of the most highly-criticised facets of JSF, which is where I got involved, leading me to create the <a
href="../../../../../prettyfaces">PrettyFaces</a> URL rewriting extension. If you need to be convinced of the collective dysfunction on this topic, look at the results of a google search for &#8220;jsf bookmark&#8221;. Yet, at the root of all this was something JSF lacked until very recently &#8211; something very important.</p><blockquote><h2 style="text-align: center;"><em>A set of ears.</em></h2></blockquote><p
align="left">The community was speaking, but until recently, nobody was listening. Blame JCP? Cay Horstmann thinks that <a
href="http://weblogs.java.net/blog/cayhorstmann/archive/2009/01/a_call_to_fix_t.html">the JCP needs to be more open</a> to the community.<a
name="sdfootnote2anc" href="#sdfootnote2sym"><sup>2</sup></a></p><p
align="left">Personally, I&#8217;m surprised that JSF wasn&#8217;t abandoned completely, which says in my mind, &#8220;they got something right.&#8221; The framework does a lot for you, but &#8220;I can&#8217;t figure out how to use it&#8221;, &#8220;it doesn&#8217;t do what I need,&#8221; and &#8220;everything takes forever.&#8221;. This is where we see the light, and JSF2 enters from stage left; a new star performer?</p><p
align="left">From the very start, JSF2 is different, more open. Ed Burns, Ryan Lubke, Jim Driskoll and other <a
href="http://weblogs.java.net/">blogging developers</a> can be thanked for engaging the community in a way that Sun has not done before.</p><p
align="left">Convention over configuration has taught us a lot. We might thank Ruby on Rails, or possibly a collective laziness, but the <a
href="http://jcp.org/en/jsr/detail?id=314">JSR314</a> Expert Group has taken it to heart. &#8220;EzComp&#8221; is JSF&#8217;s new component writing system, and yes, it&#8217;s &#8220;Ez&#8221;.</p><p
align="left">Jim Driscoll <a
href="http://weblogs.java.net/blog/driscoll/archive/2008/11/another_jsf_20_1.html">explains</a> how to create a &#8220;click to edit&#8221; AJAX input field, like those so popularly seen on Flickr, or Facebook. (About 30 lines of XHTML, plus JavaScript.) Tag libraries no longer need to be defined manually; they will <a
href="http://weblogs.java.net/blog/driscoll/archive/2008/11/writing_a_simpl_1.html">spring to life</a> as needed, based on the names and interfaces of your components.</p><p
align="left">JSF2 is showing stunning promise and vision. This is just a small set of changes that will drastically improve the usefulness and adoption of JSF. When a rookie Java web-developer can pick up JSF2.0, in their IDE of choice, and write a small, useful application in a day, that&#8217;s when we&#8217;ll know they&#8217;ve gotten it right. Man, life is good&#8230; but.</p><blockquote><h2 style="text-align: center;"><em>Where are my bookmarks?</em></h2></blockquote><p
align="left">Ahh yes.</p><p
align="left">After learning about JSF2 in mid-October, I&#8217;ve been following very closely the changes and discussions around its new architecture, and how it can be &#8216;fixed.&#8217; At the top of <a
href="http://www.jsfcentral.com/editorial/jsf2_wishlist_1.html">the wish list</a>, among other contenders like &#8220;Fixing Navigation Rules,&#8221; and even above &#8220;Simplified component development,&#8221; is one very near to my heart: &#8220;Enhanced support for GET requests.&#8221;</p><p
align="left">I began work on <a
href="../../../../../prettyfaces">PrettyFaces</a> before learning that JSF2 was in progress, but not before I had evaluated the other options available from the community. Jboss Seam had a UrlRewriting feature, but I found it cumbersome, requiring too much configuration, and the added burden of learning the entire Seam framework was too much for me. RestFaces was an alternative that I tried for a while, but several design choices made it difficult to incorporate in a non-invasive way, and I was left writing lines and lines of code in order to compensate for its (albeit few) shortcomings.</p><p
align="left">Shocked, disappointment struck when I was contacted by a PrettyFaces user, disheartened, who urged me to contact the JSF2 expert group because they were <a
href="http://forums.sun.com/thread.jspa?messageID=10541909#10541909">close to abandoning</a> bookmarking support for the next release, a full five years after the last specification update. How could they be considering omitting such a critical feature? It would surely finish off whatever damage had been done by the first 8 years of JSF&#8217;s mis-managed life, and it would be dead forever. &#8220;Long live Struts,&#8221; Apache would tout.</p><blockquote><h2 style="text-align: center;"><em>New life.</em></h2></blockquote><p
align="left">But fate struck, and before I could even begin to write emails, begging for reconsideration, I got another pop-up from my inbox.</p><p
align="left">From: Dan J. Allen &#8211; Jan 10, 2:50pm</p><p
style="padding-left: 30px; text-align: justify;"><tt>Lincoln,</tt></p><p
style="padding-left: 30px; text-align: justify;"><tt>Hey there. I have recently joined the JSF EG by way of my employment with Red Hat. My first action was to submit a couple of proposals to make JSF more "website friendly". After all, that is what got me interested in Seam in the first place.</tt></p><p
style="padding-left: 30px; text-align: justify;"><tt>In the most recent proposal, I cited the statements you made in a recent blog post. I have attached that proposal to this e-mail as well as a related proposal. We are listening (at least those of us at Red Hat) and we are trying our best to improve JSF within the boundaries that we have to work (i.e., the JCP). The JSF EG was definitely dysfunctional in the past, but Ed Burns, Red Hat, and a handful of other members have really started to turn things around. Adding pretty URLs is definitely too big of a change at this point given the time constraints, but you may find these two proposals to satisfy many of your other concerns. Feel free to provide feedback to the JSF EG regarding the design changes.</tt></p><p
style="padding-left: 30px; text-align: justify;"><tt>-Dan</tt></p><p
align="left">Dan is the author of <a
href="http://www.manning.com/dallen/">Seam in Action</a>, and from my interactions with him, a brilliant individual. If he isn&#8217;t rich already, in heart or on paper, he will be someday.</p><p
align="left">Struck by two emails on this subject in the same day, I &#8220;hurriedly&#8221; (from 11pm-2am) typed a response. Someone at RedHat was asking <em>me</em> for <em>my feedback?</em> Talk about an ego trip. My friends at work won&#8217;t let me hear the end of it.</p><p
align="left">The proposal was stunning. While still omitting Pretty URL rewriting, it contained in depth solutions for using query-string parameters (http://url?key=value) to bookmark pages within JSF. It lacked page-load actions, but that would follow, as we talked through the issues, in the next few days.</p><p
align="left">During the process of reviewing Dan&#8217;s proposals, providing feedback where I could, and wishing I weren&#8217;t just a part-time contributor, we worked through issues regarding usability, convention over configuration, and strategies for implementing the new functionality that would be required. Two weeks and 91 emails later, we had a draft of the spec, and off it went (via Pete Muir at RedHat) to the Expert Group for review.</p><p
align="left">The proposal was accepted; Dan&#8217;s job got even better. Within a week, he would have to implement his proposed specification, create a sample application, make any necessary changes to the spec, submit it back to the EG, and believe me, it was good.</p><blockquote><h2 style="text-align: center;"><em>Things yet to come.</em></h2></blockquote><p
align="left">JSF2 is still under review, and all of these changes may yet be changed, but I&#8217;m confident that the people in charge have heads on their shoulders, and that they are pointing in the right direction.</p><p
align="left">I&#8217;m impressed. Impressed by Dan Allen, Jim Driscoll, Ryan Lubke, and by Sun for starting to recognize that its developer community is its best chance at survival. JSF2 won&#8217;t have everything that we&#8217;ve asked for, but it will have the most critical features that the community has asked for. I&#8217;m impressed that it&#8217;s turning out so well: Component writing is truly easy; pages will be bookmark-able; templating is built in; and annotations are on the way to deprecating faces-config.xml for trivial tasks.</p><p
align="left">So what can Sun do next? Well. For starters, keep listening. Don&#8217;t limit ideas to people on its payroll. JSF2 will be a success if Sun gives users a voice.</p><p
align="left">The developer blogs are great, but we need a centralized place for core documentation. The site needs to be fast, and you should be able to easily register and contribute. Yes, it will take management and oversight, but we aren&#8217;t out to hurt anyone. Dear sun: &#8220;We like what you&#8217;re doing, and the direction in which we think you might be turning. We&#8217;re here to further the cause of software development, and guess what&#8230; If you listen to us&#8230; we&#8217;ll do it for free.&#8221;</p><p
align="left">Whether or not this happens, the future of JSF is in our hands.</p><p
style="text-align: center;">&#8211;</p><p><a
name="sdfootnote1sym" href="#sdfootnote1anc">1</a><a
href="http://www.jcp.org/en/jsr/results?id=614" target="_blank">http://www.jcp.org/en/jsr/results?id=614</a></p><p><a
name="sdfootnote2sym" href="#sdfootnote2anc">2</a><a
href="http://weblogs.java.net/blog/cayhorstmann/archive/2009/01/a_call_to_fix_t.html" target="_blank">http://weblogs.java.net/blog/cayhorstmann/archive/2009/01/a_call_to_fix_t.html</a></p> ]]></content:encoded> <wfw:commentRss>http://ocpsoft.com/java/jsf2-in-good-hands/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> </channel> </rss>
<!-- Served from: ocpsoft.com @ 2010-07-29 17:03:53 by W3 Total Cache -->