[ 
https://issues.apache.org/jira/browse/WICKET-4699?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13432731#comment-13432731
 ] 

Bertrand Guay-Paquet commented on WICKET-4699:
----------------------------------------------

I had a look at 0c30132219807d09f962d31381f682dffd1a9dbc and have a 
question/comment: is is really necessary to receive the RequestCycle as a 
parameter? In my own usage of this exception, I found it easier to retrieve the 
request cycle in the constructor itself. I also added another constructor 
accepting a url parameter.

To illustrate, below is the version I use currently. It is missing a 
constructor with a RenderPageRequestHandler.RedirectPolicy parameter however 
because I haven't had any use for it yet.

public class NonResettingRestartException extends ReplaceHandlerException {

        public NonResettingRestartException(Class<? extends Page> pageClass) {
                this(pageClass, null);
        }

        public NonResettingRestartException(Class<? extends Page> pageClass, 
PageParameters params) {
                super(createRequestHandler(pageClass, params), true);
                transferResponseMetaData();
        }

        public NonResettingRestartException(String redirectUrl) {
                super(new RedirectRequestHandler(redirectUrl, 
HttpServletResponse.SC_MOVED_TEMPORARILY),
                                true);
                transferResponseMetaData();
        }

        private void transferResponseMetaData() {
                RequestCycle cycle = RequestCycle.get();
                Response response = cycle.getResponse();
                if (response instanceof IMetaDataBufferingWebResponse) {
                        WebResponse originalResponse = (WebResponse) 
cycle.getOriginalResponse();
                        if (response != originalResponse) {
                                IMetaDataBufferingWebResponse 
bufferingWebResponse = (IMetaDataBufferingWebResponse) response;
                                
bufferingWebResponse.writeMetaData(originalResponse);
                        }
                }
        }

        private static IRequestHandler createRequestHandler(Class<? extends 
Page> pageClass,
                        PageParameters params) {
                return new RenderPageRequestHandler(new PageProvider(pageClass, 
params));
        }
}

p.s. anything in this post can be included as Apache licensed.
                
> Add NonResettingRestartException
> --------------------------------
>
>                 Key: WICKET-4699
>                 URL: https://issues.apache.org/jira/browse/WICKET-4699
>             Project: Wicket
>          Issue Type: New Feature
>          Components: wicket
>    Affects Versions: 6.0.0-beta3
>            Reporter: Bertrand Guay-Paquet
>            Assignee: Martin Grigorov
>            Priority: Minor
>              Labels: exception, response, restart
>             Fix For: 6.0.0
>
>
> In my application, I use a NonResettingRestartException as suggested by 
> Martin Grigorov in the mailing lists. This exception triggers a redirect 
> which restarts the response but does not discard the response's meta data 
> (e.g. cookies). Its implementation and discussion are in WICKET-4637.
> In my opinion, such an "official" version of this exception would be useful 
> in wicket-core since it's not at all trivial to come up with unless much of 
> Wicket internals is known.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to