flowExecutionUrl appending twice while using th:action tag in thymeleaf
-
21-12-2019 - |
Question
I am using thymeleaf with Spring webflow and spring mvc. I am trying to get application url by
flowExecutionUrl
. But when I print flowExecutionUrl
in span I am getting the url that is like
/SWF/loginflow.htm?execution=e2s1
but when I pass the same in th:action
my project name got appended twice. Like this
/SWF/SWF/loginflow.htm?execution=e2s1
below is my code
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring3-3.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div>
<div style="width: 1330px; height: 100px;">
<div id="header" th:include="'/header'::headerfream"></div>
</div>
<div style="width: 1330px; height: 500px; position: absolute; top: 110px;">
<form action = "#" th:action="@{${flowExecutionUrl}}" method="POST">
<div>
<table>
<tr><td><span th:text="${flowExecutionUrl}"></span></td></tr>
<tr>
<td>
<p>User Name</p>
</td>
<td>
<input type="text" name="name" id="name" />
</td>
</tr>
<tr>
<td>
<p>Password</p>
</td>
<td>
<input type="password" name="password" id ="password" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit"/>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
</html>
Solution 2
Thank you Tom for your answer . I found the solution
<form id="myForm" th:action="${flowExecutionUrl}"
th:object="${userDetail}" method="post">
<input type="hidden" name="_eventId" value="loginCredentialsEntered" />
And my action will be
/SWF/loginflow.htm?execution=e3s2_eventId=loginCredentialsEntered
OTHER TIPS
Theth:action
uses the @{...}
syntax, which rewrites the URL. Since the flowExecutionUrl
starts with a /
, the URL is rewritten relative to the context root of your application. The context path /SWF
is prepended to the URL.
The span does not use this @
syntax and thus just writes the original value of flowExecutionUrl
.
You should remove the context path from the flowExecutionUrl
and let Thymeleaf prepend the context path using the @
syntax, so your application is not dependent on the context path.
Source: Thymeleaf Standard URL syntax
Found this answer here:
It works with webflow and thymeleaf very well.
Use server-relative URLs as explained here: http://www.thymeleaf.org/doc/html/Using-Thymeleaf.html#link-urls
This would look like:
th:href="@{'~' + ${flowExecutionUrl}}"