From: krulls Date: Mon, 23 Feb 2015 17:24:45 +0000 (+0100) Subject: issue 564: enable ticket page update on tomcat with redirects X-Git-Tag: v1.7.0~10^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F245%2Fhead;p=gitblit.git issue 564: enable ticket page update on tomcat with redirects issue 564: fix imports issue 564 --- diff --git a/src/main/java/com/gitblit/wicket/pages/TicketPage.java b/src/main/java/com/gitblit/wicket/pages/TicketPage.java index b690e4c0..19788f27 100644 --- a/src/main/java/com/gitblit/wicket/pages/TicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/TicketPage.java @@ -378,7 +378,7 @@ public class TicketPage extends RepositoryPage { } TicketModel update = app().tickets().updateTicket(repository, ticket.number, change); app().tickets().createNotifier().sendMailing(update); - setResponsePage(TicketsPage.class, getPageParameters()); + redirectTo(TicketsPage.class, getPageParameters()); } }; String css = TicketsUI.getStatusClass(item.getModel().getObject()); @@ -442,7 +442,7 @@ public class TicketPage extends RepositoryPage { } TicketModel update = app().tickets().updateTicket(repository, ticket.number, change); app().tickets().createNotifier().sendMailing(update); - setResponsePage(TicketsPage.class, getPageParameters()); + redirectTo(TicketsPage.class, getPageParameters()); } }; item.add(link); @@ -487,7 +487,7 @@ public class TicketPage extends RepositoryPage { } TicketModel update = app().tickets().updateTicket(repository, ticket.number, change); app().tickets().createNotifier().sendMailing(update); - setResponsePage(TicketsPage.class, getPageParameters()); + redirectTo(TicketsPage.class, getPageParameters()); } }; item.add(link); @@ -560,7 +560,7 @@ public class TicketPage extends RepositoryPage { change.vote(user.username); } app().tickets().updateTicket(repository, ticket.number, change); - setResponsePage(TicketsPage.class, getPageParameters()); + redirectTo(TicketsPage.class, getPageParameters()); } }; add(link); @@ -600,7 +600,7 @@ public class TicketPage extends RepositoryPage { change.watch(user.username); } app().tickets().updateTicket(repository, ticket.number, change); - setResponsePage(TicketsPage.class, getPageParameters()); + redirectTo(TicketsPage.class, getPageParameters()); } }; add(link); @@ -1297,7 +1297,7 @@ public class TicketPage extends RepositoryPage { } TicketModel updatedTicket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change); app().tickets().createNotifier().sendMailing(updatedTicket); - setResponsePage(TicketsPage.class, getPageParameters()); + redirectTo(TicketsPage.class, getPageParameters()); } protected X setNewTarget(X x) { @@ -1408,8 +1408,8 @@ public class TicketPage extends RepositoryPage { GitBlitWebSession.get().cacheErrorMessage(msg); logger.error(msg); } - - setResponsePage(TicketsPage.class, getPageParameters()); + + redirectTo(TicketsPage.class, getPageParameters()); } }; mergePanel.add(mergeButton); diff --git a/src/main/java/com/gitblit/wicket/panels/CommentPanel.java b/src/main/java/com/gitblit/wicket/panels/CommentPanel.java index acf4dd9a..2bc08899 100644 --- a/src/main/java/com/gitblit/wicket/panels/CommentPanel.java +++ b/src/main/java/com/gitblit/wicket/panels/CommentPanel.java @@ -15,12 +15,15 @@ */ package com.gitblit.wicket.panels; +import org.apache.wicket.PageParameters; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.model.IModel; import org.apache.wicket.model.Model; +import org.apache.wicket.protocol.http.RequestUtils; +import org.apache.wicket.request.target.basic.RedirectRequestTarget; import com.gitblit.models.RepositoryModel; import com.gitblit.models.TicketModel; @@ -79,7 +82,7 @@ public class CommentPanel extends BasePanel { TicketModel updatedTicket = app().tickets().updateTicket(repository, ticket.number, newComment); if (updatedTicket != null) { app().tickets().createNotifier().sendMailing(updatedTicket); - setResponsePage(pageClass, WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number)); + redirectTo(pageClass, WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number)); } else { error("Failed to add comment!"); } @@ -87,6 +90,24 @@ public class CommentPanel extends BasePanel { // TODO update comment } } + + /** + * Steal from BasePage to realize redirection. + * + * @see BasePage + * @author krulls@GitHub; ECG Leipzig GmbH, Germany, 2015 + * + * @param pageClass + * @param parameters + * @return + */ + private void redirectTo(Class pageClass, PageParameters parameters) + { + String relativeUrl = urlFor(pageClass, parameters).toString(); + String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl); + getRequestCycle().setRequestTarget(new RedirectRequestTarget(canonicalUrl)); + } + }.setVisible(ticket != null && ticket.number > 0)); final IModel markdownPreviewModel = Model.of();