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:
xml version = " 1.0" encoding = "UTF -8"? > < DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Strict / / EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd " >