<?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>dominikdorn.com &#187; JSF2</title>
	<atom:link href="http://dominikdorn.com/tag/jsf2/feed/" rel="self" type="application/rss+xml" />
	<link>http://dominikdorn.com</link>
	<description>shit happens ;)</description>
	<lastBuildDate>Tue, 03 Jan 2012 19:47:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>JSF Components &#8211; The entity &#8220;uuml&#8221; was referenced, but not declared</title>
		<link>http://dominikdorn.com/2010/10/jsf-components-entity-referenced-not-declared/</link>
		<comments>http://dominikdorn.com/2010/10/jsf-components-entity-referenced-not-declared/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 15:21:54 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[JSF]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[javaee6]]></category>
		<category><![CDATA[JSF2]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=348</guid>
		<description><![CDATA[Shows how to use html entities in a JSF 2 Facelets Composite Component]]></description>
			<content:encoded><![CDATA[<p>Today I created a custom <strong>JSF 2 Composite Component</strong>, but <strong>Mojarra</strong> threw an error on me, when I tried to use a German <strong>Umlaut</strong> like <strong>&amp;uuml;</strong> in my markup, like this</p>
<h1>HTTP Status 500 -</h1>
<hr /><strong>type</strong> Exception report</p>
<p><strong>message</strong></p>
<p><strong>description</strong>The server encountered an internal error () that prevented it from fulfilling this request.</p>
<p><strong>exception</strong></p>
<pre>javax.servlet.ServletException: javax.servlet.ServletException: javax.faces.view.facelets.FaceletException: Error Parsing /resources/sg/uploadedDoc.xhtml: Error Traced[line: 45] The entity "uuml" was referenced, but not declared.</pre>
<p><strong>root cause</strong></p>
<pre>javax.servlet.ServletException: javax.faces.view.facelets.FaceletException: Error Parsing /resources/sg/uploadedDoc.xhtml: Error Traced[line: 45] The entity "uuml" was referenced, but not declared.</pre>
<p><strong>root cause</strong></p>
<pre>java.util.concurrent.ExecutionException: javax.faces.view.facelets.FaceletException: Error Parsing /resources/sg/uploadedDoc.xhtml: Error Traced[line: 45] The entity "uuml" was referenced, but not declared.</pre>
<p><strong>root cause</strong></p>
<pre>javax.faces.view.facelets.FaceletException: Error Parsing /resources/sg/uploadedDoc.xhtml: Error Traced[line: 45] The entity "uuml" was referenced, but not declared.</pre>
<p><strong>note</strong> <span style="text-decoration: underline;">The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.</span></p>
<hr />
<h3>GlassFish Server Open Source Edition 3.0.1</h3>
<hr />The reason this happened is, that I referenced an entity &#8220;uuml;&#8221; in a xml document where it is not defined.<br />
XML basically just supports a few build-in entities, like &#8220;amp;&#8221; &#8220;quot;&#8221;, &#8220;apos;&#8221;, &#8220;lt;&#8221; and &#8220;gt;&#8221;.</p>
<p>To let the SAX-Parser know which additional entities I wanted to use, I simply added the XHTML 1.1 DOCTYPE to the head of the document.<br />
My Component now looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span style="color: #00bbdd;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:h</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/html&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:f</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/core&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/facelets&quot;</span></span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:composite</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/composite&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
....
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:interface<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;composite:implementation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
.... text <span style="color: #ddbb00;">&amp;Uuml;</span>bermorgen ist auch noch ein Tag ... text
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/composite:implementation<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Hope this helps some of you out there. </p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/10/jsf-components-entity-referenced-not-declared/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CDI/Weld manual lookup</title>
		<link>http://dominikdorn.com/2010/04/cdi-weld-manual-bean-lookup/</link>
		<comments>http://dominikdorn.com/2010/04/cdi-weld-manual-bean-lookup/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 18:04:28 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF2]]></category>
		<category><![CDATA[Weld]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=279</guid>
		<description><![CDATA[This post describes how to manually lookup beans in a CDI / Weld managed environment when you are somewhere where a simple @Inject does not work because the object itself is not managed by CDI / Weld. ]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;re ended up in a situation, where you are somewhere (e.g. a javax.faces.Converter) where you are <strong>unable to simple @Inject SomeClass</strong> ? </p>
<p>I had the problem, that I had a FacesConverter like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.ManagedBean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.annotation.PostConstruct</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.enterprise.context.RequestScoped</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.component.UIComponent</span><span style="color: #339933;">;</span>
<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.convert.Converter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.convert.FacesConverter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.inject.Inject</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
@FacesConverter<span style="color: #009900;">&#40;</span>forClass <span style="color: #339933;">=</span> AvailableCountry.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
@ManagedBean <span style="color: #666666; font-style: italic;">// does not help :(</span>
@RequestScoped <span style="color: #666666; font-style: italic;">// does not help :(</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AvailableCountryConverter <span style="color: #000000; font-weight: bold;">implements</span> Converter
<span style="color: #009900;">&#123;</span>
	@Inject
	AvailableCountryDao dao<span style="color: #339933;">;</span>
&nbsp;
	@PostConstruct
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> postConstruct<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;calling postConstruct&quot;</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;">public</span> <span style="color: #003399;">Object</span> getAsObject<span style="color: #009900;">&#40;</span>FacesContext facesContext, UIComponent
			component, <span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> value.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</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>
		<span style="color: #000000; font-weight: bold;">return</span> dao.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span>getKey<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003399;">Long</span> getKey<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Long</span> key<span style="color: #339933;">;</span>
		key <span style="color: #339933;">=</span> <span style="color: #003399;">Long</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> key<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003399;">String</span> getStringKey<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">long</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">StringBuffer</span> sb <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		sb.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> sb.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</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;">public</span> <span style="color: #003399;">String</span> getAsString<span style="color: #009900;">&#40;</span>FacesContext facesContext, UIComponent
			component, <span style="color: #003399;">Object</span> object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <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> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>object <span style="color: #000000; font-weight: bold;">instanceof</span> AvailableCountry<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			AvailableCountry o <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AvailableCountry<span style="color: #009900;">&#41;</span> object<span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> getStringKey<span style="color: #009900;">&#40;</span>o.<span style="color: #006633;">getCountry</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">IllegalArgumentException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;object &quot;</span> <span style="color: #339933;">+</span> object <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;
					is of type &quot;</span> <span style="color: #339933;">+</span> object.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</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: #339933;">+</span> <span style="color: #0000ff;">&quot;; expected type: &quot;</span> <span style="color: #339933;">+</span>
					AvailableCountry.<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>But my <strong>DAO was <u>not</u> injected</strong>, nor was the postConstruct method triggered by CDI.</p>
<p>Why?<br />
<strong>Because the bean is not managed by CDI</strong>, not even when annotating it with @ManagedBean because it gets created by the JSF-Lifecycle and not by CDI. </p>
<p>Well.. but <strong>how to manually lookup a Bean with CDI / Weld? </strong></p>
<p>First, you need to get the <strong>BeanManager</strong>. When you have a <strong>FacesContext</strong> (like in the converter above), you can get it like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> BeanManager getBeanManager<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> <span style="color: #009900;">&#40;</span>BeanManager<span style="color: #009900;">&#41;</span> 
              <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>ServletContext<span style="color: #009900;">&#41;</span> facesContext.<span style="color: #006633;">getExternalContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                   .<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.enterprise.inject.spi.BeanManager&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you don&#8217;t have access to a FacesContext, ServletContext or similar, you can<strong> lookup the BeanManager through JNDI</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> BeanManager getBeanManager<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;">try</span><span style="color: #009900;">&#123;</span>
            <span style="color: #003399;">InitialContext</span> initialContext <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InitialContext</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: #009900;">&#40;</span>BeanManager<span style="color: #009900;">&#41;</span> initialContext.<span style="color: #006633;">lookup</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java:comp/BeanManager&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">NamingException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            log.<span style="color: #006633;">error</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Couldn't get BeanManager through JNDI&quot;</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>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>After you&#8217;ve got your <strong>BeanManager</strong>, simply <strong>lookup</strong> your Bean like this:<br />
(In my case, I wanted to lookup a bean with the type AvailableCountryDao)<br />
<strong>Type-based CDI manual lookup</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> AvailableCountryDao getFacade<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        BeanManager bm <span style="color: #339933;">=</span> getBeanManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Bean<span style="color: #339933;">&lt;</span>AvailableCountryDao<span style="color: #339933;">&gt;</span> bean <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>Bean<span style="color: #339933;">&lt;</span>AvailableCountryDao<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span> bm.<span style="color: #006633;">getBeans</span><span style="color: #009900;">&#40;</span>AvailableCountryDao.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        CreationalContext<span style="color: #339933;">&lt;</span>AvailableCountryDao<span style="color: #339933;">&gt;</span> ctx <span style="color: #339933;">=</span> bm.<span style="color: #006633;">createCreationalContext</span><span style="color: #009900;">&#40;</span>bean<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        AvailableCountryDao dao <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>AvailableCountryDao<span style="color: #009900;">&#41;</span> bm.<span style="color: #006633;">getReference</span><span style="color: #009900;">&#40;</span>bean, AvailableCountryDao.<span style="color: #000000; font-weight: bold;">class</span>, ctx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// this could be inlined, but intentionally left this way</span>
        <span style="color: #000000; font-weight: bold;">return</span> dao<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Thanks to my friend <a href="http://ocpsoft.com/">Lincoln Baxter, III</a> for the snipped. </p>
<p><strong>Name-based CDI manual lookup</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Object</span> getBeanByName<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// eg. name=availableCountryDao</span>
    <span style="color: #009900;">&#123;</span>
        BeanManager bm <span style="color: #339933;">=</span> getBeanManager<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Bean bean <span style="color: #339933;">=</span> bm.<span style="color: #006633;">getBeans</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">iterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        CreationalContext ctx <span style="color: #339933;">=</span> bm.<span style="color: #006633;">createCreationalContext</span><span style="color: #009900;">&#40;</span>bean<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// could be inlined below</span>
        <span style="color: #003399;">Object</span> o <span style="color: #339933;">=</span> bm.<span style="color: #006633;">getReference</span><span style="color: #009900;">&#40;</span>bean, bean.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, ctx<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// could be inlined with return</span>
        <span style="color: #000000; font-weight: bold;">return</span> o<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So, now you&#8217;re able to manually lookup beans with CDI.<br />
In case you have the same problem (with Converters/Validators) like I had above, checkout <a href="http://seamframework.org/Seam3/FacesModule">Seam Faces</a>, where this <strong>problem already is fixed</strong>,<br />
meaning your <strong>@ManagedBean annotated Converter/Validator is working as expected with @Inject, @PostConstruct &#038; @PreDestroy</strong> <img src='http://dominikdorn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/04/cdi-weld-manual-bean-lookup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using complex urls &amp; regular expressions with PrettyFaces</title>
		<link>http://dominikdorn.com/2010/03/complex-urls-regular-expressions-validators-prettyfaces/</link>
		<comments>http://dominikdorn.com/2010/03/complex-urls-regular-expressions-validators-prettyfaces/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 20:15:24 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF2]]></category>
		<category><![CDATA[PrettyFaces]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[Validator]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=249</guid>
		<description><![CDATA[In this post you will learn how to match complex urls with regular expressions and PrettyFaces in JSF2 Web Applications.]]></description>
			<content:encoded><![CDATA[<p>If you like to construct complex &#038; pretty urls with JSF2 &#038; PrettyFaces, you might be interested in the following few lines of code.</p>
<p>In our example, we want to match a URL like this one</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">http://www.studyguru.eu/at/tuwien/184.153--Entwurfsmethoden-fuer-verteilte-Systeme</pre></td></tr></table></div>

<p>Previously I tried to match it with a PrettyFaces Pattern/Regex like this:</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;pattern</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/([a-z]{2})/([a-z0-9\-_]*)/([a-z0-9\-_\.]*)\-\-.*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>But thankfully, PrettyFaces >2.0.4 supports directly populating the RequestParams! </p>
<p>Configure your pretty-config like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pretty-config</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces/2.0.4&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces/2.0.4</span>
<span style="color: #009900;">                http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-2.0.4.xsd&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;url-mapping</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;coursePage&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;/#{countryCode}/#{uniShortName}/#{courseId}--.*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/path/to/coursePage.xhtml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/view-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
....</pre></td></tr></table></div>

<p>and use JSF2&#8242;s viewParams like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td 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: #00bbdd;">&lt;!DOCTYPE html</span>
<span style="color: #00bbdd;">        PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span style="color: #00bbdd;">        &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #000066;">xml:lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:h</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/html&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:f</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/core&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:pretty</span>=<span style="color: #ff0000;">&quot;http://ocpsoft.com/prettyfaces&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/facelets&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:p</span>=<span style="color: #ff0000;">&quot;http://primefaces.prime.com.tr/ui&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:metadata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:viewParam</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;countryCodeId&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">requiredMessage</span>=<span style="color: #ff0000;">&quot;Kein Land spezifiziert&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;countryCode&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{coursePageBean.countryCode}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:validateRegex</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;([a-z]{2})&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:viewParam<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:viewParam</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;universityCodeId&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">requiredMessage</span>=<span style="color: #ff0000;">&quot;Keine Hochschule spezifiziert&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;uniShortName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{coursePageBean.universityCode}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:validateRegex</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;([a-z0-9\-_]*)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:viewParam<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:viewParam</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;courseIdId&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">required</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">requiredMessage</span>=<span style="color: #ff0000;">&quot;Keine KursId spezifiziert&quot;</span></span>
<span style="color: #009900;">                 <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;courseId&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{coursePageBean.courseId}&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:validateRegex</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;([a-z0-9\-_\.]*)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:viewParam<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:event</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;preRenderView&quot;</span> <span style="color: #000066;">listener</span>=<span style="color: #ff0000;">&quot;#{coursePageBean.populate}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/f:metadata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>coursePage<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
countryCode #{ coursePageBean.countryCode} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
courseId #{coursePageBean.courseId}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;br</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
universityCode #{coursePageBean.universityCode}<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;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Voila! You now can match complex urls with PrettyFaces and apply all your custom validators<br />
to your Pretty URL <img src='http://dominikdorn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/03/complex-urls-regular-expressions-validators-prettyfaces/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Authentication in JSF2 with JAAS: Part 2 &#8211; Authenticating a client/user</title>
		<link>http://dominikdorn.com/2010/02/authentication-jsf2-jaas-authorization-user-roles-realms/</link>
		<comments>http://dominikdorn.com/2010/02/authentication-jsf2-jaas-authorization-user-roles-realms/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 11:28:04 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[JAAS]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF2]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=213</guid>
		<description><![CDATA[The second part of the series covers the basics needed to understand authorization in a JavaEE application based on the principles provided by JAAS and how they apply in modern, JavaEE based web applications. The user is thought, how to configure his web-application to use role-based authorization and authenticate against a specific realm.]]></description>
			<content:encoded><![CDATA[<p>In the second part of this series, we are going to understand some more terminology of JAAS and start creating our own authentication system.</p>
<p>A <strong>LoginContext</strong> Object is used by applications to authenticate <strong>user</strong>s independently of the underlying authentication technology. <strong>Authentication technology</strong> in this context means stuff like &#8220;file based authentication&#8221;, &#8220;Database based authentication&#8221;, &#8220;LDAP authentication&#8221;, &#8220;CERTIFICATE authentication&#8221; and so on.</p>
<p>The <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/login/LoginContext.html">LoginContext</a> class is part of the javax.security.auth.login package and describes methods used to authenticate <strong>Subjects/user</strong> in the meaning of <a href="http://dominikdorn.com/2010/02/jaas-authentication-jsf2-terminology/">Part 1 of this series</a>). The <a href="http://java.sun.com/developer/technicalArticles/Security/jaasv2/index.html">documentation</a> states:</p>
<blockquote><p>A subject is an identity in a system that you want to authenticate and assign access rights to. A subject can be a human user, a process, or a machine..</p></blockquote>
<p>which is basically what I said before. Its still a little bit unclear to me, why they use &#8220;user&#8221; in one documentation and &#8220;subject&#8221; in the other, but as its the same thing, we know what to do.</p>
<p>The documentation further states, that a <strong>subject</strong> may interact with different <strong>authorities</strong> (applications) and may have different passwords (<strong>credentials</strong>) for each of them. To represent the <strong>subject/user</strong> in these applications, the <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/security/Principal.html"><strong>java.security.Principal</strong></a> class is used.</p>
<p>Our own <strong>LoginContext</strong> now invokes various <strong>LoginModules</strong> ( these handle the different ways of authentication, like form based, HTTP-Basic, HTTP-Digest, etc.). The <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/spi/LoginModule.html"><strong>LoginModule</strong></a> interface is part of<br />
the <strong>javax.security.auth.spi</strong> package. If one ever wants to integrate Facebook connect or something similar, this is where to look at!</p>
<p>But how does the <strong>LoginContext</strong> know, which <strong>LoginModules</strong> to invoke? This is done by a <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/login/Configuration.html"><strong>Configuration</strong></a> Object.</p>
<p>So, to sum this up:</p>
<ol>
<li>We have 1-n <strong>LoginModules</strong>, handling different form of authentication.. file, db, ldap and so on</li>
<li>We have a <strong>LoginContext</strong>, taking users credentials and supplying them to the <strong>LoginModules</strong></li>
<li>We have <strong>configuration</strong>s, specifying which <strong>LoginModules</strong> should be used by the <strong>LoginContext</strong></li>
<li>A <strong>client supplies</strong> its <strong>credentials</strong> to the <strong>LoginContext</strong>. The LoginContext <strong>looks up</strong>, <strong>which LoginModules to use</strong> in its <strong>Configuration</strong> and <strong>authenticates the client</strong> with the <strong>provided credentials</strong> against the <strong>LoginModules</strong>.</li>
</ol>
<p><strong>But why bother with all this stuff of LoginContext, LoginModules, Configuration and so on? Shouldn&#8217;t it be easy to use authentication, especially custom authentication in a web-app? </strong></p>
<p>Because we&#8217;ve already got it in our AppServer!</p>
<p>Configuration:<br />
We&#8217;re actually creating our Configuration object manually in our web.xml. </p>
<p>Here we define, how we gain the authentication data from the user. In this example, I used auth-method=FORM because no-one wants to use HTTP-Basic Authentication anymore today! </p>
<pre lang="xml" lines="1">
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>nameOfTheRealm</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/loginError.xhtml</form-error-page>
        </form-login-config>
    </login-config>
</pre>
<p>With this configuration, you can already create your own login form with your preferred style, like this:<br />
login.xhtml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;form method=&quot;post&quot; action=&quot;#{request.contextPath}/j_security_check&quot;&gt;
&lt;label for=&quot;username&quot;&gt;Userid&lt;/label&gt;&lt;input type=&quot;text&quot; id=&quot;username&quot; name=&quot;j_username&quot;&gt;
&lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;&lt;input type=&quot;password&quot; id=&quot;password&quot; name=&quot;j_password&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Login&quot;&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>In the next part of the series, we&#8217;ll see how you can do it with an jsf/facelets page.</p>
<p>Ok, we now got our form for login. To <strong>Logout</strong> simply make a link to <strong>/j_security_logout </strong></p>
<p>We&#8217;ve now got login + logout, but they are not working yet. What we still have to do, is specify, what we&#8217;re authenticating against. In this post, we called it LoginModule, in Glassfishv3 its called Realm and we have already<br />
configured it with our Login-Config above.</p>
<p>A post which explains <a href="http://www.developinjava.com/features/47-enterprise-java/105-securing-a-web-application-on-glassfish-using-jaas.html">how to configure the simply, build in Glassfish &#8220;File-Realm&#8221;</a> is available at <a href="http://www.developinjava.com">DevelopInJava.com</a>. </p>
<p>In the next blog entry of this series, we&#8217;ll see how we can create our own realm, that really suits our needs.</p>
<p>We now got everything needed for a basic authentication, but we don&#8217;t yet have a group to role mapping, which we need for stuff like #{request.isUserInRole(&#8216;ADMIN&#8217;)} or annotating our beans (see later for all of that).<br />
So what we&#8217;re going to do is, map the given &#8220;groups&#8221; to roles. Before we do that, we should tell our application, which roles we have. Do it like that in your web.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>all the users with the role Admin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ADMIN<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>all the users that are authenticated<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>LOGGEDIN_USER<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>all the users that are moderators/extended rights<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MODERATOR<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-role<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Now we can map the groups we get from the realm to our roles. We have to put this in<br />
<strong>/WEB-INF/sun-web.xml </strong> (if you&#8217;re using Glassfish v3). My file looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td 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: #00bbdd;">&lt;!DOCTYPE sun-web-app PUBLIC '-//Sun Microsystems, Inc.//DTD </span>
<span style="color: #00bbdd;">Application Server 9.0 Servlet 2.5//EN'</span>
<span style="color: #00bbdd;">    'http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd'&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sun-web-app</span> <span style="color: #000066;">error-url</span>=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context-root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context-root<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-role-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>LOGGEDIN_USER<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;group-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>default<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/group-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-role-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-role-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MODERATOR<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;group-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>moderatoren<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/group-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-role-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-role-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ADMIN<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;group-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>root<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/group-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-role-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class-loader</span> <span style="color: #000066;">delegate</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;jsp-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;keepgenerated&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;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Keep a copy of the generated 
                servlet class' java code.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/property<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jsp-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sun-web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Click here to <a href="http://docs.sun.com/app/docs/doc/819-3660/beaql?a=view">view the general structure of the sun-web.xml file</a>.</p>
<p>Our User -> Principal, Group -> Role mapping now works. We can start protecting resources in our app! <strong>Horray</strong>!</p>
<p>We&#8217;re doing this by specifying &#8220;security-constraints&#8221; like this in our web.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>admin-area<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-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>/admin/<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;/web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>admins should be allowed to access this resources<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ADMIN<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/role-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This should be quite self-explanatory, for a detailed explanation take a look at<br />
<a href="http://java.sun.com/developer/technicalArticles/J2EE/security_annotation/">Security Annotations and Authorization in GlassFish and the Java EE 5 SDK</a>, which also explains how to secure beans with annotations<br />
and has a nice matrix whats possible with annotations and whats not.</p>
<p>If you want to lock some stuff for everyone, simply leave the auth-constraint element empty, like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-resource-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>admin-area<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-resource-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>/admin/<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;/web-resource-collection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/auth-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security-constraint<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>If you&#8217;ve followed these instructions and the one on the blog-post <a href="http://www.developinjava.com/features/47-enterprise-java/105-securing-a-web-application-on-glassfish-using-jaas.html">Securing a Web Application on Glassfish using JAAS</a>, you should now be able to authenticate different users with different roles in your app using the File-Realm. </p>
<p>In the next articles of the series, we will look how to create an own realm, how to replace the form-based login with a JSF-Based one and how to work with roles in your JSF-Pages.</p>
<p>References:</p>
<ul>
<li><a href="http://dominikdorn.com/2010/02/jaas-authentication-jsf2-terminology/">Authentication in JSF2 with JAAS: Part 1 – Understand the terminology</a></li>
<li><a href="http://java.sun.com/developer/technicalArticles/Security/jaasv2/index.html">Java Authentication and Authorization Service (JAAS)in Java 2, Standard Edition (J2SE) 1.4</a></li>
<li><a href="http://www.developinjava.com/features/47-enterprise-java/105-securing-a-web-application-on-glassfish-using-jaas.html">Securing a Web Application on Glassfish using JAAS</a></li>
<li><a href="http://docs.sun.com/app/docs/doc/819-3660/beaql?a=view">Structure of sun-web.xml file</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/02/authentication-jsf2-jaas-authorization-user-roles-realms/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Authentication in JSF2 with JAAS: Part 1 &#8211; Understand the terminology</title>
		<link>http://dominikdorn.com/2010/02/jaas-authentication-jsf2-terminology/</link>
		<comments>http://dominikdorn.com/2010/02/jaas-authentication-jsf2-terminology/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 23:02:12 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[JAAS]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF2]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=206</guid>
		<description><![CDATA[Authenticating users in a JSF2 application with the help of JAAS. Part one of a multiple article series, covering the terminology used by JAAS and how to understand it with simple examples.]]></description>
			<content:encoded><![CDATA[<p>Ok, this will be a multi-part blog entry series.<br />
What I want to do with this blog entries, is to document, how to make your JSF2 application use JAAS ( Java Authentication and Authorization Service ) to manage your/my users, authenticate them through a form with<br />
the help of the server and use that security information in our JSF2 pages and our Java Beans.</p>
<p>In this first part of the series, I&#8217;ll try to cover the terminology used in easy to understand words. </p>
<p>These are the terms, you&#8217;ll need to know:</p>
<ul>
<li><strong>realm</strong>: A realm is basically a &quot;user database&quot;, being it a flat file with user/pass + group info,  database tables or even an ldap directory or something else you can imagine, like facebook connect or google authentication system. It may be used by n applications.</li>
<li><strong>user</strong>: A user is a person or program wishing to authenticate against our server/app. If you only make your website for real persons, these are your users. If you also offer a webservice, other programs accessing that service are also users. A user belongs to a realm, so may be valid in n applications (see principal below)</li>
<li><strong>role</strong>: Roles are assigned to users and/or groups in an application. E.g. GUEST for a not authenticated visitor, LOGGEDIN_USER for an authenticated user, MODERATOR or ADMIN for special people. </li>
<li><strong>group</strong>: Groups are like roles, but they are used over multiple applications and mapped to specific ROLES on an per-application-basis</li>
<li><strong>principal</strong>: A Principal is an authenticated user in the scope of an application. The same user may have different principals in different applications. A principal is identified by its <strong>name</strong> and authenticated using <strong>authentication data (credentials)</strong></li>
<li><strong>security policy domain</strong>: Also called <strong>security domain</strong> or <strong>realm</strong>. Basically, the database where you lookup users. But in this meaning, its where the realms are used, being it application1, application2, applicationN</li>
<li><strong>Security attributes</strong>: are attributes associated with every principal, like &quot; is allowed to access the admin area&quot; or stuff like that.</li>
<li><strong>credential</strong>: contains or references security attributes; are used to authenticate a Principal for a Java EE product service (your webapp)</li>
<p>If you want to get the original documentation, take a look at the <a href="http://docs.sun.com/app/docs/doc/820-7627/gijrp?a=view">Security chapter</a> in the <a href="http://docs.sun.com/app/docs/doc/820-7627">Java EE 6 Tutorial Volume I</a></p>
<p>Further references, which I&#8217;ll probably be using in the next posts of these series:</p>
<ul>
<li><a href="http://jcp.org/en/jsr/detail?id=115">JSR 115: JavaTM Authorization Contract for Containers</a></li>
<li><a href="http://java.sun.com/developer/technicalArticles/Security/jaasv2/index.html">Java Authentication and Authorization Service (JAAS)in Java 2, Standard Edition (J2SE) 1.4</a></li>
<li><a href="http://java.sun.com/javase/6/docs/technotes/guides/security/jaas/JAASRefGuide.html">JavaTM  Authentication and Authorization Service (JAAS) Reference Guide</a></li>
<li><a href="http://java.sun.com/javase/6/docs/technotes/guides/security/jaas/JAASLMDevGuide.html">JavaTM  Authentication and Authorization Service (JAAS) LoginModule Developer&#8217;s Guide</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/02/jaas-authentication-jsf2-terminology/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using German Umlauts / Umlaute in JSF/JSF2</title>
		<link>http://dominikdorn.com/2010/02/using-german-umlauts-umlaute-in-jsf-jsf2/</link>
		<comments>http://dominikdorn.com/2010/02/using-german-umlauts-umlaute-in-jsf-jsf2/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 17:28:16 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[JSF2]]></category>
		<category><![CDATA[l10n]]></category>
		<category><![CDATA[umlauts]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=198</guid>
		<description><![CDATA[If you happen to localize your JSF Web-Application to German, you&#8217;ll probably have problems displaying German Umlauts ( &#228;&#196;, &#246; &#214;, &#252; &#220;, &#223;) in your page. How to resolve this? Encode the umlauts with their Unicode code in your message-bundle like this &#228; = \u00e4 &#196; = \u00c4 &#246; = \u00f6 &#214; =\u00d6 &#252; [...]]]></description>
			<content:encoded><![CDATA[<p>If you happen to localize your JSF Web-Application to German, you&#8217;ll probably have problems displaying German Umlauts ( &auml;&Auml;, &ouml; &Ouml;, &uuml; &Uuml;, &szlig;) in your page.</p>
<p>How to resolve this? Encode the umlauts with their Unicode code in your message-bundle like this</p>
<ol>
<li>&auml; = \u00e4 </li>
<li>&Auml; = \u00c4</li>
<li>&ouml; = \u00f6</li>
<li>&Ouml; =\u00d6</li>
<li>&uuml; = \u00fc </li>
<li>&Uuml; = \u00dc</li>
<li>&szlig; = \u00df</li>
</ol>
<p>So, e.g. just specify it like this in your bundle.properties</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">homework=Haus\u00fcbung</pre></td></tr></table></div>

<p>Specify the bundle itself in your faces-config.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="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;">'1.0'</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">'UTF-8'</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<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;2.0&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd&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;application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-bundle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;base-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/bundle<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/base-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;var<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>bundle<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/var<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-bundle<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<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></td></tr></table></div>

<p>and use it in your facelets page example.xhtml like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">#{bundle.homework}</pre></td></tr></table></div>

<p>or like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:outputText</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{bundle.homework}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>If you don&#8217;t want to convert all the Umlauts in your bundle by hand, simply use javas</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">native2ascii</pre></td></tr></table></div>

<p>command to automatically encode the Umlauts in your bundle.properties file.</p>
<p>Update:<br />
I found this <a href="http://inamidst.com/stuff/unidata/">unicode chart</a>, which I think is quite useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2010/02/using-german-umlauts-umlaute-in-jsf-jsf2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>FileUpload with JSF 2 and Servlet 3.0</title>
		<link>http://dominikdorn.com/2009/12/fileupload-with-jsf-2-and-servlet-3-0/</link>
		<comments>http://dominikdorn.com/2009/12/fileupload-with-jsf-2-and-servlet-3-0/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 23:11:28 +0000</pubDate>
		<dc:creator>Dominik Dorn</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaEE6]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JavaEE]]></category>
		<category><![CDATA[JSF2]]></category>
		<category><![CDATA[Servlet 3.0]]></category>

		<guid isPermaLink="false">http://dominikdorn.com/?p=169</guid>
		<description><![CDATA[Facelets Taglib for JSF2 and Servlet 3.0]]></description>
			<content:encoded><![CDATA[<p>As I had serious problems with FileUpload and the existing &#8220;solutions&#8221;, mainly Tomahawk, MyFaces, RichFaces, PrimeFaces, etc. which are all not 100% ready for JSF 2.</p>
<p>I created a taglib based on the code of <a href="http://balusc.blogspot.com">BalusC</a>.<br />
You can find the <a href="http://github.com/domdorn/fileUploadServlet3JSF2">Taglib on Github</a></p>
<p>The source code is based on these two posts:</p>
<ol>
<li><a href="http://balusc.blogspot.com/2009/12/uploading-files-in-servlet-30.html">Uploading files in Servlet 3.0</a></li>
<li><a href="http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html" target="_blank">Uploading files with JSF 2.0 and Servlet 3.0</a></li>
</ol>
<p>Simply check out the code with git</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> clone http:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>domdorn<span style="color: #000000; font-weight: bold;">/</span>fileUploadServlet3JSF2.git</pre></td></tr></table></div>

<p>then install the taglib with</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">mvn clean compile <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

<p>and import it into your maven project like this</p>
<pre>
net.balusc
fileUploadServlet3JSF2
1.0-SNAPSHOT
</pre>
<p>You can then use the taglib in your Facelets files like this:</p>
<p>Upload.xhtml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td 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: #00bbdd;">&lt;!DOCTYPE html</span>
<span style="color: #00bbdd;">PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span>
<span style="color: #00bbdd;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #000066;">xml:lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:h</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/html&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:f</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/core&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:ui</span>=<span style="color: #ff0000;">&quot;http://java.sun.com/jsf/facelets&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">xmlns:hh</span>=<span style="color: #ff0000;">&quot;http://balusc.net/jsf/html&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>FileUploadTest<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<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>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:messages</span> <span style="color: #000066;">globalOnly</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;messages&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:panelGrid</span> <span style="color: #000066;">columns</span>=<span style="color: #ff0000;">&quot;3&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;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;someText&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				SomeText:
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
			<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;someText&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{uploadBean.someText}&quot;</span> <span style="color: #000066;">required</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;f:ajax</span> <span style="color: #000066;">event</span>=<span style="color: #ff0000;">&quot;blur&quot;</span> <span style="color: #000066;">render</span>=<span style="color: #ff0000;">&quot;someText someTextMessage&quot;</span> <span style="color: #000066;">execute</span>=<span style="color: #ff0000;">&quot;@this&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:inputText<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:message</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;someText&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;someTextMessage&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;label</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;filenameText&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			Filename:
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
			<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;filenameText&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{uploadBean.filename}&quot;</span> <span style="color: #000066;">required</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;f:ajax</span> <span style="color: #000066;">event</span>=<span style="color: #ff0000;">&quot;blur&quot;</span> <span style="color: #000066;">render</span>=<span style="color: #ff0000;">&quot;filenameText filenameTextMessage&quot;</span> <span style="color: #000066;">execute</span>=<span style="color: #ff0000;">&quot;@this&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:inputText<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:message</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;filenameText&quot;</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;filenameTextMessage&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:panelGrid<span style="color: #000000; font-weight: bold;">&gt;</span></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>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:form</span> <span style="color: #000066;">enctype</span>=<span style="color: #ff0000;">&quot;multipart/form-data&quot;</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;h:panelGrid</span> <span style="color: #000066;">columns</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:outputLabel</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;uploadedFile&quot;</span> <span style="color: #000066;">rendered</span>=<span style="color: #ff0000;">&quot;#{empty uploadBean.file}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
				Input File:
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:outputLabel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hh:inputFile</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;uploadedFile&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#{uploadBean.file}&quot;</span> <span style="color: #000066;">rendered</span>=<span style="color: #ff0000;">&quot;#{empty uploadBean.file}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;f:validator</span> <span style="color: #000066;">validatorId</span>=<span style="color: #ff0000;">&quot;fileValidator&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hh:inputFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:message</span> <span style="color: #000066;">for</span>=<span style="color: #ff0000;">&quot;uploadedFile&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:panelGrid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h:commandButton</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">&quot;#{uploadBean.submit}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h:form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The bean:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.dominikdorn.simpleFileUpload.beans</span><span style="color: #339933;">;&lt;/</span>code<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.bean.ManagedBean</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.bean.RequestScoped</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.bean.SessionScoped</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.faces.bean.ViewScoped</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
&nbsp;
@ViewScoped
@ManagedBean
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UploadBean <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">File</span> file<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> filename<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getFilename<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> filename<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> setFilename<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> filename<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;binding filename&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">filename</span> <span style="color: #339933;">=</span> filename<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> submit<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;calling submit&quot;</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>file <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;">this</span>.<span style="color: #006633;">filename</span> <span style="color: #339933;">=</span> file.<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: #009900;">&#125;</span>
&nbsp;
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;processed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// do what you want with the file</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;yeah&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> UploadBean<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;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">File</span> getFile<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> file<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> setFile<span style="color: #009900;">&#40;</span><span style="color: #003399;">File</span> file<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">file</span> <span style="color: #339933;">=</span> file<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> someText<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getSomeText<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> someText<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> setSomeText<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> someText<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;binding someText&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">someText</span> <span style="color: #339933;">=</span> someText<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://dominikdorn.com/2009/12/fileupload-with-jsf-2-and-servlet-3-0/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

