180 likes | 380 Views
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...). .
E N D
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? • 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 JavaScript! • Integration with some JavaScript libraries such as jQuery • 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 • 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 HttpSession. • 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 MySession extends WebSession { private ShoppingCart cart; public ShoppingCartgetCart() { … } public void setCart(ShoppingCart cart) { … } } mysession.setCart(new ShoppingCart()); • The sessions is accessible from ALL pages / panels
Components! • The ultimate superclass! • Encapsulate the programmatic manipulation of markup. • May receive events • onClick, onSubmit, etc.. • Know how and when to render themselves
How components work. HTML Markup Java Code • <h1 wicket:id=“title”/> • <input wicket:id=“firstName”/> • Behaviors: • <button wicket:id=“addUser" type="submit" class="positive“> <b>Add User</b></button> • new Label(“title”, “It’s a Title!”); • new TextField(“firstName", new PropertyModel(user, "firstName")); • Behaviors • new Button("addUser", new Model<String>("Add User")) { • @Override • public void onSubmit() { • // do something here!!! • }
Component Validation • Input validation is key in all web applications, fortunately Wicket makes this easy! TextFieldphoneNumberInput = new TextField("phoneNumberInput", new PropertyModel(currentUser, "phoneNumber")); phoneNumberInput.setRequired(true) .add(new StringValidator.ExactLengthValidator(10)) .add(new PatternValidator("[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 • Models bind your POJO’s to Wicket components Label(“name”, model) <<Person>> +name : String +city : String PropertyModel
Example Models: • PropertyModel: • new PropertyModel(person, “name”) • new PropertyModel(person, “address.street”) • In Code: • Person person = new Person(); • new TextField(“firstName", new PropertyModel(person, "firstName"));