wicket deliver your webapp on time
TRANSCRIPT
2Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Apache Wicket Apache Wicket Deliver your web Deliver your web
application on timeapplication on timeYoav Hakman
Development Manager & Consultant, AlphaCSP
3Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
AgendaAgenda
Overview
The Wicket Way (Concepts)
Features
Demo A wicket application A custom component
Q & A
4Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
From Roi’s JSF presentation:From Roi’s JSF presentation:
Shortcomings Development
Customizing components is complicated Exceptions are not descriptive No support for annotations
Deployment Unnecessary deployment step Not JEE compliant (packaging, DI)
Components Missing components Limited component functionality (DataGrid)
Security No security model (managed beans, resources)
Ajax
JSF 1.2 (JSR 252):
5Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
OverviewOverview
• Component based Java web framework• rich component suite
• Open source (Apache 2 Licensed)• Wicket makes developing webapps simple and
enjoyable again• Flat learning curve• No XML configuration files• Very easy to create and reuse components!• Pure Object Oriented!
6Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
A little bit of historyA little bit of history
10/2004
0.9 1.0 1.1 1.2 1.3
06/2005
10/2005
05/2006
07/2007
11/2007
7Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Good DocumentationGood Documentation
Wicket wiki:http://cwiki.apache.org/WICKET/
Wicket Examples (Live Demo + sources):http://www.wicketstuff.org/wicket13/
8Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
From Roi’s JSF presentation:From Roi’s JSF presentation:
JSF 2.0 (JSR 314): Purpose
Max. development productivity (IDE) Min. maintenance complexity Integrate with other web tech. More responsive UI (Ajax)
Requirements Ease of development New Features & Fixes Performance & Scalability Technology Adoption
9Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
AgendaAgenda
Overview
The Wicket Way (Concepts)
Features
Demo A wicket application A custom component
Q & A
10Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Wicket TemplatesWicket Templates
• HTML Templates contains • static presentation code (markup)• wicket:id attribute placeholder for wicket
components
• Forces the developer to keep “clean templates”
• The html designer has no knowledge regarding the business domain objects• vs jsf backing bean
11Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
TemplatesTemplatesJSP:
JSF:
WICKET:
<table> <tr> <c:forEach var="item" items="${sessionScope.list}"> <td> <c:out value="item.name" /> </td> </c:forEach> </tr> </table>
<h:dataTable value="#{list}" var="item"> <h:column> <h:outputText value="#{item.name}"/> </h:column> </h:dataTable>
<table> <tr> <td wicket:id=”list”> <span wicket:id=”name”>power point</span> </td> </tr> </table>
12Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Wicket TemplatesWicket Templates
• Most existing frameworks require special HTML code.
• fully compliant with the XHTML standard, so you can use:
• Macromedia Dreamweaver• Microsoft Front Page• Any other HTML editor
13Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
If you know Java and HTML you already know a lot about Wicket!!
14Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Linking Java and HTMLLinking Java and HTML
public class HelloWorld extends WebPage { public HelloWorld() { add(new Label("message", "Hello World!")); } }
Identifier Model
<html> <body> <span wicket:id="message" id="message">to be replaced</span> </body> </html>
15Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Linking Java and HTMLLinking Java and HTML
HTML and Java files resides in the same classpath package
16Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Object OrientedObject Oriented
• Object Oriented• Great for Java developers • Everything is done in Java• Swing like programming …
Form form = new Form("customerform", new CompoundPropertyModel(new Customer())); TextField zipCodeComponent = new TextField("zip"); zipCodeComponent.add(new ZipCodeValidator()); form.add(zipCodeComponent);
18Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Application ClassApplication Class
• Settings– Application Settings– Debug Settings– Exception Settings– Markup Settings– Page Settings– RequestCycle Settings– Security Settings– Session Settings
public class DemoApplication extends WebApplication { @Override public Class getHomePage() { return HomePage.class; } @Override protected void init() { getMarkupSettings().setCompressWhitespace(false); }
19Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Application ClassApplication Class
• The only xml configuration is the web.xml configuration!
<filter> <filtername>DemoApplication</filtername> <filterclass>org.apache.wicket.protocol.http.WicketFilter</filter <initparam> <paramname>applicationClassName</paramname> <paramvalue>com.alphacsp.DemoApplication</paramvalue> </initparam> <initparam> <paramname>configuration</paramname> <paramvalue>development</paramvalue> <! <paramvalue>deployment</paramvalue> > </initparam> </filter>
20Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
From Roi’s JSF presentation:From Roi’s JSF presentation:
Shortcomings Development
Customizing components is complicated Exceptions are not descriptive No support for annotations
Deployment Unnecessary deployment step Not JEE compliant (packaging, DI)
Components Missing components Limited component functionality (DataGrid)
Security No security model (managed beans, resources)
JSF 1.2 (JSR 252):
21Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Customizing ComponentsCustomizing Components
• Object Oriented Basics – how to extend:• By Inheritance• By Delegation
public class PasswordTextField extends TextField { public PasswordTextField(String id) { super(id); } /** * Processes the component tag */ protected final void onComponentTag(final ComponentTag tag) { super.onComponentTag(tag); tag.put("value", ""); } }
22Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Customizing ComponentsCustomizing Components
public class MyComponent extends Component { protected void onAfterRender() { } protected void onBeforeRender() { } protected void onComponentTag(ComponentTag tag) { } protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) { } protected void onModelChanged() { } protected void onRender(MarkupStream markupStream) { } }
Component Hook Methods
23Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Customizing ComponentsCustomizing Components
• Object Oriented Basics – how to extend:• By Inheritance• By Delegation
24Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Customizing ComponentsCustomizing Components
public class SimpleAttributeModifier extends AbstractBehavior { /** * Called any time a component that has this behavior registered is * rendering the component tag. */ public void onComponentTag(final Component component, final ComponentTag tag) { if (isEnabled(component)) { tag.getAttributes().put(attribute, value); } }
25Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Customizing ComponentsCustomizing Components
TextField myText = new TextField("myText", new Model("foo")); myText.add(new SimpleAttributeModifier("class", "green"));
With the following markup: <input type="text" wicket:id="myText"/>
Would be rendered as: <input type=”text” wicket:id=”myText” name=”myText” class=”green” value=”foo”/>
SimpleAttributeModifer
26Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Customizing ComponentsCustomizing Components
item.add(new AbstractBehavior() { /** * Called any time a component that has this behavior registered is * rendering the component tag. */ 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>
27Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Customizing ComponentsCustomizing Components
• Behaviors are used for:• Modifying attributes• Adding Java Script events• Adding Ajax Events
TextField field = new TextField("textfield", inputModel); add(field); field.add(new AjaxFormComponentUpdatingBehavior("onblur") { protected void onUpdate(AjaxRequestTarget target) { // do something here } });
28Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
AgendaAgenda
Overview
The Wicket Way (Concepts)
Features
Demo A wicket application A custom component
Q & A
29Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
From Roi’s JSF presentation:From Roi’s JSF presentation:
Shortcomings Development
Customizing components is complicated Exceptions are not descriptive No support for annotations
Deployment Unnecessary deployment step Not JEE compliant (packaging, DI)
Components Missing components Limited component functionality (DataGrid)
Security No security model (managed beans, resources)
JSF 1.2 (JSR 252):
30Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Editable tableEditable table
31Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
TableTable
32Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Editable Tree TableEditable Tree Table
33Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
DatePickerDatePicker
34Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
CaptchaCaptcha
35Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Modal WindowModal Window
36Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
File UploadFile Upload
37Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Tabbed PanelTabbed Panel
<span wicket:id="tabs" class="tabpanel">[tabbed panel]</span>
List<ITab> tabs = new ArrayList<ITab>(); tabs.add(new AbstractTab(new Model("first tab")) { public Panel getPanel(String panelId) { return new TabPanel1(panelId); } }); tabs.add(new AbstractTab(new Model("second tab")) { public Panel getPanel(String panelId) { return new TabPanel2(panelId); } }); tabs.add(new AbstractTab(new Model("third tab")) { public Panel getPanel(String panelId) { return new TabPanel3(panelId); } }); add(new TabbedPanel("tabs", tabs));
38Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Auto Complete ComponentAuto Complete Component
39Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
ModelsModels
• Holds the values of the components• Mediate between the view and domain
layer
public interface IModel { Object getObject(); void setObject(Object object); }
40Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
ModelsModels
public class HelloWorld extends WebPage { public HelloWorld() { add(new Label("message", "Hello World!")); } }
public class HelloWorld extends WebPage { public HelloWorld() { add(new Label("message", new Model("Hello World!")); } }
The data is constant
41Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
public class HelloWorld extends WebPage { public HelloWorld() { add(new TextField("name", new Model(person.getName())); } }
ModelsModels
• Immutable, not dynamic• Can produce null pointer exceptions!
person.getAddress().getCity()
42Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
ModelsModels
• Dynamic• Inconvenient!
personForm.add(new TextField("personName", new IModel() { public Object getObject() { return person.getName(); } public void setObject(Serializable serializable) { person.setName((String) serializable); } }));
43Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
ModelsModels
• The expression language is more compact than the analogous Java code
• Simpler than to subclass a Model• No null pointer exceptions
– “person.address.city”
new TextField("personName", new PropertyModel(person, "name"));
44Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
ModelsModels
Adds property expressions and MessageFormat substitutions
StringResourceModel
Used for retrieving messages from resource bundles
ResourceModel
Used for large data setsLoadableDetachableModel
Uses component identidiers as property expressions
CompoundPropertyModel
Uses a property expression to dynamically access a property in your domain objects
PropertyModel
Wraps a serializable objectModelDescriptionModel
45Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
From Roi’s JSF presentation:From Roi’s JSF presentation:
Shortcomings Development
Customizing components is complicated Exceptions are not descriptive No support for annotations
Deployment Unnecessary deployment step Not JEE compliant (packaging, DI)
Components Missing components Limited component functionality (DataGrid)
Security No security model (managed beans, resources)
JSF 1.2 (JSR 252):
46Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
descriptive exceptions!descriptive exceptions!
47Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
More FeaturesMore Features
• Ajax Debug Window– Shows the ajax request and response– Shows exceptions
• Integration with other frameworks• Spring• Juice• Seam 2.0• Acegi Security
• Nice and Secure URL’s
48Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
SessionsSessions
• Strongly Typed Sessions
public class MySession extends WebSession { private String myAttribute; private ShoppingCart cart; private UserDetails userDetails; public MySession(WebApplication application) { super(application); } // ... getters and setters }
49Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
LocalizationLocalization
• String Resource Search Order:• Component• Panel (parent)• Page • Application
50Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
AgendaAgenda
Overview
The Wicket Way (Concepts)
Features
Demo A wicket application A custom component
Q & A
51Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
Q&AQ&A