Updated Branches: refs/heads/wicket-1.4.x 2faab9517 -> 87e1b07f2
WICKET-4355 make client-side redirects easier by introducing RedirectException Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/87e1b07f Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/87e1b07f Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/87e1b07f Branch: refs/heads/wicket-1.4.x Commit: 87e1b07f235d7984480737997a009df077021fbc Parents: 2faab95 Author: Peter Ertl <[email protected]> Authored: Tue Jan 24 23:19:16 2012 +0100 Committer: Peter Ertl <[email protected]> Committed: Tue Jan 24 23:19:16 2012 +0100 ---------------------------------------------------------------------- .../java/org/apache/wicket/RedirectException.java | 70 +++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/87e1b07f/wicket/src/main/java/org/apache/wicket/RedirectException.java ---------------------------------------------------------------------- diff --git a/wicket/src/main/java/org/apache/wicket/RedirectException.java b/wicket/src/main/java/org/apache/wicket/RedirectException.java new file mode 100644 index 0000000..4de9b05 --- /dev/null +++ b/wicket/src/main/java/org/apache/wicket/RedirectException.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket; + +/** + * client-Side redirect to wicket page. + * <p/> + * sends http status '302 Moved' with response header 'Location: {my-page-url}' + * to the client to enforce a client-side redirect. The client will request the + * new page with another HTTP GET request and the url in the address bar of + * the browser will be updated. + * + * @author Peter Ertl + */ +public class RedirectException extends RestartResponseException +{ + private static final long serialVersionUID = 1L; + + /** + * redirect to page + * + * @param pageClass + * page class + */ + public RedirectException(Class<? extends Page> pageClass) + { + super(pageClass); + enforceRedirect(); + } + + /** + * redirect to page + * + * @param pageClass + * page class + * @param params + * page parameters + */ + public RedirectException(Class<? extends Page> pageClass, PageParameters params) + { + super(pageClass, params); + enforceRedirect(); + } + + private void enforceRedirect() + { + final RequestCycle cycle = RequestCycle.get(); + + if (cycle == null) + { + throw new IllegalStateException("no current request cycle available"); + } + + cycle.setRedirect(true); + } +}
