fix bad returnLink locations when opening multiple version/component/variant forms one after another - fixes #750

Thu, 01 Jan 2026 16:47:11 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 01 Jan 2026 16:47:11 +0100
changeset 405
f3509f24c6c5
parent 404
c7f4a5e81202
child 406
2c0c9a4f81e2

fix bad returnLink locations when opening multiple version/component/variant forms one after another - fixes #750

src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/viewmodel/Components.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/viewmodel/Variants.kt file | annotate | diff | comparison | revisions
src/main/kotlin/de/uapcore/lightpit/viewmodel/Versions.kt file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/component-form.jsp file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/variant-form.jsp file | annotate | diff | comparison | revisions
src/main/webapp/WEB-INF/jsp/version-form.jsp file | annotate | diff | comparison | revisions
--- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt	Thu Jan 01 16:39:09 2026 +0100
+++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt	Thu Jan 01 16:47:11 2026 +0100
@@ -213,8 +213,11 @@
             val version = if (path.versionInfo is OptionalPathInfo.Specific)
                 path.versionInfo.elem else Version(-1, path.project.id)
 
+            val returnLink = http.baseHref + if (http.referer?.endsWith("/versions/") ?: true)
+                "projects/${path.project.node}/versions/" else path.issuesHref
+
             with(http) {
-                view = VersionEditView(path.projectInfo, version)
+                view = VersionEditView(path.projectInfo, version, returnLink)
                 navigationMenu = projectNavMenu(dao.listProjects(), path)
                 styleSheets = listOf("projects")
                 render("version-form")
@@ -335,8 +338,11 @@
             val component = if (path.componentInfo is OptionalPathInfo.Specific)
                 path.componentInfo.elem else Component(-1, path.project.id)
 
+            val returnLink = http.baseHref + if (http.referer?.endsWith("/components/") ?: true)
+                "projects/${path.project.node}/components/" else path.issuesHref
+
             with(http) {
-                view = ComponentEditView(path.projectInfo, component, dao.listUsers())
+                view = ComponentEditView(path.projectInfo, component, dao.listUsers(), returnLink)
                 navigationMenu = projectNavMenu(dao.listProjects(), path)
                 styleSheets = listOf("projects")
                 render("component-form")
@@ -395,8 +401,11 @@
             val variant = if (path.variantInfo is OptionalPathInfo.Specific)
                 path.variantInfo.elem else Variant(-1, path.project.id)
 
+            val returnLink = http.baseHref + if (http.referer?.endsWith("/variants/") ?: true)
+                "projects/${path.project.node}/variants/" else path.issuesHref
+
             with(http) {
-                view = VariantEditView(path.projectInfo, variant)
+                view = VariantEditView(path.projectInfo, variant, returnLink)
                 navigationMenu = projectNavMenu(dao.listProjects(), path)
                 styleSheets = listOf("projects")
                 render("variant-form")
--- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Components.kt	Thu Jan 01 16:39:09 2026 +0100
+++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Components.kt	Thu Jan 01 16:47:11 2026 +0100
@@ -42,5 +42,6 @@
 class ComponentEditView(
     val projectInfo: ProjectInfo,
     val component: Component,
-    val users: List<User>
+    val users: List<User>,
+    val returnLink: String
 ) : EditView()
--- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Variants.kt	Thu Jan 01 16:39:09 2026 +0100
+++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Variants.kt	Thu Jan 01 16:47:11 2026 +0100
@@ -40,5 +40,6 @@
 
 class VariantEditView(
     val projectInfo: ProjectInfo,
-    val variant: Variant
+    val variant: Variant,
+    val returnLink: String
 ) : EditView()
--- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Versions.kt	Thu Jan 01 16:39:09 2026 +0100
+++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Versions.kt	Thu Jan 01 16:47:11 2026 +0100
@@ -70,7 +70,8 @@
 
 class VersionEditView(
     val projectInfo: ProjectInfo,
-    val version: Version
+    val version: Version,
+    val returnLink: String
 ) : EditView() {
     val versionStatus = VersionStatus.entries
 }
--- a/src/main/webapp/WEB-INF/jsp/component-form.jsp	Thu Jan 01 16:39:09 2026 +0100
+++ b/src/main/webapp/WEB-INF/jsp/component-form.jsp	Thu Jan 01 16:47:11 2026 +0100
@@ -31,10 +31,6 @@
 <jsp:useBean id="viewmodel" type="de.uapcore.lightpit.viewmodel.ComponentEditView" scope="request" />
 <c:set var="component" scope="page" value="${viewmodel.component}"/>
 <c:set var="project" scope="page" value="${viewmodel.projectInfo.project}"/>
-<c:set scope="page" var="returnLink" value="${requestScope[Constants.REQ_ATTR_REFERER]}"/>
-<c:if test="${empty returnLink}">
-    <c:set scope="page" var="returnLink" value="./projects/${project.node}/components/"/>
-</c:if>
 
 <form action="./projects/${project.node}/components/-/commit" method="post">
     <table class="formtable" style="width: 70ch">
@@ -98,8 +94,8 @@
         <tr>
             <td colspan="2">
                 <input type="hidden" name="id" value="${component.id}"/>
-                <input type="hidden" name="returnLink" value="${returnLink}"/>
-                <a href="${returnLink}" class="button">
+                <input type="hidden" name="returnLink" value="${viewmodel.returnLink}"/>
+                <a href="${viewmodel.returnLink}" class="button">
                     <fmt:message key="button.cancel"/>
                 </a>
                 <button type="submit"><fmt:message key="button.okay"/></button>
--- a/src/main/webapp/WEB-INF/jsp/variant-form.jsp	Thu Jan 01 16:39:09 2026 +0100
+++ b/src/main/webapp/WEB-INF/jsp/variant-form.jsp	Thu Jan 01 16:47:11 2026 +0100
@@ -31,10 +31,6 @@
 <jsp:useBean id="viewmodel" type="de.uapcore.lightpit.viewmodel.VariantEditView" scope="request" />
 <c:set var="project" scope="page" value="${viewmodel.projectInfo.project}"/>
 <c:set var="variant" scope="page" value="${viewmodel.variant}"/>
-<c:set scope="page" var="returnLink" value="${requestScope[Constants.REQ_ATTR_REFERER]}"/>
-<c:if test="${empty returnLink}">
-    <c:set scope="page" var="returnLink" value="./projects/${project.node}/variants/"/>
-</c:if>
 
 <form action="./projects/${project.node}/variants/-/commit" method="post">
     <table class="formtable" style="width: 70ch">
@@ -85,8 +81,8 @@
         <tr>
             <td colspan="2">
                 <input type="hidden" name="id" value="${variant.id}"/>
-                <input type="hidden" name="returnLink" value="${returnLink}"/>
-                <a href="${returnLink}" class="button">
+                <input type="hidden" name="returnLink" value="${viewmodel.returnLink}"/>
+                <a href="${viewmodel.returnLink}" class="button">
                     <fmt:message key="button.cancel"/>
                 </a>
                 <button type="submit"><fmt:message key="button.okay"/></button>
--- a/src/main/webapp/WEB-INF/jsp/version-form.jsp	Thu Jan 01 16:39:09 2026 +0100
+++ b/src/main/webapp/WEB-INF/jsp/version-form.jsp	Thu Jan 01 16:47:11 2026 +0100
@@ -31,10 +31,6 @@
 <jsp:useBean id="viewmodel" type="de.uapcore.lightpit.viewmodel.VersionEditView" scope="request" />
 <c:set var="version" scope="page" value="${viewmodel.version}"/>
 <c:set var="project" scope="page" value="${viewmodel.projectInfo.project}"/>
-<c:set scope="page" var="returnLink" value="${requestScope[Constants.REQ_ATTR_REFERER]}"/>
-<c:if test="${empty returnLink}">
-    <c:set scope="page" var="returnLink" value="./projects/${project.node}/versions/"/>
-</c:if>
 
 <form action="./projects/${project.node}/versions/-/commit" method="post">
     <table class="formtable" style="width: 35ch">
@@ -93,8 +89,8 @@
         <tr>
             <td colspan="2">
                 <input type="hidden" name="id" value="${version.id}"/>
-                <input type="hidden" name="returnLink" value="${returnLink}"/>
-                <a href="${returnLink}" class="button">
+                <input type="hidden" name="returnLink" value="${viewmodel.returnLink}"/>
+                <a href="${viewmodel.returnLink}" class="button">
                     <fmt:message key="button.cancel"/>
                 </a>
                 <button type="submit"><fmt:message key="button.okay"/></button>

mercurial