APACHE WICKET Component Based Web Development Framework Wicket
APACHE WICKET Component Based Web Development Framework
Wicket Agenda: There is an overwhelming number of Java web frameworks available today, primarily distinguished by two main groups, Traditional – or – request based (Struts, Spring MVC…) and Component Based (Wicket, Tapestry. . . ). What is Wicket? Why use Wicket? Core Wicket Concepts A few Wicket examples
What is Wicket? Open Source Component Based Enables component oriented, programmatic manipulation of markup Pure Java & HTML Clean separation of Java and HTML The mission: bringing object oriented programming to the web application view layer
Why use Wicket? Integration Spring Guice Hibernate and more… State management Clustering support Back button support
Why use Wicket cont. . Ajax support without writing Java. Script! Integration with some Java. Script libraries such as j. Query URL Mounting Pretty URLs Component Level Security
Core Wicket Concepts: The four most important wicket concepts that require understanding by any user, are Session, Components, Models, and Behaviors. Without these four main concepts you cannot manage dataflow throughout your wicket application. Pages & Panels Session Components Models Behaviors
Pages & Panels Page: A representation of what is to be displayed to the user when the page is loaded. Consists of HTML & Java May contain 1 … N panels Panel Consists of HTML & Java Reusable displayable component May contain 1 … N panels
Wicket and Sessions Wicket’s Session is an implementation of java’s Http. Session. Stores Session specific data Locale, client info Logged in user Shopping cart contents Page history and back button support And whatever else you need to maintain. .
Sessions are EASY with Wicket class My. Session extends Web. Session { private Shopping. Cart cart; public Shopping. Cart get. Cart() { … } public void set. Cart(Shopping. Cart cart) { … } } mysession. set. Cart(new Shopping. Cart()); The sessions is accessible from ALL pages / panels
Components! The ultimate superclass! Encapsulate the programmatic manipulation of markup. May receive events on. Click, on. Submit, etc. . Know how and when to render themselves
How components work. HTML Markup Java Code <h 1 wicket: id=“title”/> new Label(“title”, “It’s a Title!”); <input wicket: id=“first. Name”/> new Text. Field(“first. Name", new Property. Model(user, " first. Name ")); Behaviors: <button wicket: id=“add. User" type="submit" class="positive“> <b>Add User</b></button> Behaviors new Button(" add. User ", new Model<String>("Add User")) { @Override public void on. Submit() { // do something here!!! }
Component Validation Input validation is key in all web applications, fortunately Wicket makes this easy! Text. Field phone. Number. Input = new Text. Field("phone. Number. Input", new Property. Model(current. User, "phone. Number")); phone. Number. Input. set. Required(true). add(new String. Validator. Exact. Length. Validator(10)). add(new Pattern. Validator("[0 -9]*"));
Creating your own Components Wicket is designed and intended for extension, if the provided components don’t do EXACTLY what you want, you can easily extend any of them!
Wicket Models bind your POJO’s to Wicket components Label(“name”, model) <<Person>> Property. Model +name : String +city : String
Example Models: Property. Model: new Property. Model(person, “name”) new Property. Model(person, “address. street”) In Code: Person person = new Person(); new Text. Field(“first. Name", new Property. Model(person, "first. Name"));
Examples and Q & A
- Slides: 16