2. Apache Wicket
Deliver your web
application on time
Yoav Hakman
Development Manager
& Consultant, AlphaCSP
2
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
3. Agenda
Overview
The Wicket Way (Concepts)
Features
Demo
A wicket application
A custom component
Q & A
3
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
4. From Roi’s JSF presentation:
JSF 1.2 (JSR 252):
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
4
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
5. Overview
• 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!
•
5
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
6. A little bit of history
1.2
0.9 1.0 1.1 1.3
10/2004 10/2005 07/2007
06/2005 05/2006 11/2007
6
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
7. Good Documentation
Wicket wiki:
http://cwiki.apache.org/WICKET/
Wicket Examples (Live Demo + sources):
http://www.wicketstuff.org/wicket13/
7
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
8. 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
8
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
9. Agenda
Overview
The Wicket Way (Concepts)
Features
Demo
A wicket application
A custom component
Q & A
9
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
10. Wicket 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
10
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
12. Wicket 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
12
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
14. Linking Java and HTML
public class HelloWorld extends WebPage {
public HelloWorld() {
add(new Label(quot;messagequot;, quot;Hello World!quot;));
}
}
Identifier Model
<html>
<body>
<span wicket:id=quot;messagequot; id=quot;messagequot;>to be replaced</span>
</body>
</html>
14
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
15. Linking Java and HTML
HTML and Java files resides in the same
classpath package
15
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
16. Object Oriented
• Object Oriented
• Great for Java developers
• Everything is done in Java
• Swing like programming …
Form form = new Form(quot;customerformquot;,
new CompoundPropertyModel(new Customer()));
TextField zipCodeComponent = new TextField(quot;zipquot;);
zipCodeComponent.add(new ZipCodeValidator());
form.add(zipCodeComponent);
16
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
17.
18. Application Class
public class DemoApplication extends WebApplication {
@Override public Class getHomePage() {
return HomePage.class;
}
@Override protected void init() {
getMarkupSettings().setCompressWhitespace(false);
}
• Settings
Application Settings
–
Debug Settings
–
Exception Settings
–
Markup Settings
–
Page Settings
–
RequestCycle Settings
–
Security Settings
–
Session Settings
–
18
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
19. Application 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>
19
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
20. From Roi’s JSF presentation:
JSF 1.2 (JSR 252):
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)
20
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
21. Customizing 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(quot;valuequot;, quot;quot;);
}
}
21
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
23. Customizing Components
• Object Oriented Basics – how to extend:
• By Inheritance
• By Delegation
23
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
24. Customizing 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);
}
}
24
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
25. Customizing Components
SimpleAttributeModifer
TextField myText = new TextField(quot;myTextquot;, new Model(quot;fooquot;));
myText.add(new SimpleAttributeModifier(quot;classquot;, quot;greenquot;));
With the following markup:
<input type=quot;textquot; wicket:id=quot;myTextquot;/>
Would be rendered as:
<input type=”text” wicket:id=”myText” name=”myText” class=”green”
value=”foo”/>
25
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
26. Customizing 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) ? quot;evenquot;:quot;oddquot;;
tag.put(quot;classquot;, css);
}
});
Output:
<tr class=“odd”>…</tr>
<tr class=“even”>…</tr>
26
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
27. Customizing Components
• Behaviors are used for:
• Modifying attributes
• Adding Java Script events
• Adding Ajax Events
TextField field = new TextField(quot;textfieldquot;, inputModel);
add(field);
field.add(new AjaxFormComponentUpdatingBehavior(quot;onblurquot;) {
protected void onUpdate(AjaxRequestTarget target) {
// do something here
}
});
27
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
28. Agenda
Overview
The Wicket Way (Concepts)
Features
Demo
A wicket application
A custom component
Q & A
28
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
29. From Roi’s JSF presentation:
JSF 1.2 (JSR 252):
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)
29
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
30. Editable table
30
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
31. Table
31
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
32. Editable Tree Table
32
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
33. DatePicker
33
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
34. Captcha
34
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
35. Modal Window
35
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
36. File Upload
36
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
37. Tabbed Panel
<span wicket:id=quot;tabsquot;
class=quot;tabpanelquot;>[tabbed panel]</span>
List<ITab> tabs = new ArrayList<ITab>();
tabs.add(new AbstractTab(new Model(quot;first tabquot;)) {
public Panel getPanel(String panelId) {
return new TabPanel1(panelId);
}
});
tabs.add(new AbstractTab(new Model(quot;second tabquot;)) {
public Panel getPanel(String panelId) {
return new TabPanel2(panelId);
}
});
tabs.add(new AbstractTab(new Model(quot;third tabquot;)) {
public Panel getPanel(String panelId) {
return new TabPanel3(panelId);
}
});
37
add(new TabbedPanel(quot;tabsquot;, tabs));
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
39. Models
• Holds the values of the components
• Mediate between the view and domain
layer
public interface IModel {
Object getObject();
void setObject(Object object);
}
39
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
40. Models
public class HelloWorld extends WebPage {
public HelloWorld() {
add(new Label(quot;messagequot;, quot;Hello World!quot;));
}
}
public class HelloWorld extends WebPage {
public HelloWorld() {
add(new Label(quot;messagequot;, new Model(quot;Hello World!quot;));
}
}
The data is constant
40
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
41. Models
public class HelloWorld extends WebPage {
public HelloWorld() {
add(new TextField(quot;namequot;, new Model(person.getName()));
}
}
• Immutable, not dynamic
• Can produce null pointer exceptions!
person.getAddress().getCity()
41
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
42. Models
personForm.add(new TextField(quot;personNamequot;, new IModel() {
public Object getObject() {
return person.getName();
}
public void setObject(Serializable serializable) {
person.setName((String) serializable);
}
}));
• Dynamic
• Inconvenient!
42
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
43. Models
new TextField(quot;personNamequot;, new PropertyModel(person, quot;namequot;));
• The expression language is more compact
than the analogous Java code
• Simpler than to subclass a Model
• No null pointer exceptions
– “person.address.city”
43
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
44. Models
Model Description
Model Wraps a serializable object
PropertyModel Uses a property expression to
dynamically access a property in
your domain objects
CompoundPropertyModel Uses component identidiers as
property expressions
LoadableDetachableModel Used for large data sets
ResourceModel Used for retrieving messages from
resource bundles
StringResourceModel Adds property expressions and
MessageFormat substitutions
44
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
45. From Roi’s JSF presentation:
JSF 1.2 (JSR 252):
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)
45
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
47. More 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
47
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
48. Sessions
• 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
}
48
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
50. Agenda
Overview
The Wicket Way (Concepts)
Features
Demo
A wicket application
A custom component
Q & A
50
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar
51. Q&A
51
Copyright AlphaCSP Israel 2007 The JavaEdge Seminar