<?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>Martin Ahrer - together we&#039;ll make IT</title>
	<atom:link href="http://www.martinahrer.at/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.martinahrer.at</link>
	<description>Mostly related to Java Enterprise Technologies</description>
	<lastBuildDate>Mon, 06 Sep 2010 08:29:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<meta name="generator" content="deVision 0.9" />
		<item>
		<title>Tapestry 5 Workshop am 2.11.2010 mit Igor Drobiazko</title>
		<link>http://www.martinahrer.at/2010/09/02/tapestry-5-workshop-mit-igor-drobiazko/</link>
		<comments>http://www.martinahrer.at/2010/09/02/tapestry-5-workshop-mit-igor-drobiazko/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 19:58:29 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Workshop]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=479</guid>
		<description><![CDATA[Am 2.11 hält Igor Drobiazko (Committer und PMC von Apache Tapestry) in Linz einen Tagesworkshop zum Thema Tapestry. Die Teilnahme am Workshop kostet €390,00 (exkl. Mwst.). Apache Tapestry ist ein komponentenorientiertes Web-Framework zur Entwicklung von skalierbaren Web-Anwendungen in Java. In dieser Session wird Tapestry vorgestellt und ein innovativer Ansatz zur Entwicklung von Web 2.0 &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Am 2.11 hält Igor Drobiazko (Committer und PMC von Apache Tapestry) in Linz einen Tagesworkshop zum Thema Tapestry. Die Teilnahme am Workshop kostet €390,00 (exkl. Mwst.).</p>
<p><a href="https://www.xing.com/events/tapestry-workshop-igor-drobiazko-committer-pmc-apache-tapestry-556179" class="btn" target="_blank"><span>Anmeldung</span></a></p>

<p><strong>Apache Tapestry</strong> ist ein komponentenorientiertes Web-Framework zur Entwicklung von skalierbaren Web-Anwendungen in Java. In dieser Session wird Tapestry vorgestellt und ein innovativer Ansatz zur Entwicklung von Web 2.0 &#8211; Anwendungen diskutiert. Es wird demonstriert, wie Tapestry 5 die Mächtigkeit von Java mit der Einfachheit und der Produktivität von Scripting-Lösungen wie Ruby on Rails oder Django kombiniert. Mit Tapestry bekommt man das Beste aus den beiden Welten. Tapestry stellt eine Menge von Features zur Steigerung der Produktivität bereit, die ich in einigen Demos zeigen werde. Weiterhin wird der Vorteil eines komponentenorientierten Frameworks wie Tapestry erläutert.</p>
<p>Dipl.-Informatiker <strong>Igor Drobiazko</strong> ist Committer und PMC von Apache Tapestry. Igor verfügt über extensive Erfahrung in Web-Entwicklung, OSGi, Test-Frameworks und JEE-Architekturen. Er hat das erste deutschsprachige Buch über Tapestry 5 geschrieben und arbeitet gerade an einer Übersetzung seines Buches für Manning Publications. Igor hält Vorträge über das Framework und bloggt auf http://tapestry5.de/</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/09/02/tapestry-5-workshop-mit-igor-drobiazko/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Nexus and the Nexus REST API for implementing a software update tool</title>
		<link>http://www.martinahrer.at/2010/05/25/using-nexus-and-the-nexus-rest-api-for-implementing-a-software-update-tool/</link>
		<comments>http://www.martinahrer.at/2010/05/25/using-nexus-and-the-nexus-rest-api-for-implementing-a-software-update-tool/#comments</comments>
		<pubDate>Tue, 25 May 2010 20:03:42 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=456</guid>
		<description><![CDATA[Nexus is using a pretty well documented REST API which is usable externally as well. For one of my customers I implemented a kind of automatic software update tool that can be embedded into any product. It is based on the Sonatype NEXUS repository manager. That tool performs the following steps Detect the current software [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nexus.sonatype.org/">Nexus </a> is using a pretty well documented REST API which is usable externally as well.<br />
For one of my customers I implemented a kind of automatic software update tool that can be embedded into any product. It is based on the Sonatype NEXUS repository manager.</p>
<p><span id="more-456"></span></p>
<p>That tool performs the following steps</p>
<ol>
<li>Detect the current software version from the artifact metadata that is embedded into any Maven-built artifact</li>
<li>Query Nexus for available artifacts for the installed software (identified by Maven groupId and artifactId).</li>
<li>Test if any of the available artfacts has a version number higher than the installed one</li>
<li>If a newer version is available then download it</li>
<li>Move the new version to the target directory (e.g. the deployment folder of the application server)</li>
</ol>
<p>The Nexus REST url for a simple query for some artifact looks like <code>http://localhost/nexus/service/local/data_index/repositories/releases/content?q=commons-lang</code>. This query asks for the <em>commons-lang</em> artifact from the <em>releases repository</em>.</p>
<p>More URL schemes are documented <a href="https://docs.sonatype.com/display/NX/Nexus+Rest+API">here</a> and <a href="https://grid.sonatype.org/ci/view/Nexus/job/Nexus/label=ubuntu/ws/trunk/nexus/nexus-rest-api/target/classes/docs/index.html">there</a>.</p>
<p>The result from this query is like (only the latest versions are included for brevity):</p>
<pre class="brush:xml">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;search-results&gt;
	&lt;totalCount&gt;5&lt;/totalCount&gt;
	&lt;from&gt;-1&lt;/from&gt;
	&lt;count&gt;-1&lt;/count&gt;
	&lt;tooManyResults&gt;false&lt;/tooManyResults&gt;
	&lt;data&gt;
		&lt;artifact&gt;

			&lt;resourceURI&gt;http://localhost/nexus/service/local/repositories/central/content/commons-lang/commons-lang/2.4/commons-lang-2.4.jar&lt;/resourceURI&gt;
			&lt;groupId&gt;commons-lang&lt;/groupId&gt;
			&lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
			&lt;version&gt;2.4&lt;/version&gt;
			&lt;packaging&gt;jar&lt;/packaging&gt;
			&lt;extension&gt;jar&lt;/extension&gt;

			&lt;repoId&gt;central&lt;/repoId&gt;
			&lt;contextId&gt;Maven Central (Cache)&lt;/contextId&gt;
			&lt;pomLink&gt;http://localhost/nexus/service/local/artifact/maven/redirect?r=central&amp;g=commons-lang&amp;a=commons-lang&amp;v=2.4&amp;e=pom&lt;/pomLink&gt;
			&lt;artifactLink&gt;http://localhost/nexus/service/local/artifact/maven/redirect?r=central&amp;g=commons-lang&amp;a=commons-lang&amp;v=2.4&amp;e=jar&lt;/artifactLink&gt;

		&lt;/artifact&gt;
		&lt;artifact&gt;
			&lt;resourceURI&gt;http://localhost/nexus/service/local/repositories/central/content/commons-lang/commons-lang/2.4/commons-lang-2.4-sources.jar&lt;/resourceURI&gt;
			&lt;groupId&gt;commons-lang&lt;/groupId&gt;
			&lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
			&lt;version&gt;2.4&lt;/version&gt;
			&lt;classifier&gt;sources&lt;/classifier&gt;

			&lt;packaging&gt;jar&lt;/packaging&gt;
			&lt;extension&gt;jar&lt;/extension&gt;
			&lt;repoId&gt;central&lt;/repoId&gt;
			&lt;contextId&gt;Maven Central (Cache)&lt;/contextId&gt;
			&lt;pomLink&gt;&lt;/pomLink&gt;
			&lt;artifactLink&gt;http://localhost/nexus/service/local/artifact/maven/redirect?r=central&amp;g=commons-lang&amp;a=commons-lang&amp;v=2.4&amp;e=jar&amp;c=sources&lt;/artifactLink&gt;

		&lt;/artifact&gt;

	&lt;/data&gt;
&lt;/search-results&gt;
</pre>
<p>That only needs to be parsed using a SAX parser for extracting the most important elements. This is the Maven GAV, packaging, classifier, and  the download url which are stored in a POJO. This POJO implements the algorithm for selecting the latest version by its compareTo method.</p>
<pre class="brush:java">
public class MavenArtifactMetadata implements Comparable&lt;MavenArtifactMetadata&gt; {
	private String groupId;
	private String artifactId;
	private String version;
	private String resourceURI;
	private String packaging;
	private String classifier;

	@Override
	public int compareTo(MavenArtifactMetadata o) {
		if (!this.groupId.equals(o.groupId) || !this.artifactId.equals(o.artifactId)) {
			return -1;
		}
		return versionCompareTo(o.version);
	}

	int versionCompareTo(String version) {
		Integer[] thatVersion = versionComponents(version);
		Integer[] thisVersion = versionComponents(this.version);
		int length = Math.min(thatVersion.length, thisVersion.length);
		for (int i = 0; i < length; i++) {
			if (thatVersion[i].equals(thisVersion[i])) {
				continue;
			}
			return thisVersion[i].compareTo(thatVersion[i]);
		}
		return thisVersion.length - thatVersion.length;
	}

	Integer[] versionComponents(String version) {
		String[] splitted = StringUtils.delimitedListToStringArray(version, ".");
		if (splitted.length>0 &#038;&#038; splitted[splitted.length-1].endsWith("-SNAPSHOT")) {
			splitted[splitted.length-1]=splitted[splitted.length-1].replaceAll("-SNAPSHOT", "");
		}
		Integer[] components = new Integer[splitted.length];
		for (int i = 0; i < splitted.length; i++) {
			components[i] = (Integer.valueOf(splitted[i]));
		}
		return components;
	}
}
</pre>
<p>While implementing the download part I had learned an important lesson. For downloading and moving large files it is much more efficient to use the Java NIO API.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/05/25/using-nexus-and-the-nexus-rest-api-for-implementing-a-software-update-tool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java5 Generics are implemented by type erasure, but &#8230;</title>
		<link>http://www.martinahrer.at/2010/05/22/java5-generics-are-implemented-by-type-erasure-but/</link>
		<comments>http://www.martinahrer.at/2010/05/22/java5-generics-are-implemented-by-type-erasure-but/#comments</comments>
		<pubDate>Sat, 22 May 2010 19:51:22 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=443</guid>
		<description><![CDATA[&#8230; still it is possible to get hold of the actual type parameters of parameterized types. Even if classical reflection does not deliver type information, this type parameters can still be extremely useful. I have a few pieces of code (DAO, controllers, etc.) that are parameterized by class objects. An example: public class EntityFormController&#60;T&#62; extends [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; still it is possible to get hold of the actual type parameters of <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/ParameterizedType.html">parameterized types</a>. Even if classical reflection does not deliver type information, this type parameters can still be extremely useful. I have a few pieces of code (DAO, controllers, etc.) that are parameterized by class objects.<br />
<span id="more-443"></span><br />
An example:</p>
<pre class="brush:java">
public class EntityFormController&lt;T&gt; extends FormController&lt;T&gt; {
	private Class&lt;T&gt; entityClass;

	public String create() {
		Object instance=getEntityClass().newInstance();
		...
	}
}
</pre>
<p>So for every specific instance of the property entityClass must be initialized explicitely by implementing a proper constructor, using dependency injection, etc.</p>
<pre class="brush:java">
public class AddressFormController extends EntityFormController&lt;Address&gt; {
	public class AddressFormController() {
		super(Address.class);
	}
}
</pre>
<p>This is kind of violating the<a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself"> DRY principle</a>. The actual type is already given through the type parameter. So I was trying to eliminate this few lines of code and come up with a solution that can analyze any parameterized type from a class declaration (super class hierarchy + interfaces).</p>
<pre class="brush:java">
/**
 * @author Martin Ahrer
 *
 */
public class GenericTypeArgumentExtractor {
	private final Class&lt;?&gt; candidateClass;

	public GenericTypeArgumentExtractor(Class&lt;?&gt; candidateClass) {
		super();
		this.candidateClass = candidateClass;
	}

	public Class&lt;?&gt;[] getGenericTypeArguments(Class&lt;?&gt; clazz) {
		// TODO: hopefully clazz.getGenericSuperclass() == clazz.getSuperclass()
		Type[] types = Arrays.copyOf(clazz.getGenericInterfaces(), clazz.getGenericInterfaces().length
				+ (clazz.getGenericSuperclass() != null ? 1 : 0));
		if (clazz.getGenericSuperclass() != null) {
			types[types.length - 1] = clazz.getGenericSuperclass();
		}
		// Iterate all types from which the clazz inherits. i.e all generic
		// interfaces and the generic super class.
		for (Type type : types) {
			Class&lt;?&gt;[] arguments = getGenericTypeArguments(type);
			if (arguments != null) {
				return arguments;
			}
		}
		return null;
	}

	private Class&lt;?&gt;[] getGenericTypeArguments(Type type) {
		if (type instanceof ParameterizedType) {
			ParameterizedType parameterizedType = (ParameterizedType) type;
			if (isCandidate(parameterizedType)) {
				Type[] arguments = parameterizedType.getActualTypeArguments();
				Class&lt;?&gt;[] result = new Class&lt;?&gt;[arguments.length];
				for (int i = 0; i &lt; result.length; i++) {
					result[i] = (Class&lt;?&gt;) (arguments[i] instanceof ParameterizedType ? ((ParameterizedType) arguments[i])
							.getRawType()
							: arguments[i]);
				}
				return result;
			}
		} else if (type != null) {
			Class&lt;?&gt;[] result = getGenericTypeArguments((Class&lt;?&gt;) type);
			return result;
		}
		return null;
	}

	/**
	 * Detects the type from which we want the type arguments. Can be overridden
	 * in subclasses.
	 *
	 * @param type
	 *            the parameterized type to check for.
	 * @return true if type arguments of the passed type are reqeusted.
	 */
	protected boolean isCandidate(ParameterizedType type) {
		return candidateClass.isAssignableFrom((Class&lt;?&gt;) type.getRawType());
	}
}
</pre>
<p>Using the above class for extracting type parameters would return an array containing the Address class object.</p>
<pre class="brush:java">
Class<?>[] genericTypeArguments = new GenericTypeArgumentExtractor(EntityFormController.class)
		.getGenericTypeArguments(AddressFormController.class);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/05/22/java5-generics-are-implemented-by-type-erasure-but/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A simple ViewController for JSF</title>
		<link>http://www.martinahrer.at/2010/05/18/a-simple-viewcontroller-for-jsf/</link>
		<comments>http://www.martinahrer.at/2010/05/18/a-simple-viewcontroller-for-jsf/#comments</comments>
		<pubDate>Tue, 18 May 2010 11:14:40 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaServer Faces]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=428</guid>
		<description><![CDATA[Very early Apache Shale came up with the idea of providing a view controller that allowed to execute dedicated methods (annotated, etc.) during various JSF life-cycle (phase) events for doing initialization work upfront for example. As Shale was hibernated, Apache Orchestra stepped in and added many more useful features. Both frameworks are based on the [...]]]></description>
			<content:encoded><![CDATA[<p>Very early <a href="http://shale.apache.org/">Apache Shale</a> came up with the idea of providing a view controller that allowed to execute dedicated methods (annotated, etc.) during various JSF life-cycle (phase) events for doing initialization work upfront for example. As Shale was hibernated, <a href="http://myfaces.apache.org/orchestra/myfaces-orchestra-core/viewController.html">Apache Orchestra</a> stepped in and added many more useful features.<br />
Both frameworks are based on the idea of having a dedicated page bean (a JSF managed bean per view) that would control important processing steps for the entire view (page).<br />
It requires following naming conventions in order to associate a page bean to a view, optionally a view controller mapper provided the ability of explicitely associating page beans and views.</p>
<p><span id="more-428"></span><br />
In many projects I found the situation that the client didn&#8217;t want to pull in another framework just for that little feature.  Also for distributing responsibilities, I usually have multiple managed beans per view. So another &#8220;artificial&#8221; page bean is required just for controlling the others. So I came up with a fairly simple solution that allows to directly invoke those life-cycle callbacks on any managed bean used on a single page.</p>
<p>The &lt;f:phaseListener&gt; tag allows to bind a JSF <a href="http://javadoc.glassfish.org/v3/apidoc/javax/faces/event/PhaseListener.html">PhaseListener</a>. You can even bind multiple phase listeners (one for each managed bean; you get the idea).</p>
<pre class="brush:xml">
&lt;f:phaseListener binding="#{bean1.viewControllerPhaseListener}" /&gt;
&lt;f:phaseListener binding="#{bean2.viewControllerPhaseListener}" /&gt;
</pre>
<p>So each of the beans would provide a reference to a phase listener that would take care to perform the proper processing for the bean itself. Every bean then would use a set of annotations (like @PreRenderView, @PostRestoreView, @PreInvokeApplication, etc.) to mark those methods that should be called during a specific phase.</p>
<pre class="brush:java">
public class EntityListController&lt;T&gt; {
	private volatile ViewControllerPhaseListener viewControllerPhaseListener;

	public ViewControllerPhaseListener getViewControllerPhaseListener() {
		if (viewControllerPhaseListener == null) {
			viewControllerPhaseListener = new ViewControllerPhaseListener(this);
		}
		return viewControllerPhaseListener;
	}

	@PreRenderView
	public void updateModel() {
		...
	}

	...
</pre>
<p>The code above is partially showing a base class from which many of my managed bean are subclassed. Key is the ViewControllerPhaseListener which hides all of the details of doing the reflection job for finding (and then caching) the annotated methods to invoke during a specific phase. For brevity I&#8217;m showing only the key elements of this class.</p>
<pre class="brush:java">
public class ViewControllerPhaseListener implements PhaseListener {
	private final Object target;

	public ViewControllerPhaseListener(Object target) {
		super();
		this.target = target;
	}

	private final Class&lt;Annotation&gt;[] LIFECYCLE_ANNOTATIONS = new Class[] { PreRenderView.class, PostRestoreView.class,
		PreInvokeApplication.class };

	private final static Map&lt;Class&lt;?&gt;, Map&lt;Class&lt;? extends Annotation&gt;, Set&lt;Method&gt;&gt;&gt; controllerClasses = new ConcurrentHashMap&lt;Class&lt;?&gt;, Map&lt;Class&lt;? extends Annotation&gt;, Set&lt;Method&gt;&gt;&gt;();

	static Map&lt;Class&lt;?&gt;, Map&lt;Class&lt;? extends Annotation&gt;, Set&lt;Method&gt;&gt;&gt; getControllerClasses() {
		return controllerClasses;
	}

	@Override
	public void beforePhase(PhaseEvent event) {
		if (PhaseId.RENDER_RESPONSE.equals(event.getPhaseId())) {
			invokeAnnotatedMethod(PreRenderView.class, target);
		} else if (PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
			invokeAnnotatedMethod(PreInvokeApplication.class, target);
		}
	}

	@Override
	public void afterPhase(PhaseEvent event) {
		if (PhaseId.RESTORE_VIEW.equals(event.getPhaseId())) {
			invokeAnnotatedMethod(PostRestoreView.class, target);
		}
	}

	@Override
	public PhaseId getPhaseId() {
		return PhaseId.ANY_PHASE;
	}

	void invokeAnnotatedMethod(Class&lt;? extends Annotation&gt; annotation, Object targetObject) {
		if (!controllerClasses.containsKey(targetObject.getClass())) {
			registerController(targetObject.getClass());
		}
		for (Method method : controllerClasses.get(targetObject.getClass()).get(annotation)) {
			try {
				method.invoke(targetObject);
			} catch (Exception e) {
				LOGGER.error("Error invoking @{} annotated method {} on {}", new Object[] { annotation.getSimpleName(),
						method, targetObject });
				throw new RuntimeException(e);
			}
		}
	}

	public void registerController(Class&lt;?&gt; controllerClass) {
		// do the reflection work
	}
}
</pre>
<p>In a few projects this has proven to be quite versatile. Currently I have a couple of interesting phase listener components, from the simple DebugPhaseListener to the OpenTransactionInViewPhaseListener. I can just throw them into any view as they are required.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/05/18/a-simple-viewcontroller-for-jsf/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Resource versioning in JSF2</title>
		<link>http://www.martinahrer.at/2010/03/24/resource-versioning-in-jsf2/</link>
		<comments>http://www.martinahrer.at/2010/03/24/resource-versioning-in-jsf2/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 16:40:03 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=423</guid>
		<description><![CDATA[JSF2 made an promising attempt to provide versatile resource versioning but obviously has failed this. After I had used weblets for a while I tried to migrate some JSF2 web application to adhere to this standard. Unfortunately I had to figure out that resource versioning does not work as it has been proposed in the [...]]]></description>
			<content:encoded><![CDATA[<p>JSF2 made an promising attempt to provide versatile <a href="http://blogs.sun.com/rlubke/entry/jsf_2_0_new_feature5">resource versioning</a> but obviously has failed this. After I had used weblets for a while I tried to migrate some JSF2 web application to adhere to this standard. Unfortunately I had to figure out that resource versioning does not work as it has been proposed in the JSF2 spec.<br />
<span id="more-423"></span><br />
Seem that doing versioning of resources loaded from a classpath location has given the JSF2 implementation team a hard time. The spec was suggesting that a JAR could contain a version number for either the library or even the resource name (e.g. <strong>META-INF/resources/library-name/version/resource-name</strong>) as described in the blog entry linked above.</p>
<p>Versioning only works for resources loaded from the webroot (e.g <strong>webroot/resources/library-name/version/resource-name</strong>&#8230;) and it looks like the next version of the JSF spec will <a href="https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1423">drop </a>some of the versioning features again.</p>
<blockquote><p>
It is questionable if this versioning mechanism makes any sense, if versioning in JAR files would not be supported at all?</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/03/24/resource-versioning-in-jsf2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rendering a FacesMessage reliably</title>
		<link>http://www.martinahrer.at/2010/02/09/rendering-a-facesmessage-reliably/</link>
		<comments>http://www.martinahrer.at/2010/02/09/rendering-a-facesmessage-reliably/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 18:13:56 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=418</guid>
		<description><![CDATA[Quite a while ago I had posted about generating a FacesMessage within a method that is called during the RENDER_RESPONSE phase. Today I had to find a way to display those at the very top of a page and none of the message should get lost. So I came up with trying that with jQuery [...]]]></description>
			<content:encoded><![CDATA[<p>Quite a while ago I had <a href="http://www.martinahrer.at/2008/02/09/create-facesmessage-within-a-get-method/">posted</a> about generating a FacesMessage within a method that is called during the RENDER_RESPONSE phase. Today I had to find a way to display those at the very top of a page and none of the message should get lost.</p>
<p>So I came up with trying that with jQuery (in my case it is already included in Rich-Faces that I was using here). The idea is to actually render all FacesMessage objects at the very bottom of the page and once the page has finished loading move its DOM tree up where it was supposed to be displayed.<br />
<span id="more-418"></span></p>
<pre class="brush:xml">
&lt;div id="messagesTarget"&lt;/div&gt;

...
...

&lt;rich:panel id="messagesSource" rendered="#{! empty facesContext.maximumSeverity}"&gt;
	&lt;rich:messages showDetail="true" showSummary="true" errorClass="errorSeverity" warnClass="warningSeverity"
		infoClass="infoSeverity" /&gt;
&lt;/rich:panel&gt;

&lt;rich:jQuery selector="$('messagesTarget')" query="append($('messagesSource'))" timing="onload" /&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/02/09/rendering-a-facesmessage-reliably/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enable Dovecot SSL</title>
		<link>http://www.martinahrer.at/2010/01/19/enable-dovecot-ssl/</link>
		<comments>http://www.martinahrer.at/2010/01/19/enable-dovecot-ssl/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:24:23 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=407</guid>
		<description><![CDATA[/etc/dovecot/dovecot.conf requires these settings ssl_disable = no ssl_cert_file = /etc/ssl/certs/certificate.pem ssl_key_file = /etc/ssl/private/key.pem The certificate and key must be created before either using the dovecot tools or the way I&#8217;m describing that in-depth.]]></description>
			<content:encoded><![CDATA[<p><code>/etc/dovecot/dovecot.conf</code> requires these settings</p>
<pre class="brush:plain">
ssl_disable = no
ssl_cert_file = /etc/ssl/certs/certificate.pem
ssl_key_file = /etc/ssl/private/key.pem
</pre>
<p>The certificate and key must be created before either using the dovecot <a href="http://wiki.dovecot.org/SSL/CertificateCreation">tools</a> or the way I&#8217;m describing that <a href="http://www.martinahrer.at/2009/11/02/create-a-server-certificate-with-openssl/">in-depth</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/01/19/enable-dovecot-ssl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SASL + Postfix with Debian Lenny</title>
		<link>http://www.martinahrer.at/2010/01/19/sasl-postfix-with-debian-lenny/</link>
		<comments>http://www.martinahrer.at/2010/01/19/sasl-postfix-with-debian-lenny/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:03:03 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[sasl]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=396</guid>
		<description><![CDATA[In the last days I have reinstalled a mail server on a new virtual host and upgraded from debain etch to lenny. The initial set was done by a friend of mine following this instructions. With the upgrade to lenny however a few adjustments were required. So I describe the new setup here. apt-get install [...]]]></description>
			<content:encoded><![CDATA[<p>In the last days I have reinstalled a mail server on a new virtual host and upgraded from debain etch to lenny. The initial set was done by a friend of mine following this <a href="http://dertompson.com/2008/02/13/mail-server-setup-for-debian-etch/">instructions</a>. With the upgrade to lenny however a few adjustments were required. So I describe the new setup here.<br />
<span id="more-396"></span></p>
<pre class="brush:bash">
apt-get install libsasl2-2 sasl2-bin libsasl2-modules
</pre>
<p>The postfix configuration requires the following update in<code>/etc/postfix/main.cf</code>.</p>
<pre  class="brush:bash">
# add permit_sasl_authenticated for SASL support
smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_unauth_destination,
        check_policy_service inet:127.0.0.1:60000

# add these options
smtpd_sasl_auth_enable = yes
smtpd_sasl_authenticated_header = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
</pre>
<p>Create <code> /etc/postfix/sasl/smtpd.conf</code> with this content</p>
<pre class="brush:bash">
pwcheck_method: saslauthd
mech_list: plain login
</pre>
<p>Then create directory <code>/var/spool/postfix/var/run/saslauthd</code></p>
<pre  class="brush:bash">
 mkdir -p /var/spool/postfix/var/run/saslauthd
</pre>
<p>Set permissions</p>
<pre  class="brush:bash">
dpkg-statoverride --add root sasl 710 /var/spool/postfix/var/run/saslauthd
</pre>
<p>And add postfix user to group sasl</p>
<pre  class="brush:bash">
adduser postfix sasl
</pre>
<p><code>/etc/default/saslauthd</code> Requires some modifications</p>
<pre  class="brush:bash">
START=yes
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"
</pre>
<p>Finally restart some services.</p>
<pre   class="brush:bash">
/etc/init.d/saslauthd restart
/etc/init.d/postfix restart
</pre>
<p><strong>Upgrading from debian etch</strong></p>
<p>If you are upgrading and getting permission errors then you can fix these by berforming the steps above where permissions for <code>/var/spool/postfix/var/run/saslauthd</code> are set and the user group sasl is updated.</p>
<pre>
SASL authentication failure: Password verification failed
SASL PLAIN authentication failed: generic failure
SASL authentication failure: cannot connect to saslauthd server: Permission denied
SASL LOGIN authentication failed: generic failure
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/01/19/sasl-postfix-with-debian-lenny/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The dreading timezone issue with JSF and how it hits you again with daylights saving</title>
		<link>http://www.martinahrer.at/2010/01/07/the-dreading-timezone-issue-with-jsf-and-how-it-hits-you-again-with-daylights-saving/</link>
		<comments>http://www.martinahrer.at/2010/01/07/the-dreading-timezone-issue-with-jsf-and-how-it-hits-you-again-with-daylights-saving/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 10:51:49 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaServer Faces]]></category>
		<category><![CDATA[timezone]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=386</guid>
		<description><![CDATA[JSF is converting all date/datetime types into GMT base for rendering. This can cause a date offset of n-hours to be shown depending on the timezone you are in. You have 2 choices to deal with it: Either you implement an application wide (global) date converter as described here or you add the timezone attribute [...]]]></description>
			<content:encoded><![CDATA[<p>JSF is converting all date/datetime types into GMT base for rendering. This can cause a date offset of n-hours to be shown depending on the timezone you are in. You have 2 choices to deal with it:<br />
Either you implement an application wide (global) date converter as described <a href="http://www.coderanch.com/t/212267/JSF/java/MyFaces-Date-TimeZone-Issue">here </a>or you add the timezone attribute to each of the convertDateTime tags.<br />
<span id="more-386"></span></p>
<pre class="brush:xml">
&lt;h:outputText value="#{day.date}"&gt;
	&lt;f:convertDateTime type="date" pattern="dd.MM.yyyy" timeZone="#{viewController.timeZoneId}"/&gt;
&lt;/h:outputText&gt;
</pre>
<p>The latter approach allows to have a single point of detecting a users timezone preference (unfortunately the timezone is not included in the HTTP header) but requires to have the timezone attribute implemented in multiple places.</p>
<p>So far so good. Many solutions propose using the timezone offset based timezone identifier which turns out to be bad. It doesn&#8217;t allow the JDK date formatters to properly apply the daylight settings. So better use &#8220;Europe/Vienna&#8221; instead of &#8220;GMT+1&#8243;. It even looks like there were some subtle <a href="http://www.mail-archive.com/dev@myfaces.apache.org/msg39804.html">changes </a>with turning from JDK 1.5 to JDK 1.6 regarding this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2010/01/07/the-dreading-timezone-issue-with-jsf-and-how-it-hits-you-again-with-daylights-saving/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending the FacesContext (and using a Faces Factory)</title>
		<link>http://www.martinahrer.at/2009/12/23/extending-the-facescontext-and-using-a-faces-factory/</link>
		<comments>http://www.martinahrer.at/2009/12/23/extending-the-facescontext-and-using-a-faces-factory/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 17:21:05 +0000</pubDate>
		<dc:creator>Martin Ahrer</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[JavaServer Faces]]></category>

		<guid isPermaLink="false">http://www.martinahrer.at/?p=378</guid>
		<description><![CDATA[JavaServer Faces has always been sold as a piece of flexible and extensible code. It really is. Through its factory facilities you can bend and twist that web framework until it fits. Today I tried to resolve something that has bothered me a long time. For a showcase I have implemented a few supporting lines [...]]]></description>
			<content:encoded><![CDATA[<p>JavaServer Faces has always been sold as a piece of flexible and extensible code. It really is. Through its factory facilities you can bend and twist that web framework until it fits. Today I tried to resolve something that has bothered me a long time. For a showcase I have implemented a few supporting lines of code that come handy in lots of places. When prototyping something, that code often ends up in some abstract base class from which managed bean are subclassed or it even ends up in some &#8220;helper&#8221; class with static methods. In the end you don&#8217;t feel that it is at the right place.<br />
<span id="more-378"></span><br />
The example I&#8217;m showing now is trying to detect if a request validated with some severe message.</p>
<pre class="brush:java">
public boolean isSevereMessage() {
	Severity severity = FacesContext.getCurrentInstance().getMaximumSeverity();
	return severity == null ? false : severity.compareTo(FacesMessage.SEVERITY_INFO) > 0;
}
</pre>
<p>Seems that could go into the FacesContext implementation, right? In order to get there you need a <a href="http://java.sun.com/javaee/javaserverfaces/2.0/docs/api/javax/faces/context/FacesContextFactory.html">FacesContextFactory </a>that instantiates your <a href="http://java.sun.com/javaee/javaserverfaces/2.0/docs/api/javax/faces/context/FacesContext.html">FacesContext </a>implementation.</p>
<p>The FacesContextFactory is setup by a <a href="http://java.sun.com/javaee/javaserverfaces/2.0/docs/api/javax/faces/FactoryFinder.html">FactoryFinder </a>which supports quite a few strategies for picking up the factory.</p>
<pre class="brush:java">
public class BlueprintFacesContextFactory extends FacesContextFactory {
	private final FacesContextFactory factory;
	public BlueprintFacesContextFactory(FacesContextFactory factory) {
		super();
		this.factory = factory;
	}
	@Override
	public FacesContext getFacesContext(Object context, Object request, Object response, Lifecycle lifecycle)
			throws FacesException {
		return new BlueprintFacesContext(factory.getFacesContext(context, request, response, lifecycle));
	}
}
</pre>
<p>By implementing a constructor that takes a FacesContextFactory as argument we can easily get hold of the factory provided by the JSF implementation and delegate.</p>
<p>For our FacesContext implementation the deal is to wrap the existing FacesContext with your own implementation. Therefore it also implements a constructor taking a Facescontext as argument.</p>
<pre class="brush:java">
public class BlueprintFacesContext extends FacesContext {
	private final FacesContext context;
	public BlueprintFacesContext(FacesContext context) {
		super();
		this.context = context;
		setCurrentInstance(this);
	}

	/**
	 * Test if a request processing resulted in a severe message. A message is
	 * considered severe if it is more severe than INFO.
	 *
	 * @return true if
	 *         &lt;code&gt;maximumSeverity.compareTo(FacesMessage.SEVERITY_INFO) &gt; 0&lt;/code&gt;
	 */
	public boolean isSevereMessage() {
		Severity severity = getMaximumSeverity();
		return severity == null ? false : severity.compareTo(FacesMessage.SEVERITY_INFO) > 0;
	}
	@Override
	public ELContext getELContext() {
		ELContext elContext = context.getELContext();
		elContext.putContext(FacesContext.class, this);
		return elContext;
	}
	//other methods stripped for brevity, they only delegate to context!
</pre>
<p>With JSF2 a <a href="http://java.sun.com/javaee/javaserverfaces/2.0/docs/api/javax/faces/context/FacesContextWrapper.html">FacesContextWrapper</a> is provided so only those methods need to overridden that are required to add the desired behaviour.<br />
Here I needed to override getELContext in order to make the custom FacesContext available in EL expressions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.martinahrer.at/2009/12/23/extending-the-facescontext-and-using-a-faces-factory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
