Apache Wicket

Apache Wicket is a component-based web framework for the Java programming language. It is an open source project and is now available under the Apache License version 2.0.

Target

Wicket aims to provide a comfortable, powerful and flexible way to create web applications for experienced Java programmers, so it should be allowed to be complex requirements and achieve high productivity. Due to the component-oriented approach of Wicket, it is very easy to develop your own reusable components.

Wicket forces the programmer, in contrast to many other frameworks, object-oriented consistently to program. It is placed on reusability great value.

Functionality

Properties of Wicket are:

  • Separation of logic (Java) and presentation (HTML and CSS).
  • Each component can store their data in an associated data model.
  • Automatic state management.
  • Except for web.xml no XML configuration files are required. Exclusively Java and (X) HTML knowledge is required to work with Wicket
  • The acquisition of the user input is done with Java. It is checked by Java first, whether an input is required, then the data in the appropriate data type to be converted. Finally, the data is checked for validity ( validation). These three steps can be trapped together for a web form on an error-handling system or component-wise. If all the steps without error, the data are stored in the data model.
  • Ajax is possible without any knowledge of JavaScript. There are some classes that provide Ajax functionality. All components can be ( also subsequently) Ajax functionality added via so-called Behaviors. There are, among other things, the class AjaxEventBehavior, for responding to a particular event or JavaScript class AbstractSelfUpdatingTimerBehavior, to automatically update the individual components at certain time intervals.

Conceptually Wicket is most comparable to Apache Tapestry, but competes primarily with Java Server Faces and Google Web Toolkit.

History

The architecture of Wicket was designed in 2004 by Jonathan Locke and Miko Matsumura, and was up to version 1.2 available on sourceforge.org. Later, the framework has been available as open - source project under the Apache license. A group of programmers by the Dutch company Topicus who were led by Eelco Hillenius, Martijn and Johan Dashorst Compagner, in addition to some other form until today, the core team. Wicket is available as an open source project under the Apache License, Version 2.0.

Since version 6.0.0, Wicket is mandatory in JDK 6 or higher. In addition, is now used by Wicket in the background as a jQuery Ajax implementation.

Example

A simple example consists of four files:

  • An Application class, which is called first
  • A Java file, which represents the side
  • To a Java file associated HTML file
  • And the web.xml file of the Tomcat server for configuration, which class is the Applications class.

Application class

The Application class provides a single entry point for the web application. Here, various settings can be made which are valid for the whole application. Among other things, the home page is set here:

Package com.myapp.wicket;   import org.apache.wicket.protocol.http.WebApplication;   public class Application extends WebApplication {      public class getHomePage () {          return OnePage.class;      } } Web Page (Java)

Each page ( Page ) is represented by a Java class and an associated HTML file of the same name. All components of the class are defined here. All components that a wicket in the HTML file: id have to be added as components.

OnePage.java:

Package com.myapp.wicket;   import org.apache.wicket.ajax.AjaxEventBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.Model;   public class OnePage extends WebPage {        public OnePage () {          final Label label = new Label ( "message", new Model ( ""));          label.setOutputMarkupId (true);          Form form = new form ("form ");          final TextField field = new TextField ("field ", new Model ( ""));          field.setOutputMarkupId (true);          form.add (field);          final Button but1 = new Button ( " button1 ") {                @ Override              public void onSubmit () {                  String value = ( String) field.getModelObject ();                  label.setModelObject ("normal request :" value);                  field.setModelObject ( "");                  / / SetResponsePage ( AnotherPage.class );              }          };          but1.setOutputMarkupId (true);          form.add ( but1 );          final Button but2 = new Button ( " Button disable ..." " button2 ", new Model ());          but2.add (new AjaxEventBehavior ( " onclick" ) {                @ Override              protected void onEvent ( AjaxRequest Target target) {                  but1.setEnabled (! but1.isEnabled ());                  if ( but1.isEnabled ()) {                      but2.setModelObject ("Button disable ... ");                  Else { }                      but2.setModelObject ("Button Activate ... ");                  }                  target.addComponent ( but2 );                  target.addComponent ( but1 );              }          });          form.add ( but2 );          add ( form);          add ( label);      } } Web Page (HTML)

For each component to be changed dynamically, one must attribute wicket: id to be created.

OnePage.html:

< DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Strict / / EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd " >               Echo Application </ title>      </ head>      <body>          <h1> echo example < / h1 >          <form wicket:id="form">              <input wicket:id="field" type="text" />              <input wicket:id="button1" type="submit" value="Button" />              <input wicket:id="button2" type="button" value="Button deaktivieren..." />          </ form >          <p wicket:id="message"> Fun Fun Fun </ p>      </ body> </ html> web.xml </p> <p> The application is only using the following web.xml - included file in the servlet container as a web application: </p> <p> <? xml version = " 1.0" encoding = "UTF -8"? > < web-app version = " 2.5" xmlns = " http://java.sun.com/xml/ns/javaee "     xmlns: xsi = " http://www.w3.org/2001/XMLSchema-instance "     xsi: schemaLocation = " http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd " >        <filter>          <filter-name> WicketApplication </ filter -name>          <filter-class> org.apache.wicket.protocol.http.WicketFilter < / filter- class>          <init-param>              <param-name> application class name < / param -name>              <param-value> com.myapp.wicket.Application </ param-value >          < / init -param >      < / filter>      <filter-mapping>          <filter-name> WicketApplication </ filter -name>          <url-pattern> / * </ url-pattern >      </ filter -mapping> < / web- app> versions </p> <p> Wicket has experienced a great development over time. </p> <ul> <li>From Wicket 1.4 there is support for generic data types. The latest version of the 4-series is here Wicket 1.4.27. </li> <li>With Wicket 1.5 the API has been radically changed. The latest version is here Wicket 1.5.10. </li> <li>With Wicket 6.x support Ajax wicket own was replaced by jQuery. </li> </ul> </section> <section class="relLinks"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- memim 1 wide adaptive --> <ins class="adsbygoogle" style="display:block;clear:both;" data-ad-client="ca-pub-8545452838648870" data-ad-slot="6796476374" data-ad-format="auto"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <a href="/apache-software-foundation.html">Apache Software Foundation</a> <a href="/web-application-framework.html">Web Application Framework</a> <a href="/uniform-resource-locator.html">Uniform Resource Locator</a> <a href="/javaserver-faces.html">JavaServer Faces</a> <a href="/java-development-kit.html">Java Development Kit</a> <a href="/apache-tomcat.html">Apache Tomcat</a> <a href="/integrated-authority-file.html">Integrated Authority File</a> </section> <div class="comments"> </div> <section> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block" data-ad-format="autorelaxed" data-ad-client="ca-pub-8545452838648870" data-ad-slot="9697283175"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </section> <span style="font-size:.5em">73009</span> <div class="share_buttons"> <div class="addthis_sharing_toolbox"></div> </div> </main> </div> </td></tr><tr><td id="footer"> <div class="aligner"> <footer class="mainHolder" style="text-align:center;"> <!--LiveInternet counter--><script type="text/javascript"><!-- document.write("<a href='http://www.liveinternet.ru/click' "+ "target=_blank rel=nofollow><img src='//counter.yadro.ru/hit?t18.5;r"+ escape(document.referrer)+((typeof(screen)=="undefined")?"": ";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth? screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+ ";"+Math.random()+ "' alt='' title='LiveInternet' "+ "border='0' width='88' height='31'><\/a>") //--></script><!--/LiveInternet--> <br /> memim.com 2020<br /> All rights reserved<br /> <span style='font-size:0.5em'>Page generated in 0.0154<br /></span> <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5093bb6e1c1ddca0"></script> <script> function jr(ready){ if(window.jQuery){ //ready(); }else{ setTimeout(jr,100,ready); } } jr(function() { $(".imagesHolder img").each(function () { var i=$(this); console.log(i.attr('src')+' '+i.width()+' '+i.readyState); //$(this).remove(); }); }); </script> </footer> </div> </td></tr></table> <span style="font-size:.3em">de</span> </body> </html>