wicket 6 jochen mader
play

Wicket 6 Jochen Mader Chief Developer @ Senacor Technologies AG - PowerPoint PPT Presentation

Wicket 6 Jochen Mader Chief Developer @ Senacor Technologies AG http://www.senacor.com jochen.mader@senacor.com Twitter: @codepitbull ? Quickstart Auf gehts Unmanaged aber nicht einsam Unmanaged aber nicht einsam Managed


  1. Wicket 6

  2. Jochen Mader • Chief Developer @ Senacor Technologies AG • http://www.senacor.com • jochen.mader@senacor.com • Twitter: @codepitbull

  3. ?

  4. Quickstart

  5. Auf geht‘s

  6. Unmanaged aber nicht einsam

  7. Unmanaged aber nicht einsam Managed

  8. Unmanaged aber nicht einsam Wicket Managed Glue Weblayer Weblayer ORM API Management Security ...

  9. Aufbau Servlet 2.5 Container <application>.war WicketFilter WebApplication

  10. public class WicketApplication extends AuthenticatedWebApplication { @Override public HomePage getHomePage () { return HomePage. class; } @Override public void init () { super . init(); getSecuritySettings() . setAuthorizationStrategy( new AnnotationsRoleAuthorizationStrategy (this)); getMarkupSettings() . setAutomaticLinking( true ); mountPage("/dummy", PlainLayoutPage. class); } @Override protected Class<? extends AbstractAuthenticatedWebSession> getWebSessionClass () { return UserAuthenticatedWebSession. class; } @Override protected Class<? extends WebPage> getSignInPageClass () { return SignInWithoutRememberMePage. class; } }

  11. enabling component- oriented, programmatic manipulation of markup* *http://wicket.apache.org/meet/vision.html

  12. Good old Java + HTML

  13. Component Component.java Component.html Component.properties

  14. UserUpdatePanel.java public class UserUpdatePanel extends Panel{ public static final String PASSWORD = "password"; public static final String PASSWORD_REPEAT = "passwordRepeat"; public static final String USER_UPDATE_FORM = "userUpdateForm"; @Autowired private UserRepository userRepository; public UserUpdatePanel ( String id, IModel<User> model) { super(id, model); FormComponent<String> password = new PasswordTextField ( PASSWORD ); FormComponent<String> passwordRepeat = new PasswordTextField ( PASSWORD_REPEAT , Model. of("")); Form<User> userUpdateForm = new Form<User> ( USER_UPDATE_FORM , new CompoundPropertyModel<User> (model)) { @Override protected void onSubmit () { userRepository . save(getModelObject()); } }; add(userUpdateForm .add( new TextField<String> ("name")) .add(password) .add(passwordRepeat) .add( new AjaxFallbackButton ("submit", userUpdateForm) {}) .add( new EqualInputValidator (password, passwordRepeat)) ); } } UserUpdatePanel.html <!DOCTYPE html> < html xmlns:wicket="http://wicket.apache.org"> < head > < meta charset="utf-8"> < title >Wicket Example App</ title > </ head > < body > < wicket:panel > < form wicket:id="userUpdateForm"> < fieldset > < legend >< wicket:message key="userUpdateTitle"/></ legend > < label wicket:for="name">< wicket:message key="username"/></ label > < input type="text" wicket:id="name"/> < label wicket:for="password">< wicket:message key="password"/></ label > < input type="password" wicket:id="password"/> < label wicket:for="passwordRepeat">< wicket:message key="passwordRepeat"/></ label > < input type="password" wicket:id="passwordRepeat"/> < p >< input type="submit" value="submit" wicket:id="submit"/></ p > </ fieldset > </ form > </ wicket:panel > </ body > </ html > UserUpdatePanel.properties userUpdateTitle =Benutzer anpassen username =Benutzername password =Passwort passwordRepeat =Passwort wiederholen

  15. public class UserUpdatePanel extends Panel{ public static final String PASSWORD = "password"; public static final String PASSWORD_REPEAT = "passwordRepeat"; public static final String USER_UPDATE_FORM = "userUpdateForm"; @Autowired private UserRepository userRepository; public UserUpdatePanel ( String id, IModel<User> model) { super(id, model); FormComponent<String> password = new PasswordTextField ( PASSWORD ); FormComponent<String> passwordRepeat = new PasswordTextField ( PASSWORD_REPEAT , Model. of("")); Form<User> userUpdateForm = new Form<User> ( USER_UPDATE_FORM , new CompoundPropertyModel<User> (model)) { @Override protected void onSubmit () { userRepository . save(getModelObject()); } }; add(userUpdateForm .add( new TextField<String> ("name")) .add(password) .add(passwordRepeat) .add( new AjaxFallbackButton ("submit", userUpdateForm) {}) .add( new EqualInputValidator (password, passwordRepeat)) ); } }

  16. <!DOCTYPE html> < html xmlns:wicket="http://wicket.apache.org"> < head > < meta charset="utf-8"> < title >Wicket Example App</ title > </ head > < body > < wicket:panel > < form wicket:id="userUpdateForm"> < fieldset > < legend >< wicket:message key="userUpdateTitle"/></ legend > < input type="text" wicket:id="name"/> < input type="password" wicket:id="password"/> < input type="password" wicket:id="passwordRepeat"/> < p >< input type="submit" value="submit" wicket:id="submit"/></ p > </ fieldset > </ form > </ wicket:panel > </ body > </ html >

  17. wicket:body wicket:message wicket:child wicket:fragment wicket:remove <html xmlns:wicket="http://wicket.apache.org"> wicket:extend wicket:container wicket:head wicket:id wicket:panel wicket:link wicket:border

  18. Keine Logik im Template

  19. Inheritance UserUpdatePanel MyUserUpdatePanel

  20. MyUserUpdatePanel.html <!DOCTYPE html> < html xmlns:wicket="http://wicket.apache.org"> < head > < meta charset="utf-8"> < title >Wicket Example App</ title > </ head > < body > < wicket:panel > < form wicket:id="userUpdateForm"> < fieldset > < legend >< wicket:message key="userUpdateTitle"/></ legend > < input type="text" wicket:id="name"/> < input type="password" wicket:id="password"/> < input type="password" wicket:id="passwordRepeat"/> < p >< input type="submit" value="submit" wicket:id="submit"/></ p > </ fieldset > </ form > </ wicket:panel > </ body > public class MyUserUpdatePanel extends UserUpdatePanel{ </ html > public UserUpdatePanel ( String id, IModel<User> model) { super(id, model); } } MyUserUpdatePanel.properties userUpdateTitle =Lustiges Felderraten

  21. Got my stuff? Markup ... MyUserUpdatePanel UserUpdatePanel Object Properties ... MyUserUpdatePanel UserUpdatePanel Object Application

  22. Datenbeschaffung public UserUpdatePanel ( String id, IModel<User> model) package de.bootcamp.wicket.web.page ; public interface IModel<T> extends IDetachable { T getObject (); void setObject ( final T object); }

  23. public class UserUpdatePanel extends Panel{ ... public UserUpdatePanel ( String id, IModel<User> model) { super(id, model); FormComponent<String> password = new PasswordTextField ( PASSWORD , new PropertyModel<String> (model, "password") ); FormComponent<String> passwordRepeat = new PasswordTextField ( PASSWORD_REPEAT , Model. of("")); Form<User> userUpdateForm = new Form<User> ( USER_UPDATE_FORM , new CompoundPropertyModel<User> (model)) { @Override protected void onSubmit () { userRepository . save(getModelObject()); } }; ... } }

  24. IModel • Entkopplung Beschaffung / Verwendung • Lazy • Chainable • Leicht testbar

  25. Behavior .add( ) Component Behavior • AttributeAppender/AttributeModifier • AjaxSelfUpdatingBehavior

  26. Behavior .add( ) Component Behavior • AttributeAppender/AttributeModifier • AjaxSelfUpdatingBehavior • AjaxEventBehavior • ...

  27. Alles zusammen

  28. Page public class HomePage extends WebPage { private static final long serialVersionUID = 1L; @SpringBean private BusinessService businessService; public HomePage ( final PageParameters parameters) { super(parameters); IModel<User> userModel = new LoadableDetachableModel<User> () { @Override protected User load () { return businessService . findUserByName("user1"); } }; add( new Label ("name", new PropertyModel<String> (userModel,"name"))); add( new MyUserUpdatePanel ("userUpdatePanel", userModel )); add( new AjaxLink ("adminLink") { @Override public void onClick ( AjaxRequestTarget target) { setResponsePage( AdminPage. class); } }); } }

  29. Praxis!!!

  30. AJAX • Seit Wicket 6: JQuery! • Transparente Verwendung • Maßgeblicher Bestandteil des Wicket-Kerns • Einfach über Behaviors erweiterbar • Weiterführung der Komponentisierung

  31. > AJAX NoScript AjaxFallbackButton AjaxFallbackDefaultDataTable AjaxFallbackHeadersToolbar AjaxFallbackLink ...

  32. Kopplung Callbacks Events

Recommend


More recommend