Wicket + JEE 6
       Michael Plöd
  Senacor Technologies AG
Agenda

• Brief Wicket Intro
• Standard Wicket - Spring App
• Integrating Wicket and EJB with CDI
• Integrating Wicket and Bean Validation
• Coding Example
Quickstart
mvn archetype:create
 -DarchetypeGroupId=org.apache.wicket
 -DarchetypeArtifactId=
       wicket-archetype-quickstart
 -DarchetypeVersion=1.4.13
 -DgroupId=com.senacor
 -DartifactId=wicket-example
WebApplication.java




                   wicket
HomePage.java         -               HomePage.html
                  example



                     web.xml
web.xml
   configures
Application
<web-app ... >
  <display-name>wicket-example</display-name>

  <filter>
  <filter-name>wicket.wicket-example</filter-name>
     <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
     <init-param>
       <param-name>applicationClassName</param-name>
        <param-value>com.senacor.WicketApplication</param-value>
     </init-param>
  </filter>

   <filter-mapping>
       <filter-name>wicket.wicket-example</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>
</web-app>
Application
   is responsible for
bootstrapping
package com.senacor;

import org.apache.wicket.protocol.http.WebApplication;

public class WicketApplication extends WebApplication
{
  public WicketApplication() {}

    public Class<HomePage> getHomePage()
    {
      return HomePage.class;
    }
}
no additional
configuration
WebApplication.java




                   wicket
HomePage.java         -               HomePage.html
                  example



                     web.xml
WebApplication.java




                   wicket
HomePage.java         -               HomePage.html
                  example



                     web.xml
Page
defines the Java part
HTML
defines the markup part
public class HomePage extends WebPage {
  public HomePage(final PageParameters parameters) {
     add(new Label("message",
              "If you see this message wicket is
               properly configured and running"));
  }
}
<html xmlns:wicket=
   "http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" >
  <head>
     <title>Wicket Quickstart Archetype Homepage</title>
  </head>
  <body>
     <strong>Wicket Quickstart Archetype Homepage</strong>
     <br/><br/>
     <span wicket:id="message">message will be here</span>
  </body>
</html>
<span wicket:id="message">message will be here</span>

add(new Label("message",
           "If you see this message wicket is
            properly configured and running"));
Spring                                        JEE



<span wicket:id="message">message will be here</span>

add(new Label("message",
           "If you see this message wicket is
            properly configured and running"));
Typical          Wicket
Wicket - Spring           @SpringBean
 Application
                   <Service>
                  Spring Bean

                          @Autowired


                  <Repository>
                   Spring Bean
public class HomePage extends WebPage {
  @SpringBean
  private PersonService personService;

    private class PersonListModel
      extends LoadableDetachableModel<List<Person>> {
        @Override
        protected List<Person> load() {
            return personService.listPersons();
        }
    }
    public HomePage(final PageParameters parameters) {
        ...
        final PropertyListView<Person> list =
          new PropertyListView<Person>("persons", new PersonListModel()) {
          ...
            }
        };
...
JSF                    Typical Java EE 6
          @ManagedBean +        Application
          @EJB / Inject

 <Service>
  EJB 3.1

          @Inject / @EJB


  <DAO>
EJB 3.1 / JPA
JSF
Wicket
  Wicket
                                     +
                          ?   Java EE6
 <Service>
  EJB 3.1

         @Inject / @EJB


  <DAO>
EJB 3.1 + JPA
Component wiring with CDI
     Weld / Seam Wicket Module
META-INF/beans.xml
or
WEB-INF/beans.xml
package com.senacor;

import org.apache.wicket.protocol.http.WebApplication;

public class WicketApplication extends WeldApplication
{
  public WicketApplication() {}

    public Class<HomePage> getHomePage()
    {
      return HomePage.class;
    }
}
public class HomePage extends WebPage {
  @Inject
  private PersonService personService;

    private class PersonListModel
      extends LoadableDetachableModel<List<Person>> {
        @Override
        protected List<Person> load() {
            return personService.listPersons();
        }
    }
    public HomePage(final PageParameters parameters) {
        ...
        final PropertyListView<Person> list =
          new PropertyListView<Person>("persons", new PersonListModel()) {
          ...
            }
        };
...
„Programming today is a race
between software engineers striving
to build bigger and better idiot-proof
programs, and the universe trying to
build bigger and better idiots.

So far, the universe is winning.“
-- Robert Cringely --
Model
Validation
  with Wicket
Validate                      Validation
                 Conversion
mandatory                          of




       Back to input           Validation
         screen                    of




                 onSubmit       Update
                EventHandler    model
Validate                      Validation
                 Conversion
mandatory                          of




       Back to input           Validation
         screen                    of




                 onSubmit       Update
                EventHandler    model
form.add(new TextField("firstname").setRequired(true));

form.add(new TextField("email")
              .setRequired(true)
              .add(EmailAddressValidator.getInstance()));

form.add(new TextField("age")
              .add(NumberValidator.minimum(18)));

form.add(new TextField("username")
              .add(StringValidator.lengthBetween(6, 10)));

form.add(new TextField("username")
              .add(new PatternValidator("[a-zA-Z0-9]*"))
              .add(StringValidator.lengthBetween(6, 10)));
No support for
           Model
Bean Validation
    Validation
     in Wicket 1.4
       with Wicket
JSR-303 Wicket Validator

from Zenika
http://code.google.com/p/wicket-jsr303-validators/

http://blog.zenika.com/index.php?post/
2010/02/24/Wicket-JSR-303-Validators
public class Person {
  @NotNull private String firstname;
  @NotNull @EMail private String email;
  ...
}
form.setModel(new CompoundPropertyModel(new Person()));
form.add(new TextField("firstname"));
form.add(new TextField("email"));
form.add(new TextField("age"));
form.add(new TextField("password"));
form.add(new TextField("username"));
form.add(new JSR303FormValidator());
Live Coding
      example
https://github.com/mploed/wicketjee6-example
Further Reading
   Wicket In Action
   Martijn Dashorst, Eelco Hillenius
   Manning



   Wicket
   Roland Förther, Olaf Siefart, Carl-Eric Menzel
   dpunkt Verlag
Thank
     You!
     Michael Plöd
Senacor Technologies AG

Integrating Wicket with Java EE 6

  • 1.
    Wicket + JEE6 Michael Plöd Senacor Technologies AG
  • 2.
    Agenda • Brief WicketIntro • Standard Wicket - Spring App • Integrating Wicket and EJB with CDI • Integrating Wicket and Bean Validation • Coding Example
  • 3.
    Quickstart mvn archetype:create -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId= wicket-archetype-quickstart -DarchetypeVersion=1.4.13 -DgroupId=com.senacor -DartifactId=wicket-example
  • 4.
    WebApplication.java wicket HomePage.java - HomePage.html example web.xml
  • 5.
    web.xml configures Application
  • 6.
    <web-app ... > <display-name>wicket-example</display-name> <filter> <filter-name>wicket.wicket-example</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>com.senacor.WicketApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>wicket.wicket-example</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
  • 7.
    Application is responsible for bootstrapping
  • 8.
    package com.senacor; import org.apache.wicket.protocol.http.WebApplication; publicclass WicketApplication extends WebApplication { public WicketApplication() {} public Class<HomePage> getHomePage() { return HomePage.class; } }
  • 9.
  • 10.
    WebApplication.java wicket HomePage.java - HomePage.html example web.xml
  • 11.
    WebApplication.java wicket HomePage.java - HomePage.html example web.xml
  • 12.
  • 13.
  • 14.
    public class HomePageextends WebPage { public HomePage(final PageParameters parameters) { add(new Label("message", "If you see this message wicket is properly configured and running")); } } <html xmlns:wicket= "http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" > <head> <title>Wicket Quickstart Archetype Homepage</title> </head> <body> <strong>Wicket Quickstart Archetype Homepage</strong> <br/><br/> <span wicket:id="message">message will be here</span> </body> </html>
  • 15.
    <span wicket:id="message">message willbe here</span> add(new Label("message", "If you see this message wicket is properly configured and running"));
  • 16.
    Spring JEE <span wicket:id="message">message will be here</span> add(new Label("message", "If you see this message wicket is properly configured and running"));
  • 17.
    Typical Wicket Wicket - Spring @SpringBean Application <Service> Spring Bean @Autowired <Repository> Spring Bean
  • 18.
    public class HomePageextends WebPage { @SpringBean private PersonService personService; private class PersonListModel extends LoadableDetachableModel<List<Person>> {         @Override         protected List<Person> load() {             return personService.listPersons();         }     } public HomePage(final PageParameters parameters) { ... final PropertyListView<Person> list = new PropertyListView<Person>("persons", new PersonListModel()) {           ...             }         }; ...
  • 19.
    JSF Typical Java EE 6 @ManagedBean + Application @EJB / Inject <Service> EJB 3.1 @Inject / @EJB <DAO> EJB 3.1 / JPA
  • 20.
  • 21.
    Wicket Wicket + ? Java EE6 <Service> EJB 3.1 @Inject / @EJB <DAO> EJB 3.1 + JPA
  • 22.
    Component wiring withCDI Weld / Seam Wicket Module
  • 23.
  • 24.
    package com.senacor; import org.apache.wicket.protocol.http.WebApplication; publicclass WicketApplication extends WeldApplication { public WicketApplication() {} public Class<HomePage> getHomePage() { return HomePage.class; } }
  • 25.
    public class HomePageextends WebPage { @Inject private PersonService personService; private class PersonListModel extends LoadableDetachableModel<List<Person>> {         @Override         protected List<Person> load() {             return personService.listPersons();         }     } public HomePage(final PageParameters parameters) { ... final PropertyListView<Person> list = new PropertyListView<Person>("persons", new PersonListModel()) {           ...             }         }; ...
  • 26.
    „Programming today isa race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning.“ -- Robert Cringely --
  • 27.
  • 28.
    Validate Validation Conversion mandatory of Back to input Validation screen of onSubmit Update EventHandler model
  • 29.
    Validate Validation Conversion mandatory of Back to input Validation screen of onSubmit Update EventHandler model
  • 30.
    form.add(new TextField("firstname").setRequired(true)); form.add(new TextField("email") .setRequired(true) .add(EmailAddressValidator.getInstance())); form.add(new TextField("age") .add(NumberValidator.minimum(18))); form.add(new TextField("username") .add(StringValidator.lengthBetween(6, 10))); form.add(new TextField("username") .add(new PatternValidator("[a-zA-Z0-9]*")) .add(StringValidator.lengthBetween(6, 10)));
  • 31.
    No support for Model Bean Validation Validation in Wicket 1.4 with Wicket
  • 32.
    JSR-303 Wicket Validator fromZenika http://code.google.com/p/wicket-jsr303-validators/ http://blog.zenika.com/index.php?post/ 2010/02/24/Wicket-JSR-303-Validators
  • 33.
    public class Person{ @NotNull private String firstname; @NotNull @EMail private String email; ... } form.setModel(new CompoundPropertyModel(new Person())); form.add(new TextField("firstname")); form.add(new TextField("email")); form.add(new TextField("age")); form.add(new TextField("password")); form.add(new TextField("username")); form.add(new JSR303FormValidator());
  • 34.
    Live Coding example https://github.com/mploed/wicketjee6-example
  • 35.
    Further Reading Wicket In Action Martijn Dashorst, Eelco Hillenius Manning Wicket Roland Förther, Olaf Siefart, Carl-Eric Menzel dpunkt Verlag
  • 36.
    Thank You! Michael Plöd Senacor Technologies AG