1

In javascript I have this variable:

var selectedItemId = null; // the actual value is set from another function

Then I have this function:

function editLink() {
    location.href = /*[[@{/supplycontracts/edit/}]]*/'';
}

Now I want to add the variable to the href, so that in the end it looks like this:

http://localhost:8080/myApp/supplycontracts/edit/?contractId=4

The number '4' at the end is the already substituted selectedItemId.

I tried stuff like this:

location.href = /*[[@{/supplycontracts/edit(${selectedItemId})}]]*/'';

But it didnt work.

If I do this:

location.href = /*[[@{/supplycontracts/edit(selectedItemId)}]]*/'';

I only get

http://localhost:8080/supply-app-0.0.1-SNAPSHOT/supplycontracts/edit?selectedItemId

How do I have to pass the selectedItemId to the href so I get the correct link?

5
  • ''; look strange ! Is it some pragma code? Commented Mar 30, 2018 at 8:34
  • No, it's a thymeleaf featuer I think. The very first code I showed actually works. It sends me to the generic edit page. However I need the parameter so I can edit a specific item. Commented Mar 30, 2018 at 8:35
  • It is all embedded in this: <script type="text/javascript" th:inline="javascript" class="init"> /*<![CDATA[/ ..... /]]>*/ </script> Commented Mar 30, 2018 at 8:37
  • Spring from Java i guest. Is it possible to make it simple like : location.href = /*[[@{/supplycontracts/edit/}]]*/'' + selectedItemId; , take look this qnswer maybe can help you : stackoverflow.com/questions/25687816/… Commented Mar 30, 2018 at 8:44
  • You're right, I use Java, Spring and Thymeleaf. I am trying the stuff from the answer you linked. Your suggestion does not seem to work because the strings at the don't make it into the final link Commented Mar 30, 2018 at 9:13

1 Answer 1

0

For some reason, adding the parameter in the same line, as suggested by Nikola Lukic, did not work for me, although I have seen this notation in other sources as well. What finally worked is this:

function editLink() {
    var baseUrl = /*[[@{/supplycontracts/edit}]]*/'';
    location.href = baseUrl + "?contractId=" + selectedItemId;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.