Professional Documents
Culture Documents
Agenda
What is Wicket
Open Source (Apache Software Foundation) Simple Pure HTML and Pure Java clear separation markup/logic Component based framework Custom components
Spring MVC
Pages are hard to maintain Pages are slow because they need jsp compilation time no more scriptlets and no more jstl which is limited compile time errors reusability easier html templates - no more jsp inclusions ajax
Wicket
Features
Page composition
panels and markup inheritance
Agenda
Wickets concepts
Application
Main entry point for your web application Initialization and Configuration
Defines homepage Output Wicket specific tags?
Factories for
Session
RequestCycle Security
Application
Configured in web.xml:
<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>
Wickets concepts
Session
Session
mysession.setCart(new ShoppingCart());
ShoppingCart cart = mysession.getCart();
cart.add(quantity, selectedProduct);
Wickets concepts
RequestCycle
Responsible for processing requests Cleans up resources at the end Steps in a request cycle:
1.Create request cycle object 2.Decode the request 3. Identify request target (page, component, ) 4. Process event (onClick, onSubmit, ) 5. Respond (page, component, image, pdf, ) 6.Clean up
RequestCycle
Stateless
Not necessarily tied to specific user session Bookmarkable
Wickets concepts
Components
Component
A component is identified in markup with wicket:id Html: <h1 wicket:id=msg>Gets replaced</h1> Java component must have the same wicket:id new Label(msg, Hello, World!); Final (wicket tags can be stripped with one configuration): <h1>Hello, World!</h1>
Put java, markup and supporting files in same package on class path
Wickets concepts
Behaviors
Behaviors are plug-ins for Components They can modify the components markup
item.add(new AbstractBehavior() { public void onComponentTag( Component component, ComponentTag tag) { String css = (((Item)component).getIndex() % 2 == 0) ? "even" : "odd"; tag.put("class", css); } });
Output: <tr class=odd></tr> <tr class=even></tr>
Behaviors
Change attributes of your components markup Add javascript events Add Ajax behavior component.add( new AjaxSelfUpdatingBehavior( Duration.seconds(1)));
Wickets concepts
Models
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));
Agenda
weak
medium
strong
Components
Creating custom component is as easy as typing in extends Extends wicket.Component down the line Available on application classpath
Conclusion
Smart component oriented web framework Easy creation and use of custom components Let's the user concentrate on the business logic Enthustiatic community
http://wicket.apache.org/
Documentation
Wicket in action Martin Dashorst Wicket cookbook Igor Vaynberg Wicket free guide Andrea del Bene http://wicket.apache.org/ https://cwiki.apache.org/confluence/display/WICKE T/How+to+do+things+in+Wicket http://wicketstuff.org/
Appendix examples
Use Wicket version 6.9.1 Create nice URLs by mapping web pages to suggestive paths https://cwiki.apache.org/confluence/display/ WICKET/Request+mapping