Add a lambda method to StatelessLink
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c96ffc8e Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c96ffc8e Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c96ffc8e Branch: refs/heads/master Commit: c96ffc8e1e2255cef57c2d5e57dac1af0e24f51f Parents: b4caae0 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Mon Jun 20 23:11:26 2016 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Mon Jun 20 23:11:26 2016 +0200 ---------------------------------------------------------------------- .../wicket/markup/html/link/StatelessLink.java | 29 +++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/c96ffc8e/wicket-core/src/main/java/org/apache/wicket/markup/html/link/StatelessLink.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/link/StatelessLink.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/link/StatelessLink.java index c0896ba..ac6d157 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/link/StatelessLink.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/link/StatelessLink.java @@ -17,6 +17,9 @@ package org.apache.wicket.markup.html.link; +import org.apache.wicket.lambda.WicketConsumer; +import org.apache.wicket.util.lang.Args; + /** * This link is stateless that means that the url to this link could generate a new page before the * link onClick is called. Because of this you can't depend on model data in the onClick method. @@ -42,7 +45,6 @@ public abstract class StatelessLink<T> extends Link<T> super(id); } - @Override protected boolean getStatelessHint() { @@ -54,4 +56,29 @@ public abstract class StatelessLink<T> extends Link<T> { return urlForListener(getPage().getPageParameters()); } + + /** + * Creates a {@link Link} based on lambda expressions + * + * @param id + * the id of the link + * @param onClick + * the {@link WicketConsumer} which accepts the {@link Void} + * @return the {@link Link} + */ + public static <T> StatelessLink<T> onClick(String id, WicketConsumer<Link<T>> onClick) + { + Args.notNull(onClick, "onClick"); + + return new StatelessLink<T>(id) + { + private static final long serialVersionUID = 1L; + + @Override + public void onClick() + { + onClick.accept(this); + } + }; + } }
