Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

56
Apache Wicket Gerolf Seitz

Transcript of Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Page 1: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Apache Wicket

Gerolf Seitz

Page 2: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Web Development withjust Java

and a little bit of HTML

Page 3: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Gerolf Seitz

• Since Sept.07– Committer– PMC

• MSc student (almost finished)

• Software Engineer at Software Competence Center Hagenberg GmbH, Upper Austria

Page 4: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Agenda

• What is Wicket?

• Core Concepts

• Developing a custom Component

• Summary

• Q&A

Page 5: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Agenda

• What is Wicket?

• Core Concepts

• Developing a custom Component

• Summary

• Q&A

Page 6: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Wicket in a Nutshell

• Open Source

• Component oriented

• Web application framework

• Java + HTML

Page 7: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Features

• Everything in Java

• State management

• Safe URLs

• Nice URLs (mounting)

• OOTB support for– Clustering– Portlet

Page 8: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Features

• Reusable components

• Nested forms

• No more double submit of forms

• Back-button-support

• I18n

• WicketTester

Page 9: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Features

• Ajax "without" JavaScript

• Header Contributions– JavaScript & CSS

• Component level security

Page 10: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Hello, World!<h1 wicket:id="msg">[text goes

here]</h1>

Page 11: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Hello, World!<h1 wicket:id="msg">[text goes

here]</h1>

+

add(new Label("msg", "Hello, World!"));

Page 12: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Hello, World!<h1 wicket:id="msg">[text goes

here]</h1>

+

add(new Label("msg", "Hello, World!"));

=

<h1>Hello, World!</h1>

Page 13: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Hello, World!<h1 wicket:id="msg">[text goes

here]</h1>

+

add(new Label("msg", "Hello, World!"));

=

<h1>Hello, World!</h1>

Page 14: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Hello, World!<h1 wicket:id="msg">[text goes

here]</h1>

+

add(new Label("msg", "Hello, World!"));

=

<h1>Hello, World!</h1>

Page 15: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Brief History

• 2004: The First Encounter

• 2005: JavaOne'05 Smackdown

• 2006: Incubation at ASF

Page 16: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Brief History

• 2007: Graduation

• 2007: 1.3 released

• 2007: WUGs start spawningAmsterdam meetup: 80 attendees

Page 17: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Projects

• core

• extensions

• ioc (spring, guice)

• date/time

• velocity

• jmx

Page 18: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Getting Wicket

Current Release: 1.3.3

<dependencygroupId="org.apache.wicket"artifactId="wicket"version="1.3.3"

/>

Page 19: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Getting Wicket - Quickstarthttp://wicket.apache.org/quickstart.html

Page 20: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Agenda

• What is Wicket?

• Core Concepts

• Developing a custom Component

• Summary

• Q&A

Page 21: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Core Concepts

• Application

• Session

• RequestCycle

• Components

• Behaviors

• Models

Page 22: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Application

• Main entry point

• Initialization

• Configuration

• Factories

• Homepage

• Configured in web.xml

Page 23: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Application<filter> <filter-name>wicket</servlet-name> <filter-class>

org.apache.wicket.protocol.http.WicketFilter </filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>example.MyApplication</param-

value> </init-param> <load-on-startup>1</load-on-startup></filter>

Page 24: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Core Concepts

• Application

• Session

• RequestCycle

• Components

• Behaviors

• Models

Page 25: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Session

• Abstraction of a user session

• Stores session specific data

• Strongly typed session attributes

Page 26: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Core Concepts

• Application

• Session

• RequestCycle

• Components

• Behaviors

• Models

Page 27: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

RequestCycle

• Stateful– Tied to specific user session– Not (typically) bookmarkable

• Stateless– Not necessarily tied to specific user

session– Bookmarkable

Page 28: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Core Concepts

• Application

• Session

• RequestCycle

• Components

• Behaviors

• Models

Page 29: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Components

• Basic building blocks

• Encapsulate the programmatic manipulation of markup

• Render content

• Receive events

– onClick, onSubmit

Page 30: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Components – lots of `em

• Label, MultiLineLabel, TextField, PasswordTextField, Image, Link, AjaxLink, AjaxFallbackLink, Button, AjaxButton, DatePicker, ListView, RefreshingView, DataGrid, DataTable, Tree, GMap, Wizard, JasperReports, ...

Page 31: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Components

• Component has wicket:id

• Same wicket:id in markup

• Hierarchy must match

<h1 wicket:id=„msg“>[gets replaced]</h1>

new Label(„msg“, „Hello World!“);

Page 32: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Component: Link<a href="#" wicket:id="link">Click</a>

Link link = new Link("link");

add(link);

Page 33: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Component: Link<a href="#" wicket:id="link">Click</a>

Link link = new Link("link") {@Override public void onClick() {

//do somethingsetResponsePage(new NewPage());

}};add(link);

Page 34: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Component: AjaxLink<a wicket:id="link">Click</a>

AjaxLink link = new AjaxLink("link") {public void onClick(AjaxRequestTarget t){

//do something

}};add(link);

Page 35: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Component: AjaxLink<a wicket:id="link">Click</a>

someComponent.setOutputMarkupId(true);AjaxLink link = new AjaxLink("link") {

public void onClick(AjaxRequestTarget t){//do somethingt.addComponent(someComponent);

t.appendJavascript("Effects.fade('foo');");}

};add(link);

Page 36: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Components

• Components with own markup– Page, Panel, Border

• Java and markup files in same package on classpath

Page 37: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Core Concepts

• Application

• Session

• RequestCycle

• Components

• Behaviors

• Models

Page 38: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Behaviors

• Plugins for components• Change attributes of your component‘s

markup• Add Javascript events• Add Ajax behavior

timeLabel.add(new AjaxSelfUpdatingTimerBehavior(

Duration.seconds(5)));

Page 39: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Behaviorslink.add(new AbstractBehavior() {

public void onComponentTag(Component component, ComponentTag tag) {tag.put("onclick",

"return confirm('Are you sure?');");

}

});

Output:<a href="..." onclick="return

confirm('...');">...</a>

Page 40: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Core Concepts

• Application

• Session

• RequestCycle

• Components

• Behaviors

• Models

Page 41: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Models

• Bind POJO's to Wicket components

new Label("name", model)

Model

<<Person>+name: String+city: String

Page 42: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Models

• Lazy binding in Java sucks– Doesn't update:

• new Label("name", person.getName());

– Null checks necessary• new Label("street", person.getAddress().getStreet());

• Solution: OGNL/EL like expressions

Page 43: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Models

• PropertyModel:– new PropertyModel(person, “name”)– new PropertyModel(person,

“address.street”)

• CompoundPropertyModel– setModel(new CompoundPropertyModel(p));

– add(new Label("name"));– add(new Label("address.street"));

Page 44: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Agenda

• What is Wicket?

• Core Concepts

• Developing a custom Component

• Summary

• Q&A

Page 45: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Custom Components• Eelco Hillenius:

« Imagine being told that you can use Java as your programming language, but at the same time being told not to create your own classes. [...]

I fail to understand why that has to be different for UI development, and Wicket proves it doesn't have to be so. »

Page 46: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

PasswordStrenghIndicator<html>

<head><title>Insert title here</title><wicket:head>

<wicket:link><link rel="stylesheet" type="text/css" href="res/PasswordField.css"/>

</wicket:link></wicket:head>

</head><body>

<wicket:panel><input wicket:id="password" type="password" /><span

wicket:id="strength">[strengthbar]</span></wicket:panel><div>

<hr/>Examples:<br/><input type="password" /> <span class="weak">&nbsp;</span> (weak)<br/><input type="password" /> <span class="medium">&nbsp;</span> (medium)<br/><input type="password" /> <span class="strong">&nbsp;</span> (strong)<br/>

</div></body>

</html>

Page 47: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

PSI - Markup<wicket:head>

<wicket:link><link rel="stylesheet" type="text/css"

href="res/PasswordField.css"/></wicket:link>

</wicket:head>

<wicket:panel><input wicket:id="password" type="password" />

<span wicket:id="strength">[strengthbar]</span></wicket:panel>

Page 48: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

PSI - Javapublic class PasswordField extends Panel {

public final static String WEAK = "weak";public final static String MEDIUM = "medium";public final static String STRONG = "strong";

 public PasswordField(String id, IModel model) {

super(id, model);PasswordTextField passwordTextField = new PasswordTextField("password", model);add(passwordTextField);

 final Label strength = new Label("strength", "");add(strength);strength.add(new AttributeModifier("class", true, new Model() {

public Object getObject() {return getPasswordStrength(PasswordField.this.getModelObjectAsString());

}}));

 strength.setOutputMarkupId(true);passwordTextField.add(new OnKeyPausedAjaxBehavior() {

protected void onUpdate(AjaxRequestTarget target) {target.addComponent(strength);

}});

}}

Page 49: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

PSI - TestPagepublic class TestPage extends WebPage {

private String password;

public TestPage() {Form form = new Form("form");form.add(new PasswordField("password",

new PropertyModel(this, "password")));

add(form);}

}

Page 50: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Agenda

• What is Wicket?

• Core Concepts

• Developing a custom Component

• Summary

• Q&A

Page 51: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Summary

• Component oriented web application framework

• Just Java and HTML

• Easy Ajax

• Enthusiastic community

Page 52: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Community

• http://wicket.apache.org

[email protected]

• ##[email protected]

Page 53: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Future – Wicket NEXT• Java 5 based

– Generics (already in)– Varargs?– Typesafe PropertyModel

• New WicketTester– Based on JDave/Hamcrest

• Many more cool features

Page 54: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Books

Page 55: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Agenda

• What is Wicket?

• Core Concepts

• Developing a custom Component

• Q&A

Page 56: Apache Wicket Gerolf Seitz. Web Development with just Java and a little bit of HTML.

Thank you for yourattention