Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Michael Plöd on Advanced Wicket

Michael Plöd on Advanced Wicket

More Decks by Enterprise Java User Group Austria

Other Decks in Technology

Transcript

  1. BookmarkablePageLink BookmarkablePageLink link1 = new BookmarkablePageLink("link1", Link1Page.class); link1.add(new Label("label1", model1));

    add(link1); PageParameters params = new PageParameters(); pageParameters2.add("key", "value"); BookmarkablePageLink link2 = new BookmarkablePageLink("link2", Link2Page.class, params); link2.add(new Label("label2", model2)); add(link2);
  2. URL Strategie /profile?username=mploed QueryStringUrlEncodingStrategy /profile/username/mploed BookmarkablePageRequestTarget UrlCodingStrategy /profile/mploed IndexedParamUrlCodingStrategy /profile/mploed/?tags=kanada

    MixedParamUrlCodingStrategy /profile/name/mploed HybridUrlCodingStrategy mount(new MixedParamUrlCodingStrategy("profile", UserProfilePage.class, new String[] { "username" }));
  3. Link Link link3 = new Link("link3") { @Override ! public

    void onClick() { ! ! setResponsePage(Link3Page.class); ! } }; Link link4 = new Link("link4") { @Override ! public void onClick() { ! ! setResponsePage(Link4Page.class, pageParameters4); ! } };
  4. Crypted Urls @Override protected IRequestCycleProcessor newRequestCycleProcessor() { return new WebRequestCycleProcessor()

    { ! ! @Override ! ! protected IRequestCodingStrategy newRequestCodingStrategy() { ! ! ! return new CryptedUrlWebRequestCodingStrategy( new WebRequestCodingStrategy()); ! } ! }; }
  5. class PersonLoadableDetachableModel extends LoadableDetachableModel<Person> { ! private final long id;

    ! ! public PersonLoadableDetachableModel(long id) { ! ! this.id = id; ! ! } ! ! @Override ! ! protected Person load() { ! ! ! return userService.retrieve(id); ! ! } } IModel<Person> personModel = new CompoundPropertyModel<Person>( new PersonLoadableDetachableModel(personId)); Model Chaining
  6. public class AllschoolsWicketApplication extends WicketApplication { @Override protected void init()

    { super.init(); ... getSecuritySettings().setAuthorizationStrategy( new AllschoolsAuthorizationStrategy()); getSecuritySettings() .setUnauthorizedComponentInstantiationListener( new AllschoolsAuthorizationStrategy()); } Security by hand
  7. public class AllschoolsAuthorizationStrategy implements IAuthorizationStrategy, IUnauthorizedComponentInstantiationListener { public boolean isActionAuthorized(Component

    component, Action action) { if (action.equals(Component.RENDER)) { Class<? extends Component> c = component.getClass(); AdminOnly adminOnly = c.getAnnotation(AdminOnly.class); if (adminOnly != null) { Author user = AllschoolsSession.get().getAuthor(); return user != null; } } return true; } Security by hand
  8. ... @SuppressWarnings("unchecked") public boolean isInstantiationAuthorized(Class componentClass) { if (ProtectedPage.class.isAssignableFrom(componentClass)) {

    ... } } public void onUnauthorizedInstantiation(Component component) { if (AllschoolsSession.get().isAuthenticatedAsAuthor()) { throw new RestartResponseAtInterceptPageException (UnauthorizedAccessPage.class); } else { throw new RestartResponseAtInterceptPageException (SignInPage.class); } } Security by hand
  9. public class HomePage extends WebPage { public HomePage(final PageParameters parameters)

    { add(JavascriptPackageResource .getHeaderContribution(HomePage.class, "myscript.js")); add(CSSPackageResource .getHeaderContribution(HomePage.class, "mystyle.css")); ... } } <wicket:head> <wicket:link> <link href= "mystyle.css" rel="stylesheet" type="text/css"/> ... </wicket:link> </wicket:head>
  10. Further Reading Wicket In Action Martijn Dashorst, Eelco Hillenius Manning

    Wicket Roland Förther, Olaf Siefart, Carl-Eric Menzel dpunkt Verlag