I had the same problem with generating statistics.
If your're extending the wicket Image class, you should override
getImageResource.
Simply add this method in getImageResource:
@Override
protected void setHeaders(WebResponse response) {
if (isCacheable()) {
super.setHeaders(response);
} else {
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
}
}
And you're done.
Good luck.
On Fri, Oct 2, 2009 at 12:51 PM, RG <[email protected]> wrote:
> Hi,
>
> I'm trying to create a form with captcha for a demo I was building, but am
> having problems with the update when the password is incorrect. What I
> wanted to achieve was the captcha being
> regenerated with a new word on each try. On submit I can see the captcha
> being regenerated, but it does not update (the feedback form is.), if I do
> a 'view image' in
> firefox I see the updated image.
>
> I think this is because the image is being cached by firefox, but am not
> certain.
>
> I'm probably missing something stupid, but for the life of me can't work it
> out. Any help greatly appreciated.
>
> Thanks
>
> Rory
>
> ---------------------------------------------------------------
>
> package org.sourceforge.jemm.jemmblog.pages.blog;
>
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import org.apache.wicket.ajax.markup.html.form.AjaxButton;
> import org.apache.wicket.markup.ComponentTag;
> import org.apache.wicket.markup.html.form.Form;
> import org.apache.wicket.markup.html.form.RequiredTextField;
> import org.apache.wicket.markup.html.form.TextArea;
> import org.apache.wicket.markup.html.image.Image;
> import org.apache.wicket.markup.html.panel.FeedbackPanel;
> import org.apache.wicket.model.CompoundPropertyModel;
> import org.apache.wicket.model.PropertyModel;
> import org.apache.wicket.util.value.ValueMap;
> import org.sourceforge.jemm.jemmblog.domain.Blog;
> import org.sourceforge.jemm.jemmblog.domain.DuplicateUserException;
> import org.sourceforge.jemm.jemmblog.domain.dto.BlogDTO;
> import org.sourceforge.jemm.jemmblog.pages.BasePage;
> import org.sourceforge.jemm.jemmblog.util.CaptchaHelper;
>
> /**
> * Form for creating blog with captcha.
> *
> * n.b. captchaHelper.refreshCaptcha() creates a new CaptchaImageResource
> with a different
> * password on each invocation.
> */
> public class CreateBlogPage extends BasePage {
>
> private final FeedbackPanel feedbackPanel;
> private final ValueMap properties = new ValueMap();
>
> private final CaptchaHelper captchaHelper = new CaptchaHelper();
> private final Image captchaImage;
> public CreateBlogPage() {
> ;
> Form<BlogDTO> form = new Form<BlogDTO>("form");
> form.setModel(new CompoundPropertyModel<BlogDTO>(new BlogDTO()));
>
> form.add(new TextArea<String>("blogName").setRequired(true));
> form.add(new TextArea<String>("username").setRequired(true));
> form.add(new TextArea<String>("password").setRequired(true));
>
>
> //*****************************************************************************************
> // create teh captcha components captchaImage = new
> Image("captchaImage", captchaHelper.refreshCaptcha());
> captchaImage.setOutputMarkupId(true);
> form.add(captchaImage);
> form.add(new RequiredTextField<String>("captchaField", new
> PropertyModel<String>(properties, "captchaField")) {
> private static final long serialVersionUID = 1L;
>
> @Override
> protected void onComponentTag(final ComponentTag tag) {
> super.onComponentTag(tag);
> //
> **************************************************************************************
> // this does not work either...
>
> // clear the field after each render
> tag.put("value", "");
> }
> });
>
>
>
> add(form);
>
> AjaxButton ajaxBtn = new AjaxButton("ajaxButton") {
> private static final long serialVersionUID = 1L;
>
> @Override
> protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
> super.onSubmit();
> if (!captchaHelper.captchaMatches(getPassword())) {
> error("Captcha value incorrect.");
> } else {
> BlogDTO blogDTO = (BlogDTO) form.getModelObject();
> try {
> Blog blog = getManager().createBlog(blogDTO);
> setResponsePage(new BlogOverviewPage(blog));
> }catch(DuplicateUserException due) {
> error("Blog user " + blogDTO.getUsername() + " already
> exists");
> }
> }
>
>
> //***************************************************************************************
> // update the captcha image, add it to the ajax response
> captchaImage.setImageResource(captchaHelper.refreshCaptcha());
> target.addComponent(captchaImage,"captchaImage");
> }
>
> @Override
> protected void onError(AjaxRequestTarget target, Form<?> form) {
> target.addComponent(feedbackPanel);
> }
> };
> form.add(ajaxBtn);
> feedbackPanel = new FeedbackPanel("feedback");
> // need to set output markupid to true
> feedbackPanel.setOutputMarkupId(true);
> add(feedbackPanel);
> }
>
> private String getPassword() {
> return properties.getString("captchaField");
> }
>
> /** Utility method used for testing */
> public String getCaptchaChallenge() {
> return captchaHelper.getCPassword();
> }
> }
> ---------------------------------------------------------------------------------------------------------------
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title>Create Blog</title>
>
> </head>
>
> <body>
> <wicket:extend>
> <div wicket:id="feedback">
> </div>
>
> <form wicket:id="form">
> <p>
> Blog Name:
> <br />
> <input type="text" wicket:id="blogName" />
> </p>
> <p>
> Username:
> <br />
> <input type="text" wicket:id="username" />
> </p>
> <p>
> Password:
> <br />
> <input type="text" wicket:id="password" />
> </p>
> <p><img wicket:id="captchaImage" /></p>
> <p> Please replicate the text you see above
> <br/>
> <input wicket:id="captchaField" id="captchaField" type="text"
> size="40" />
> <p>
> <input type="submit" wicket:id="ajaxButton" value="Create
> blog" />
> </p>
> </form>
> </wicket:extend>
> </body>
> </html>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]