| I"ó%<p>The Apache Wicket project is proud to announce the release of Apache Wicket |
| 1.4. Apache Wicket is an open source, component oriented Java web application |
| framework. With overwhelming support from the user community, this release |
| marks a departure from the past where we leave Java 1.4 behind and we require |
| Java 5 as the minimum JDK version. By moving to Java 5 as the required |
| minimum platform, we were able to utilize Java 5 idioms and increase the type |
| safety of our APIs. Using Java generics you can now write typesafe web |
| applications and create typesafe, self documenting, reusable custom |
| components.</p> |
| |
| <h2 id="download-apache-wicket-14">Download Apache Wicket 1.4</h2> |
| |
| <p>You can download the release here: |
| http://www.apache.org/dyn/closer.cgi/wicket/1.4.0</p> |
| |
| <p>Or use this in your Maven pomâs to upgrade to the new version:</p> |
| |
| <figure class="highlight"><pre><code class="language-xml" data-lang="xml"><span class="nt"><dependency></span> |
| <span class="nt"><groupId></span>org.apache.wicket<span class="nt"></groupId></span> |
| <span class="nt"><artifactId></span>wicket<span class="nt"></artifactId></span> |
| <span class="nt"><version></span>1.4.0<span class="nt"></version></span> |
| <span class="nt"></dependency></span></code></pre></figure> |
| |
| <p>You will need to upgrade all modules (i.e. wicket, wicket-extensions) to |
| their 1.4 counterparts. It is not possible to mix Wicket 1.3 libraries with |
| 1.4 libraries due to API changes.</p> |
| |
| <h2 id="most-notable-changes">Most notable changes</h2> |
| |
| <p>From all the changes that went into this release, the following are the most |
| important ones:</p> |
| |
| <ul> |
| <li>Generified <code class="language-plaintext highlighter-rouge">IModel</code> interface and implementations increases type safety in your Wicket applications</li> |
| <li><code class="language-plaintext highlighter-rouge">Component#getModel()</code> and <code class="language-plaintext highlighter-rouge">Component#setModel()</code> have been renamed to <code class="language-plaintext highlighter-rouge">getDefaultModel()</code> and <code class="language-plaintext highlighter-rouge">setDefaultModel()</code> to better support generified models</li> |
| <li>The Spring modules have been merged (wicket-spring-annot is now obsolete, all you need is wicket-spring)</li> |
| <li>Many APIâs have been altered to better work with Java 5âs idioms</li> |
| <li>Wicket jars are now packaged with metadata that makes them OSGI bundles</li> |
| </ul> |
| |
| <p>Apart from these changes, the release is mostly compatible with Wicket 1.3 |
| and upgrading shouldnât take too long. Early adopters report about a days |
| work to upgrade medium to large applications to Wicket 1.4. Read the |
| migration guide to learn more about the changes in our APIs. To learn more |
| about all the improvements and new features that went into this release, |
| check the solved issue list in our JIRA instance.</p> |
| |
| <h2 id="increased-type-safety">Increased type safety</h2> |
| |
| <p>Moving towards Java 5 has given us the opportunity to utilize generics and |
| clarify our APIâs. For example, take a look at <code class="language-plaintext highlighter-rouge">DropDownChoice</code>âone of the |
| components with the most questions on our list prior to 1.4. A |
| <code class="language-plaintext highlighter-rouge">DropDownChoice</code> component is a form component that displays a list of |
| available choices in a drop down box, and allows one selection to be made. |
| DropDownChoice components are typically used to display a list of countries, |
| nationalities, credit card processors, etc.</p> |
| |
| <p>The signature of a constructor for the <code class="language-plaintext highlighter-rouge">DropDownChoice</code> component in Wicket |
| 1.3 was:</p> |
| |
| <figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="kd">class</span> <span class="nc">DropDownChoice</span> <span class="kd">extends</span> <span class="o">...</span> |
| <span class="kd">public</span> <span class="nf">DropDownChoice</span><span class="o">(</span><span class="nc">String</span> <span class="n">id</span><span class="o">,</span> <span class="nc">IModel</span> <span class="n">model</span><span class="o">,</span> <span class="nc">IModel</span> <span class="n">choices</span><span class="o">)</span> |
| <span class="o">}</span></code></pre></figure> |
| |
| <p>As you can see, this constructor doesnât give much insight into what goes |
| where (other than the names of the parameters). The first parameter is the |
| component identifier, the second parameter is the model that contains the |
| selection, and the third parameter is a model that contains the list of |
| choices from which the user can select one. Youâll have to read the JavaDoc |
| to assign the right IModel values to the right parameters. Now take a look at |
| the same constructor, but now in Wicket 1.4. The signature for our generified |
| constructor looks like the following example.</p> |
| |
| <figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="kd">public</span> <span class="o"><</span><span class="no">T</span><span class="o">></span> <span class="nc">DropDownChoice</span> <span class="kd">extends</span> <span class="o">...</span> |
| <span class="kd">public</span> <span class="nf">DropDownChoice</span><span class="o">(</span><span class="nc">String</span> <span class="n">id</span><span class="o">,</span> <span class="nc">IModel</span><span class="o"><</span><span class="no">T</span><span class="o">></span> <span class="n">model</span><span class="o">,</span> <span class="nc">IModel</span><span class="o"><?</span> <span class="kd">extends</span> <span class="nc">List</span><span class="o"><?</span> <span class="kd">extends</span> <span class="no">T</span><span class="o">>></span> <span class="n">choices</span><span class="o">)</span> |
| <span class="o">}</span></code></pre></figure> |
| |
| <p>Here we communicate that the first <code class="language-plaintext highlighter-rouge">IModel</code> parameter is a <code class="language-plaintext highlighter-rouge">T</code>, which is the |
| single value that will be provided when the <code class="language-plaintext highlighter-rouge">DropDownChoice</code> selects one |
| value. The second parameter provides a <code class="language-plaintext highlighter-rouge">List</code> of objects that extend <code class="language-plaintext highlighter-rouge">T</code>, the |
| choices from which to select one value. This was not apparent in the Wicket |
| 1.3 API, and the type safety brought by generics make this much more clear, |
| albeit much more verbose.</p> |
| |
| <h2 id="removal-of-default-model-from-component">Removal of default model from component</h2> |
| |
| <p>In Wicket 1.3 each component had by default a model: a <code class="language-plaintext highlighter-rouge">Label</code> had a model, a |
| <code class="language-plaintext highlighter-rouge">Link</code> and even <code class="language-plaintext highlighter-rouge">WebMarkupContainer</code> had a model property (all because they |
| extend <code class="language-plaintext highlighter-rouge">Component</code> which has a model property). When we generified <code class="language-plaintext highlighter-rouge">IModel</code>, |
| this had averse effects on <code class="language-plaintext highlighter-rouge">Component</code>: suddenly all components had to be |
| generified and had to take the type parameter of the model that was |
| associated with it. But that poses problems for components that either do not |
| use a model or use two different model types: which one should be in the |
| lead? We chose to generify only the components that clearly benefited from |
| the extra type information, leading to clean code like this:</p> |
| |
| <figure class="highlight"><pre><code class="language-java" data-lang="java"><span class="nc">ListView</span><span class="o"><</span><span class="nc">Person</span><span class="o">></span> <span class="n">peopleListView</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">ListView</span><span class="o"><</span><span class="nc">Person</span><span class="o">>(</span><span class="s">"people"</span><span class="o">,</span> <span class="n">people</span><span class="o">)</span> <span class="o">{</span> |
| <span class="kd">protected</span> <span class="kt">void</span> <span class="nf">populateItem</span><span class="o">(</span><span class="nc">ListItem</span><span class="o"><</span><span class="nc">Person</span><span class="o">></span> <span class="n">item</span><span class="o">)</span> <span class="o">{</span> |
| <span class="n">item</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="k">new</span> <span class="nc">Link</span><span class="o"><</span><span class="nc">Person</span><span class="o">>(</span><span class="s">"editPerson"</span><span class="o">,</span> <span class="n">item</span><span class="o">.</span><span class="na">getModel</span><span class="o">()){</span> |
| <span class="kd">public</span> <span class="kt">void</span> <span class="nf">onClick</span><span class="o">()</span> <span class="o">{</span> |
| <span class="nc">Person</span> <span class="n">p</span> <span class="o">=</span> <span class="n">getModelObject</span><span class="o">();</span> |
| <span class="n">setResponsePage</span><span class="o">(</span><span class="k">new</span> <span class="nc">EditPersonPage</span><span class="o">(</span><span class="n">p</span><span class="o">));</span> |
| <span class="o">}</span> |
| <span class="o">});</span> |
| <span class="o">}</span> |
| <span class="o">};</span></code></pre></figure> |
| |
| :ET |