Integrating Wicket with Java EE 6

  • 4,346 views
Uploaded on

Apache Wicket is constantly growing in popularity throughout all kinds of projects. However Wicket doesn't come out of the box with a built-in Java EE support. Integration to CDI is missing and the …

Apache Wicket is constantly growing in popularity throughout all kinds of projects. However Wicket doesn't come out of the box with a built-in Java EE support. Integration to CDI is missing and the same is valid for Bean Validation support for example. This session demonstrates how you can user CDI, Conversations and Bean Validation together with Apache Wicket. The first part of the talk will consist of a small slide-driven theoretical part whereas the second part will consist of a coding session that demonstrates hands-on how to hook everything together.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,346
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. Wicket + JEE 6 Michael Plöd Senacor Technologies AG
  • 2. Agenda• Brief Wicket Intro• Standard Wicket - Spring App• Integrating Wicket and EJB with CDI• Integrating Wicket and Bean Validation• Coding Example
  • 3. Quickstartmvn archetype:create -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId= wicket-archetype-quickstart -DarchetypeVersion=1.4.13 -DgroupId=com.senacor -DartifactId=wicket-example
  • 4. WebApplication.java wicketHomePage.java - HomePage.html example web.xml
  • 5. web.xml configuresApplication
  • 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 forbootstrapping
  • 8. package com.senacor;import org.apache.wicket.protocol.http.WebApplication;public class WicketApplication extends WebApplication{ public WicketApplication() {} public Class<HomePage> getHomePage() { return HomePage.class; }}
  • 9. no additionalconfiguration
  • 10. WebApplication.java wicketHomePage.java - HomePage.html example web.xml
  • 11. WebApplication.java wicketHomePage.java - HomePage.html example web.xml
  • 12. Pagedefines the Java part
  • 13. HTMLdefines the markup part
  • 14. 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>
  • 15. <span wicket:id="message">message will be 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 WicketWicket - Spring @SpringBean Application <Service> Spring Bean @Autowired <Repository> Spring Bean
  • 18. 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()) {          ...            }        };...
  • 19. JSF Typical Java EE 6 @ManagedBean + Application @EJB / Inject <Service> EJB 3.1 @Inject / @EJB <DAO>EJB 3.1 / JPA
  • 20. JSF
  • 21. Wicket Wicket + ? Java EE6 <Service> EJB 3.1 @Inject / @EJB <DAO>EJB 3.1 + JPA
  • 22. Component wiring with CDI Weld / Seam Wicket Module
  • 23. META-INF/beans.xmlorWEB-INF/beans.xml
  • 24. package com.senacor;import org.apache.wicket.protocol.http.WebApplication;public class WicketApplication extends WeldApplication{ public WicketApplication() {} public Class<HomePage> getHomePage() { return HomePage.class; }}
  • 25. 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()) {          ...            }        };...
  • 26. „Programming today is a racebetween software engineers strivingto build bigger and better idiot-proofprograms, and the universe trying tobuild bigger and better idiots.So far, the universe is winning.“-- Robert Cringely --
  • 27. ModelValidation with Wicket
  • 28. Validate Validation Conversionmandatory of Back to input Validation screen of onSubmit Update EventHandler model
  • 29. Validate Validation Conversionmandatory 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 ModelBean Validation Validation in Wicket 1.4 with Wicket
  • 32. JSR-303 Wicket Validatorfrom Zenikahttp://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 examplehttps://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ödSenacor Technologies AG