0

So I'm trying to paginate results where I have a page with a path variable, and the Thymeleaf th:href keeps telling me Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'

So I added an object called "StudySet" to the model in my controller method, like this

modelAndView.addObject("studySet", studySetById);

And then I try to use it in a th:href in my HTML like this

th:href= "@{${studySet.id}/?page=} + ${page}"

But my URL just shows up like this

http://localhost:8080/studySet/$%7BstudySet.id%7D/?page=2

When I want it to look like this

http://localhost:8080/studySet/8/?page=2

8 is the id of the "studySet" object.

So if anyone has any idea on what I'm doing wrong and could let me know, that would be awesome, thanks.

dochsner
  • 249
  • 2
  • 8
  • 25
  • is studySetById is an object of StudySet class or a variable ? – Enigo Feb 09 '16 at 07:31
  • It's a variable, I think, I find the StudySet that I want to pull up using the 'findOne()' method and then I assigned it to 'studySetById' – dochsner Feb 09 '16 at 08:24
  • try to output `${studySet.id}` somewhere on the page, e.g. `` to see if this variable can be resolved. – Enigo Feb 09 '16 at 08:46

1 Answers1

2

ok, I reproduced your problem and here is a solution:

th:href= "@{{studySetid}/?page={page}(studySetid=${studySet.id},page=${page})}"

here is a reference for further reading

Community
  • 1
  • 1
Enigo
  • 3,685
  • 5
  • 29
  • 54
  • I just noticed that with this solution, when I'm on page 2 and go to page 3, I get this url `http://localhost:8080/studySet/8/8/?page=3`, It duplicates the path variable, do you have any idea on how to fix this? – dochsner Feb 09 '16 at 20:31
  • never mind, I fixed it with this `"@{/studySet/{studySetid}/?page={page}(studySetid=${studySet.id},page=${page})}"` – dochsner Feb 09 '16 at 20:48