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?

hooch
  • 1,135
  • 1
  • 16
  • 31
  • ''; look strange ! Is it some pragma code? – Nikola Lukic Mar 30 '18 at 08: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. – hooch Mar 30 '18 at 08:35
  • It is all embedded in this: – hooch Mar 30 '18 at 08: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 : https://stackoverflow.com/questions/25687816/setting-up-a-javascript-variable-from-spring-model-by-using-thymeleaf – Nikola Lukic Mar 30 '18 at 08: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 – hooch Mar 30 '18 at 09:13

1 Answers1

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;
}
hooch
  • 1,135
  • 1
  • 16
  • 31