Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Apache Wicket Web Framework


Published on

Apache Wicket Web Framework Presentation

Published in: Technology, Education
  • Login to see the comments

Apache Wicket Web Framework

  1. 1. Apache Wicket Java Web Application Framework St. Louis - Java User’s Group Luther Baker • September 2009
  2. 2. What is Wicket? • Web Application Framework • Component-based Framework • Wicket 1.4 is Java 1.5+ compliant
  3. 3. Where does Wicket fit? User Presentation Tier (Wicket) Shared Business Tier Objects Integration Tier
  4. 4. Request / Response JSP Request / Response home request jsp browser server response
  5. 5. Model 2 (MVC) Struts, Spring MVC, Stripes home jsp request browser server response home controller
  6. 6. Advantages of R/R • Rendering views is generally quite fast • Development can leverage existing tag libraries • Recruiting developers may be easier • Modern implementations have good support for DI and IoC frameworks
  7. 7. Disadvantages of R/R • Controller implementations must explicitly consider multiple concurrent users and threads • Controllers generally work literally in terms of HTTP requests and responses • Controllers often explicitly manage state • Not strictly Object Oriented • The programming model is skewed
  8. 8. The Impedance Mismatch The Programming Model • Programming in Java - do we regularly focus on how the JVM manages object instances and variables? • Generally, website development requires an understanding of the HTTP protocol. IE: manually managing state within and across requests forces front end handlers to be protocol specific.
  9. 9. What if ... ? • What if we considered a page ... a Page? • What if we considered a button ... a Button? • And upon clicking a button, handled an onClick event? • What if web-development resembled Swing or event-driven development? • What kind of framework could possibly enable this?!
  10. 10. Enter ... Wicket • Component-based framework • Instead of creating a controller, servlet or action class ... create a Page • Place components on said Page and define how each component reacts to user input • Build the Page in Java to manage HTML page elements ... not the other way around
  11. 11. The Component Model The Underlying Abstraction • Graphic elements are laid out in HTML while their actual representation, behavior and implementation is defined in Java • A DOM style parent/child approach • An event-driven programming model • You wonder ... “How can such an abstraction sit on top of HTTP?”
  12. 12. Web App Config web.xml <web-app> <context-param> <param-name>configuration</param-name> <param-value>development</param-value> </context-param> <filter> <filter-name>WebApplication</filter-name> <filter-class> org.apache.wicket.protocol.http.WicketFilter </filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>mypackage.HelloWorldApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>WebApplication</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
  13. 13. Wicket Config package mypackage; import org.apache.wicket.protocol.http.WebApplication; public class HelloWorldApplication extends WebApplication { public Class getHomePage() { return HelloWorld.class; } }
  14. 14. General Structure Markup (HTML’s Role) • Layout the element hierarchy • Style the elements Code (Java’s Role) • Mirror and implement markup’s element hierarchy • Event handling Properties Files (~Auxiliary Roles) • Literal strings and i18n
  15. 15. Hello World Markup <html> <body> <span wicket:id="message">Message goes here!</span> </body> </html> Java import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; public class HelloWorld extends WebPage { public HelloWorld() { add(new Label("message", "Hello World!")); } }
  16. 16. Forms (HTML) Markup <html> <body> <span wicket:id="message">Message goes here</span> <form wicket:id="messageInputForm"> <input type="text" wicket:id="messageInput"/> <input type="submit" value="update"/> </form> </body> </html>
  17. 17. Forms (Java) Java public class HelloWorld extends WebPage { public HelloWorld() { IModel messageModel = new Model("Hello World!"); add(new Label("message", messageModel)); add(new MessageForm("messageInputForm", messageModel)); } private final class MessageForm extends Form { public MessageForm(String id, IModel model) { super(id); add(new TextField("messageInput", model)); } protected void onSubmit() { // nothing to do here as the model is automatically updated } } }
  18. 18. Component Family Component Page WebComponent Link Panel WebPage AjaxLink Button Checkbox TextArea Form TextField DropDown Label ...many more
  19. 19. Super Models • Static Model • Dynamic Model • Property Model • Compound Property • Loadable Detached
  20. 20. Basic Models Static Model public class HelloWorld extends WicketExamplePage { public HelloWorld() { add(new Label ("name", new Model(person.getName()))); } } Dynamic Model personForm.add(new RequiredTextField("personName", new IModel<String>() { @Override public String getObject() { return person.getName(); } @Override public void setObject(String value) { person.setName(value); } }));
  21. 21. More Models Property Model public PropertyModel(final Object modelObject, final String expression) class Person class Address { { private Address address; private String zip; public Address getAddress() public String getZip() { { return name; return zip; } } ... ... } } personForm.add(new RequiredTextField("zip", new PropertyModel<Person>(person, "")));
  22. 22. Demonstration WebPage Component • Java • HTML Subclass Master Page child & parent tags Custom Component • Java, HTML • Child components • Panel Superclass • Tags to include Event Handling • Original HTML • Ajax (Debug) • Generated Javascript • Submit handling
  23. 23. Ideally Suited For ... • Highly interactive apps • Help-Desk style ticketing applications and online Registration applications • Apps with lots of Forms and/or UI controls • Apps requiring seamless Ajax behavior • Apps simulating thick clients • Anytime an event programming model better suites the problem domain
  24. 24. Deeper Dive Maven Quickstart Archetype • An easy way to start with a simple, Mavenized, Wicket project Other Topics • More on Models, Sessions and Security • Unit Testing • Custom components • URL mapping, IoC Integration, Persistence ...
  25. 25. Wicket Resources Wicket Links • • • Wicket Books • Wicket in Action (Manning) • Pro Wicket (Apress)