wicket deliver your webapp on time

51

Upload: will-hoover

Post on 25-May-2015

4.357 views

Category:

Business


3 download

TRANSCRIPT

Page 1: Wicket Deliver Your Webapp On Time
Page 2: Wicket Deliver Your Webapp On Time

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

Page 3: Wicket Deliver Your Webapp On Time

3Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

AgendaAgenda

Overview

The Wicket Way (Concepts)

Features

Demo A wicket application A custom component

Q & A

Page 4: Wicket Deliver Your Webapp On Time

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):

Page 5: Wicket Deliver Your Webapp On Time

5Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

OverviewOverview

• Component based Java web framework• rich component suite

• Open source (Apache 2 Licensed)• Wicket makes developing web­apps simple and 

enjoyable again• Flat learning curve• No XML configuration files• Very easy to create and reuse components!• Pure Object Oriented!

Page 6: Wicket Deliver Your Webapp On Time

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

Page 7: Wicket Deliver Your Webapp On Time

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/

Page 8: Wicket Deliver Your Webapp On Time

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

Page 9: Wicket Deliver Your Webapp On Time

9Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

AgendaAgenda

Overview

The Wicket Way (Concepts)

Features

Demo A wicket application A custom component

Q & A

Page 10: Wicket Deliver Your Webapp On Time

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

Page 11: Wicket Deliver Your Webapp On Time

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> 

 

Page 12: Wicket Deliver Your Webapp On Time

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

Page 13: Wicket Deliver Your Webapp On Time

13Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

If you know Java and HTML you already know a lot about Wicket!!

Page 14: Wicket Deliver Your Webapp On Time

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> 

 

Page 15: Wicket Deliver Your Webapp On Time

15Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

Linking Java and HTMLLinking Java and HTML

HTML and Java files resides in the same classpath package

Page 16: Wicket Deliver Your Webapp On Time

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); 

 

Page 17: Wicket Deliver Your Webapp On Time
Page 18: Wicket Deliver Your Webapp On Time

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);     } 

 

Page 19: Wicket Deliver Your Webapp On Time

19Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

Application ClassApplication Class

• The only xml configuration is the web.xml configuration!

<filter>     <filter­name>DemoApplication</filter­name>     <filter­class>org.apache.wicket.protocol.http.WicketFilter</filter­     <init­param>         <param­name>applicationClassName</param­name>         <param­value>com.alphacsp.DemoApplication</param­value>     </init­param>     <init­param>         <param­name>configuration</param­name>         <param­value>development</param­value>         <!­­ <param­value>deployment</param­value> ­­>     </init­param> </filter> 

 

Page 20: Wicket Deliver Your Webapp On Time

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):

Page 21: Wicket Deliver Your Webapp On Time

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", "");     }  } 

 

Page 22: Wicket Deliver Your Webapp On Time

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

Page 23: Wicket Deliver Your Webapp On Time

23Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

Customizing ComponentsCustomizing Components

• Object Oriented Basics – how to extend:• By Inheritance• By Delegation

Page 24: Wicket Deliver Your Webapp On Time

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);     }   }  

 

Page 25: Wicket Deliver Your Webapp On Time

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

Page 26: Wicket Deliver Your Webapp On Time

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> 

 

Page 27: Wicket Deliver Your Webapp On Time

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     } }); 

 

Page 28: Wicket Deliver Your Webapp On Time

28Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

AgendaAgenda

Overview

The Wicket Way (Concepts)

Features

Demo A wicket application A custom component

Q & A

Page 29: Wicket Deliver Your Webapp On Time

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):

Page 30: Wicket Deliver Your Webapp On Time

30Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

Editable tableEditable table

Page 31: Wicket Deliver Your Webapp On Time

31Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

TableTable

Page 32: Wicket Deliver Your Webapp On Time

32Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

Editable Tree TableEditable Tree Table

Page 33: Wicket Deliver Your Webapp On Time

33Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

DatePickerDatePicker

Page 34: Wicket Deliver Your Webapp On Time

34Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

CaptchaCaptcha

Page 35: Wicket Deliver Your Webapp On Time

35Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

Modal WindowModal Window

Page 36: Wicket Deliver Your Webapp On Time

36Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

File UploadFile Upload

Page 37: Wicket Deliver Your Webapp On Time

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)); 

 

Page 38: Wicket Deliver Your Webapp On Time

38Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

Auto Complete ComponentAuto Complete Component

Page 39: Wicket Deliver Your Webapp On Time

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);      } 

 

Page 40: Wicket Deliver Your Webapp On Time

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 

Page 41: Wicket Deliver Your Webapp On Time

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()

Page 42: Wicket Deliver Your Webapp On Time

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);             }         })); 

 

Page 43: Wicket Deliver Your Webapp On Time

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")); 

 

Page 44: Wicket Deliver Your Webapp On Time

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

Page 45: Wicket Deliver Your Webapp On Time

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):

Page 46: Wicket Deliver Your Webapp On Time

46Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

descriptive exceptions!descriptive exceptions!

Page 47: Wicket Deliver Your Webapp On Time

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

Page 48: Wicket Deliver Your Webapp On Time

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 } 

 

Page 49: Wicket Deliver Your Webapp On Time

49Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

LocalizationLocalization

• String Resource Search Order:• Component• Panel (parent)• Page • Application

Page 50: Wicket Deliver Your Webapp On Time

50Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

AgendaAgenda

Overview

The Wicket Way (Concepts)

Features

Demo A wicket application A custom component

Q & A

Page 51: Wicket Deliver Your Webapp On Time

51Copyright AlphaCSP Israel 2007 ­ The JavaEdge Seminar

Q&AQ&A