<?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>JSF Blog &#187; JSF</title>
	<atom:link href="http://www.jsfblog.info/category/jsf/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jsfblog.info</link>
	<description>Discussion on all things Java and JSF</description>
	<lastBuildDate>Fri, 03 Feb 2012 20:24:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using maven to check facelets are valid</title>
		<link>http://www.jsfblog.info/2011/02/using-maven-to-check-facelets-are-valid/</link>
		<comments>http://www.jsfblog.info/2011/02/using-maven-to-check-facelets-are-valid/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 11:36:00 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[JSF]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[xml-maven-plugin]]></category>

		<guid isPermaLink="false">http://www.jsfblog.info/?p=404</guid>
		<description><![CDATA[Although eclipse validates our xml documents, sometimes invalid xml documents can get committed into our source repository by accident. Using the maven xml-maven-plugin we can force the build to break when xml documents aren&#8217;t welformed. Currently we are only doing it for facelets files (with a .xhtml extension): The xml snippet below shows the configuration [...]]]></description>
			<content:encoded><![CDATA[<p>Although eclipse validates our xml documents, sometimes invalid xml documents can get committed into our source repository by accident.</p>
<p>Using the <a href="http://maven.apache.org/" target="_blank">maven</a> <a href="http://mojo.codehaus.org/xml-maven-plugin/validation.html">xml-maven-plugin</a> we can force the build to break when xml documents aren&#8217;t welformed.</p>
<p>Currently we are only doing it for facelets files (with a .xhtml extension): The xml snippet below shows the configuration of the plugin for xhtml files.</p>
<p>Add this to the plugins element in the build section.</p>
<pre class="brush: xml; highlight: [16]; title: ; notranslate">
&lt;plugin&gt;
	&lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
	&lt;artifactId&gt;xml-maven-plugin&lt;/artifactId&gt;
	&lt;executions&gt;
		&lt;execution&gt;
			&lt;goals&gt;
				&lt;goal&gt;validate&lt;/goal&gt;
			&lt;/goals&gt;
		&lt;/execution&gt;
	&lt;/executions&gt;
	&lt;configuration&gt;
		&lt;validationSets&gt;
			&lt;validationSet&gt;
				&lt;dir&gt;src/main/webapp&lt;/dir&gt;
				&lt;includes&gt;
					&lt;include&gt;**/*.xhtml&lt;/include&gt;
				&lt;/includes&gt;
			&lt;/validationSet&gt;
		&lt;/validationSets&gt;
	&lt;/configuration&gt;
&lt;/plugin&gt;
</pre>
<p><strong>To Do:</strong></p>
<p>Really we should be validating all xml files. Also we should investigate turning on schema validation, especially for facelets files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jsfblog.info/2011/02/using-maven-to-check-facelets-are-valid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSF, Iterating with tomahawk radio buttons, t:datalist, a4j:repeat</title>
		<link>http://www.jsfblog.info/2010/05/jsf-iterating-with-tomahawk-radio-buttons-tdatalist-a4jrepeat/</link>
		<comments>http://www.jsfblog.info/2010/05/jsf-iterating-with-tomahawk-radio-buttons-tdatalist-a4jrepeat/#comments</comments>
		<pubDate>Fri, 14 May 2010 18:22:48 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[tomahawk]]></category>

		<guid isPermaLink="false">http://www.jsfblog.info/?p=224</guid>
		<description><![CDATA[The standard JSF radio buttons h:selectOneRadio render a load of old school html (i.e. they use table tags to do layout, (all a bit 1996)). e.g. JSF h:selectOneRadio tag Code for #{radioOptions} Note: I&#8217;m using jboss seam in the example above, but you could easily remove the seam annotations and define the bean in using [...]]]></description>
			<content:encoded><![CDATA[<p>The standard JSF radio buttons <a href="http://java.sun.com/javaee/javaserverfaces/1.2/docs/tlddocs/h/selectOneRadio.html">h:selectOneRadio</a> render a load of old school html (i.e. they use table tags to do layout, (all a bit 1996)).</p>
<p>e.g. JSF h:selectOneRadio tag</p>
<pre class="brush: xml; title: ; notranslate">
&lt;h:selectOneRadio id=&quot;aRadio&quot;&gt;
	&lt;f:selectItems value=&quot;#{radioOptions.items}&quot; /&gt;
&lt;/h:selectOneRadio&gt;
</pre>
<p>Code for #{radioOptions}</p>
<pre class="brush: java; title: ; notranslate">
import java.util.ArrayList;
import java.util.List;

import javax.faces.model.SelectItem;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

@Name(&quot;radioOptions&quot;)
@Scope(ScopeType.APPLICATION)
public class RadioOptions
{
	public List&lt;SelectItem&gt; items = new ArrayList&lt;SelectItem&gt;();

	public RadioOptions()
	{
		items.add(new SelectItem(&quot;1&quot;, &quot;label 1&quot;));
		items.add(new SelectItem(&quot;2&quot;, &quot;label 2&quot;));
		items.add(new SelectItem(&quot;3&quot;, &quot;label 3&quot;));
	}

	public List&lt;SelectItem&gt; getItems()
	{
		return items;
	}

	public void setItems(List&lt;SelectItem&gt; items)
	{
		this.items = items;
	}
}
</pre>
<p>Note: I&#8217;m using jboss seam in the example above, but you could easily remove the seam annotations and define the bean in using jsf managed beans or faces config etc. Also the examples here are a bit mickey mouse and could be better.</p>
<p>Under JSF 1.2 will be rendered as</p>
<pre class="brush: xml; title: ; notranslate">
&lt;table id=&quot;myForm:aRadio&quot;&gt;
	&lt;tr&gt;
		&lt;td&gt;
			&lt;input type=&quot;radio&quot; name=&quot;myForm:aRadio&quot; id=&quot;myForm:aRadio:0&quot; value=&quot;1&quot; /&gt;
			&lt;label for=&quot;myForm:aRadio:0&quot;&gt;Label 1&lt;/label&gt;
		&lt;/td&gt;
		&lt;td&gt;
			&lt;input type=&quot;radio&quot; name=&quot;myForm:aRadio&quot; id=&quot;myForm:aRadio:1&quot; value=&quot;2&quot; /&gt;
			&lt;label for=&quot;myForm:aRadio:1&quot;&gt;Label 2&lt;/label&gt;
		&lt;/td&gt;
		&lt;td&gt;
			&lt;input type=&quot;radio&quot; name=&quot;myForm:aRadio&quot; id=&quot;myForm:aRadio:2&quot; value=&quot;3&quot; /&gt;
			&lt;label for=&quot;myForm:aRadio:2&quot;&gt;Label 3&lt;/label&gt;
		&lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;
</pre>
<p>Anyway this limitation is well known and as a result we&#8217;ve been using the apache tomahawk <a href="http://myfaces.apache.org/tomahawk-project/tomahawk12/tagdoc/t_selectOneRadio.html">t:selectOneRadio</a> (using the layout=&#8221;spread&#8221; attribute) and <a href="http://myfaces.apache.org/tomahawk-project/tomahawk12/tagdoc/t_radio.html">t:radio</a> tags to provide more flexible layouts which can be styled by css.</p>
<p><strong>Iterating through a list of select items</strong></p>
<p>There are times when I want to render the radio buttons in a flexible fashion (offered by t:radio) using a loop tag such as <a href="http://myfaces.apache.org/tomahawk-project/tomahawk12/tagdoc/t_dataList.html">t:dataList</a> or <a href="http://docs.jboss.org/richfaces/latest_3_3_X/en/tlddoc/a4j/repeat.html">a4j:repeat</a> e.g.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot; xmlns:h=&quot;http://java.sun.com/jsf/html&quot; xmlns:f=&quot;http://java.sun.com/jsf/core&quot; xmlns:fn=&quot;http://java.sun.com/jsp/jstl/functions&quot; xmlns:c=&quot;http://java.sun.com/jstl/core&quot; xmlns:t=&quot;http://myfaces.apache.org/tomahawk&quot; xmlns:a4j=&quot;https://ajax4jsf.dev.java.net/ajax&quot;&gt;
&lt;f:view&gt;
&lt;h:form id=&quot;myForm&quot;&gt;
	&lt;!-- radio button, layout spread  --&gt;
	&lt;t:selectOneRadio id=&quot;myRadio&quot; forceId=&quot;true&quot; layout=&quot;spread&quot;&gt;
		&lt;f:selectItems value=&quot;#{radioOptions.items}&quot; /&gt;
	&lt;/t:selectOneRadio&gt;

	&lt;!-- data list, loops through all the radio button options --&gt;
	&lt;t:dataList var=&quot;helper&quot; value=&quot;#{radioOptions.items}&quot; rowIndexVar=&quot;idx&quot;&gt;
		&lt;!-- example html, not constrained to table layout --&gt;
		&lt;h1&gt;Heading&lt;/h1&gt;
		&lt;t:radio for=&quot;myRadio&quot; index=&quot;#{idx}&quot;/&gt;
		&lt;h1&gt;Another Heading&lt;/h1&gt;
	&lt;/t:dataList&gt;
&lt;/h:form&gt;
&lt;/f:view&gt;
&lt;/html&gt;
</pre>
<p>Unfortunately this doesn&#8217;t work and throws:</p>
<pre class="brush: plain; title: ; notranslate">
java.lang.IllegalStateException: Could not find component 'myRadio' (calling findComponent on component 'myForm:j_id3:0:j_id5')
</pre>
<p><strong>The Fix:</strong></p>
<p>I <em>almost always</em> forget this which is why im blogging about it,</p>
<pre class="brush: xml; title: ; notranslate">
&lt;t:radio for=&quot;myRadio&quot; index=&quot;#{idx}&quot;/&gt;
</pre>
<p>needs to be replaced with</p>
<pre class="brush: xml; title: ; notranslate">
&lt;t:radio for=&quot;:myForm:myRadio&quot; index=&quot;#{idx}&quot;/&gt;
</pre>
<p>The tomahawk t:radio component must have the <a href="#fullyQualified"><em>fully qualified</em></a> component name of the t:selectOneRadio name otherwise it cannot find it.</p>
<p>Since the form is defined as:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;h:form id=&quot;myForm&quot;&gt;
</pre>
<p>:myForm needs to be prefixed to the for attribute of the t:radio giving :myForm:myRadio</p>
<p>I take absolutely no credit for this because its explained <a href="https://issues.apache.org/jira/browse/TOMAHAWK-26">here</a> and on the <a href="http://wiki.apache.org/myfaces/Display_Radio_Buttons_In_Columns">Myfaces wiki </a>this article is merely a note to self.</p>
<p>Btw, the above works with a4j:repeat as well as t:datalist</p>
<p><span style="text-decoration: line-through">Currently tomahawk isn&#8217;t working in JSF 2.0 which is a shame as we are looking to upgrade very soon. Hopefully a decent radio button will become part of JSF 2 at some point.</span></p>
<p>The<a href="http://myfaces.apache.org/tomahawk-project/tomahawk20/index.html"> tomahawk </a>component library now works with JSF 2.0</p>
<h5 id="fullyQualified">Update: Fully Qualified JSF Name</h5>
<p>A bit of searching around on the web took me to Lincoln Baxter&#8217;s blog  where he mentions <a href="http://ocpsoft.com/java/jsf2-java/how-to-jsf-2-0-render-components-outside-of-the-form/">rendering  components outside of the form</a> and explains that the first &#8220;:&#8221;  tells JSF to start looking from the very top of the JSF View Root. Thanks for that!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jsfblog.info/2010/05/jsf-iterating-with-tomahawk-radio-buttons-tdatalist-a4jrepeat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

