friendly-id icon indicating copy to clipboard operation
friendly-id copied to clipboard

Is it supposed to work on JSP pages in Spring Boot?

Open kerdosmedia opened this issue 5 years ago • 2 comments

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?

kerdosmedia avatar Feb 07 '20 22:02 kerdosmedia

Sorry, I'm not using JSP for long time. I don't know if there is a better way :(

mariuszs avatar Sep 02 '20 21:09 mariuszs

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:

spring-mvc-controller

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:

mapstruct-mappers

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.

Screenshot from 2021-12-12 12-51-24

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

mariogarcia avatar Dec 12 '21 11:12 mariogarcia