<?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>VolkomenJuist.nl &#187; component</title>
	<atom:link href="http://www.volkomenjuist.nl/blog/tag/component/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.volkomenjuist.nl/blog</link>
	<description>Juist! Volkomen Juist!</description>
	<lastBuildDate>Mon, 08 Mar 2010 19:58:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Wicket&#8217;s FormComponent setType</title>
		<link>http://www.volkomenjuist.nl/blog/2009/02/05/wickets-formcomponent-settype/</link>
		<comments>http://www.volkomenjuist.nl/blog/2009/02/05/wickets-formcomponent-settype/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 20:41:02 +0000</pubDate>
		<dc:creator>Stefanovich</dc:creator>
				<category><![CDATA[Wicket]]></category>
		<category><![CDATA[component]]></category>
		<category><![CDATA[setType]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.volkomenjuist.nl/blog/?p=143</guid>
		<description><![CDATA[If you are creating a form for your application you might need some validation on components before submitting. Wicket has some methods (e.g setRequired(true)) which can help you with that. In this article I will show you the setType method. This method will prevent you to submit the form when e.g. the input field is not filled in [...]]]></description>
			<content:encoded><![CDATA[<p>If you are creating a form for your application you might need some validation on components before submitting. Wicket has some methods (e.g <code>setRequired(true)</code>) which can help you with that. In this article I will show you the setType method. This method will prevent you to submit the form when e.g. the input field is not filled in correctly. An example could be when your users have to fill in a double as number. If the user fills in something else it will show a warning in the feedbackpanel. See java example below how to deal with this.</p>
<p><span id="more-143"></span></p>
<pre class="brush: java;">public HomePage(final PageParameters parameters) {

Form form = new Form(&quot;form&quot;, new CompoundPropertyModel(this));
add(form);

TextField tf = new TextField(&quot;doubleValue&quot;);
tf.setType(Double.class);
tf.setRequired(true);
form.add(tf);
form.add(new Button(&quot;bt1&quot;) {
 private static final long serialVersionUID = -1179492663996608643L;

 @Override
 public void onSubmit() {
  super.onSubmit();

  System.out.println(&quot;Form submitted&quot;);
}});

add(new FeedbackPanel(&quot;feedback&quot;).setOutputMarkupId(true));
}

public double getDoubleValue(){
 return m_value;
}

public void setDoubleValue(double value) {
 m_value = value;
} </pre>
<p>Please note the <code>setType(Double.class)</code> (line 7). This will prevent the user to submit the form when no double is filled in. Simply it doesn&#8217;t goes into the <code>onSubmit()</code> method. By default it will use the String type. This type will also be used when updating the model for this component.  </p>
<p>A shorter notation (instead of line 6 and 7):</p>
<pre class="brush: java;">TextField tf = new TextField(&quot;doubleValue&quot;, Double.class);
</pre>
<p>Corresponding HTML:</p>
<pre class="brush: xml;">
&lt;form wicket:id=&quot;form&quot;&gt;
&lt;input type=&quot;text&quot; wicket:id=&quot;tf1&quot;/&gt;
&lt;input type=&quot;submit&quot; wicket:id=&quot;bt1&quot;/&gt;
&lt;/form&gt;
&lt;div wicket:id=&quot;feedback&quot;/&gt;
</pre>
 <img src="http://www.volkomenjuist.nl/blog/wp-content/plugins/feed-statistics.php?view=1&post_id=143" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.volkomenjuist.nl/blog/2009/02/05/wickets-formcomponent-settype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
