Ajax Re-render does not work after AbstractRestartResponseException()
---------------------------------------------------------------------

                 Key: WICKET-1450
                 URL: https://issues.apache.org/jira/browse/WICKET-1450
             Project: Wicket
          Issue Type: Bug
          Components: wicket
    Affects Versions: 1.3.2
         Environment: Windows XP Java 1.6.0_05-b13
            Reporter: Matthew Young


To handle possible exception in Model#getObject(): I do

1) make note of exception has occurred (and subsequently only return some error 
value and not cause exception thrown again),
2) register an error feedback message,
3) calll page.detach()  (for clean up and reset?, I'm not sure but I know this 
makes FeedbackPanelErrorMessage reload message from session) and
4) throw new AbstractRestartResponseException() to re-render response with the 
new error message from the model shown.

I'm finding that this works perfectly in non-Ajax.  But in Ajax, there are 2 
problems:

1) the error message register in step 2) above is not rendered in the 
FeedbackPanel
2) the Ajax response is incomplete, it's missing the label component in my test 
case and missing the </ajax-response> closing tag.


Test case below:  if you enter "blowup" in the text field, the label's model 
will do the steps outline above.  Run this in non-Ajax and you will see two 
error messages as expected.  Run in Ajax, you will see the problem (open Wicket 
Ajax Debug panel to see).


= = = =     HomePage.html:

<html>
<head></head>
    <span wicket:id="message">message will be here</span>
    <form wicket:id="form">
        <input type="text" wicket:id="word"/>
        <input type="submit" value="Enter" wicket:id="submitButton"/>
    </form>
    <span wicket:id="feedback">FEEDBACK</span>
</html>


= = = = =  HomePage.java:


public class HomePage extends WebPage {

        private static final long serialVersionUID = 1L;

        private String word;
        
    public HomePage(final PageParameters parameters) {

        add(new FeedbackPanel("feedback") {
                private static final long serialVersionUID = 1L;
                @Override protected void onBeforeRender() {
                        System.out.println("= = = = FeedbackPanel 
onBeforeRender()");
                        System.out.println("         FeedbackbackMessageModel = 
" + getFeedbackMessagesModel().getObject());
                        super.onBeforeRender();
                }
        }.setOutputMarkupPlaceholderTag(true));
        // if the word "blowup" is entered,
        //this register a error message and throw 
        IModel model = new Model() {
                private static final long serialVersionUID = 1L;
                        @Override public Object getObject() {
                                if (word != null && word.equals("blowup")) {
                                        word = "-w-e-b-l-e-w-u-p-";
                                        HomePage.this.fatal("[2/2]This message 
is from Model.");
                                        getPage().detach();
                                        System.out.println("! ! ! ! ! throwing  
new AbstractRestartResponseException()");
                                        throw new 
AbstractRestartResponseException() {
                                                private static final long 
serialVersionUID = 1L;
                                        };
                                } else {
                                        return "The word is: \"" + (word == 
null ? " n u l l " : word) + "\"";
                                }
                        }
        };
        add(new Label("message", model) {
                private static final long serialVersionUID = 1L;
                @Override protected void onBeforeRender() {
                        System.out.println("= = = = Label onBeforeRender(), 
model = " + getModel().getObject());
                        super.onBeforeRender();
                }
        }.setOutputMarkupId(true));
        Form form = new Form("form", new CompoundPropertyModel(this));
        add(form);
        form.add(new TextField("word").setRequired(true));
        AjaxFallbackButton submitButton = new 
AjaxFallbackButton("submitButton", form) {
                private static final long serialVersionUID = 1L;
                @Override protected void onSubmit(AjaxRequestTarget target, 
Form f) {
                        if (word != null && word.equals("blowup")) {
                                HomePage.this.error("[1/2]This message is from 
onSubmit. There should also be a message from model");
                        }
                if (target != null) {
                        target.addComponent(HomePage.this.get("feedback"));     
        // clear error feedback if any
                        target.addComponent(HomePage.this.get("message"));
                }
                }
                
                @Override protected void onError(AjaxRequestTarget target, Form 
f) {
                        target.addComponent(HomePage.this.get("feedback"));     
        // show updated error feedback
                }
        };
        form.add(submitButton);
    }
}



= = = = =  WicketApplication.java:

public class WicketApplication extends WebApplication
{    
        public WicketApplication() {
        }
        
        public Class<? extends WebPage> getHomePage() {
                return HomePage.class;
        }
        
        
        @Override public RequestCycle newRequestCycle(Request request, Response 
response) {
                return new WebRequestCycle(this, (WebRequest) request, 
(WebResponse) response) {
                        @Override public Page onRuntimeException(Page page, 
RuntimeException e) {
                                // page can be null
                                if (page == null) {
                                        return super.onRuntimeException(page, 
e);
                                }
                                return page;
                        }
                };
        }

}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to