Over a million developers have joined DZone.

Faster Development With EasyWicket

· Java Zone

Easily build powerful user management, authentication, and authorization into your web and mobile applications. Download this Forrester report on the new landscape of Customer Identity and Access Management, brought to you in partnership with Stormpath.

Wicket is a component based web framework which allows you to develop web applications in a similar way the desktop applications developed. The framework has very little effect on the HTML markup used. The dynamic elements of the html markup are marked with "wicket:id" attribute only. Eventhough it has very little addition on markup, its connection with the backend is very powerful thanks to the IModel interface.

IModel interface provides all the data the user interface elements need. Because the framework depends heavily on IModel interface, many implementations exist for IModel interface, but choosing the right model may be confusing at first. In addition to this, components of dynamic html elements created on server side but the creation and configuration of the components may lead to unnecessarily complex code.

For this reason, I am proposing another approach by using annotations to create and configure components on the server side. In order to explain it, I will create a simple "new user" page.

The source codes of the page is below;

PGNewUser.html :

<title>New User</title>
<form wicket:id="form">
<td> Name </td>
<td> <input type="text" wicket:id="txtName"/> </td>
<td> Surname </td>
<td> <input type="text" wicket:id="txtSurname"/> </td>
<td> Country </td>
<td> <select wicket:id="countrySelection" /> </td>
<td> <button type="submit" wicket:id="btnSubmit"> Send </button> </td>


public class PGNewUser extends WebPage implements IEasyWicketContainer{

Form<Void> form;

@EasyWicket(id="form.txtName", value="name")
TextField<String> txtName;

@EasyWicket(id="form.txtSurname", value="surname")
TextField<String> txtSurname;

@EasyWicket(id="form.countrySelection", value="selectedCountry",
list="countryList", idProperty="name", displayProperty="name")
DropDownChoice<Country> countrySelection;

@EasyWicket(id="form.btnSubmit", action="actionSubmit")
Button btnSubmit;

private static Logger logger = LoggerFactory.getLogger(PGNewUser.class);
private List<Country> countryList;
private Country selectedCountry;
private String name, surname;

public void initValues() {
countryList = Arrays.asList(Country.values());
selectedCountry = countryList.get(0);

public void pack() {

public void setCurrentWidgetContext(WidgetContext widgetContext) {

public void actionSubmit() {
logger.info("name=" + name + " surname=" + surname + " selected country=" + selectedCountry);

Components are marked with EasyWicket annotation.


public @interface EasyWicket {

public String id();
public String value() default "";
public String list() default "";
public String action() default "";

public boolean required() default false;

public String visible() default "";
public boolean ajaxEnabled() default false;

// Data table
public String rowsPerPage() default "10";
public String columns() default "";

// Drop down
public String displayProperty() default "";
public String idProperty() default "";

"id" is the path from topmost parent element to id of current dynamic element. If an element resides in a form element, and form element is the topmost parent then id of EasyWicket annotation is  [form_element_id.element_id]. You can see an example of this usage in java code. The textfield for name of the user defined as following;

@EasyWicket(id="form.txtName", value="name")

Here you see that the EasyWicket id is the combination of form and text field elements separated by dot.

"value" is the value of the html element. "list" is the list of possible values. For example, DropDownChoice get list of the choices from this value. "action" is used for buttons and links. It is called when button submitted or link clicked. "required" call setRequired() function of a form component. "visible" is active for some elements. It specifies the name of function to determine the visibility of the element. "ajaxEnabled" make element ready for ajax manipulation. "rowsPerPage" and "columns" used for DataTable component. "displayProperty" and "idProperty" is used for DropDownChoice components. They are the names of the properties for displaying id and text of the select boxes.

The page component, PGNewUser implements IEasyContainer interface. This interface must be implemented for the components containing EasyWicket components.


public interface IEasyWicketContainer {

public void initValues();
public void pack();
public void setCurrentWidgetContext(WidgetContext widgetContext);


"initValues()" called before components instantiated and configured. You have to initialize the values here. "pack()" called after components instantiated. "setCurrentWidgetContext()" called by some of EasyWicket components like DropDownChoice while rendering the component. It just gives the state of the current component to the container to get values while rendering in progress.

 And finally, If you want to enable EasyWicket library you have to add EasyWicketComponentListener to your application like that;

addComponentInstantiationListener(new EasyWicketComponentListener()); 
I attached source codes as zip file. Also you can get codes from easywicket.sourceforge.net.

Building Identity Management, including authentication and authorization? Try Stormpath! Our REST API and robust Java SDK support can eliminate your security risk and can be implemented in minutes. Sign up, and never build auth again!


The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}