Updated Branches: refs/heads/master f39d8fafc -> 1945ffd8d
Add 'change' Ajax link next to the captcha image to show how to refresh/change it. (cherry picked from commit e594bb85675eab0a3dfd7fdec738fada07b9607b) Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/1945ffd8 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/1945ffd8 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/1945ffd8 Branch: refs/heads/master Commit: 1945ffd8d4446cd88da82ed65a67e67a457dbd7d Parents: f39d8fa Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Mon Dec 16 11:49:35 2013 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Mon Dec 16 11:50:40 2013 +0200 ---------------------------------------------------------------------- .../apache/wicket/examples/captcha/Captcha.html | 3 +- .../apache/wicket/examples/captcha/Captcha.java | 41 +++++++++++++------- 2 files changed, 29 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/1945ffd8/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.html ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.html b/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.html index ae26525..057b990 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.html +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.html @@ -12,11 +12,12 @@ <form wicket:id="captchaForm"> <p> <img wicket:id="captchaImage" /> + <a wicket:id="changeCaptcha">change</a> </p> <p> Please replicate the text you see above <br /> - <input wicket:id="password" id="password" type="text" size="40" /> + <input wicket:id="captchaText" type="text" size="40" /> <input type="submit" value="submit" /> </p> </form> http://git-wip-us.apache.org/repos/asf/wicket/blob/1945ffd8/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.java ---------------------------------------------------------------------- diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.java b/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.java index 1b8e044..d1217ac 100644 --- a/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.java +++ b/wicket-examples/src/main/java/org/apache/wicket/examples/captcha/Captcha.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.examples.captcha; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.examples.WicketExamplePage; import org.apache.wicket.extensions.markup.html.captcha.CaptchaImageResource; import org.apache.wicket.markup.ComponentTag; @@ -24,7 +26,6 @@ import org.apache.wicket.markup.html.form.RequiredTextField; import org.apache.wicket.markup.html.image.Image; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.model.PropertyModel; -import org.apache.wicket.request.mapper.parameter.PageParameters; import org.apache.wicket.util.value.ValueMap; @@ -51,9 +52,23 @@ public class Captcha extends WicketExamplePage super(id); captchaImageResource = new CaptchaImageResource(imagePass); - add(new Image("captchaImage", captchaImageResource)); - add(new RequiredTextField<String>("password", new PropertyModel<String>(properties, - "password")) + final Image captchaImage = new Image("captchaImage", captchaImageResource); + captchaImage.setOutputMarkupId(true); + add(captchaImage); + + AjaxLink<Void> changeCaptchaLink = new AjaxLink<Void>("changeCaptcha") + { + @Override + public void onClick(AjaxRequestTarget target) + { + captchaImageResource.invalidate(); + target.add(captchaImage); + } + }; + add(changeCaptchaLink); + + add(new RequiredTextField<String>("captchaText", new PropertyModel<String>(properties, + "captchaText"), String.class) { @Override protected final void onComponentTag(final ComponentTag tag) @@ -71,10 +86,10 @@ public class Captcha extends WicketExamplePage @Override public void onSubmit() { - if (!imagePass.equals(getPassword())) + if (!imagePass.equals(getCaptchaText())) { - error("Captcha password '" + getPassword() + "' is wrong.\n" + - "Correct password was: " + imagePass); + error("Captcha text '" + getCaptchaText() + "' is wrong.\n" + + "Correct text was: " + imagePass); } else { @@ -108,19 +123,17 @@ public class Captcha extends WicketExamplePage private final ValueMap properties = new ValueMap(); /** - * Construct. - * - * @param parameters + * Constructor. */ - public Captcha(final PageParameters parameters) + public Captcha() { final FeedbackPanel feedback = new FeedbackPanel("feedback"); add(feedback); add(new CaptchaForm<>("captchaForm")); } - private String getPassword() + private String getCaptchaText() { - return properties.getString("password"); + return properties.getString("captchaText"); } -} \ No newline at end of file +}
