friendly-id
friendly-id copied to clipboard
Is it supposed to work on JSP pages in Spring Boot?
I have a spring-boot web application running as a war file on tomcat using JSP's for templates.
If I try to output the UUID in my JSP using something like ${myObject.id} it displays the UUID.
Other things are working properly. If I put the converted UUID in the URL it gets converted. If I use the Spring Form tags using something like <form:input path="id" type="hidden"/> it gets converted to a friendly ID and when posting the form
I created a tag to do the conversion but was wondering if there was a better way?
Sorry, I'm not using JSP for long time. I don't know if there is a better way :(
I've done a proof of concept with friendly-id with spring with both server pages and rest endpoints, and for rendering friendly-ids in my server rendered pages, I had to use DTOs instead of passing directly domain objects. Here's an example, whenever I need to pass model attributes to pages, I'm converting to DTOs:
And in the mappers (I'm using mapstruct), every time there is an UUID to be converted to String, the mappers have to use Friendly-Id to do the conversion:
Controllers are ok when you are expecting UUIDs, and they receive a friendly-id, they do the conversion ok, but, you have to be careful with redirections, then you have to explicitly convert the id to build the url string chain.
In this example the **bookService.createBook(...)" returns an UUID, so I have to convert it explicitly in order to get the expected shorten url.
I hope this helps