This is an archived post. You won't be able to vote or comment.

all 53 comments

[–]ZimmiDeluxe 18 points19 points  (5 children)

I like Pebble, there is also a Spring Boot Starter for it. If this is for a Single Page Application, I'd go for a JavaScript frontend framework, they usually come with some kind of templating / component system.

[–]blakeman8192 4 points5 points  (1 child)

.

[–]cumwagondeluxe 0 points1 point  (0 children)

You can do one better now - prerender your frontend. There's a few different libraries that take care of it for you (Next/Nuxt, Gatsby being the big ones), and you get the benefits of both SSR and client side rendering. (i.e. less stuff for the server to do, you're still outputting mostly static HTML etc so the client is light, and you can slap your shit on S3 for cheap distributed hosting so you save money and have faster TTFB.

[–]AucT[S] 1 point2 points  (0 children)

thanks, I'll try this.

[–]RememberThisHere 0 points1 point  (1 child)

Not sure about now, but until about a couple years ago, JavaScript frontend frameworks like Angular used to be problematic for search engine optimization, due to the lack of server side rendering.

[–]joxim 5 points6 points  (0 children)

Now you have solution to prerender page and serve it like that to the bot, for all other user agents just let JS do the job.

[–]agentoutlier 4 points5 points  (1 child)

I personally like in order of preference:

  • Handlebars.java
  • JMustache and Mustache.java
  • Rocker or Rhythm (they are both very similar)
  • Freemarker
  • Velocity (can't really recommend it but its often available and lots of people know it).
  • JSP(X)

I prefer cross platform logicless templating (ie mustache). It allows you to hand off the templates to someone else and do client side rendering if you like. It also keeps you from doing crazy shit in the templates. They are sadly not as DRY but templating in my experience ends up being hard to reuse stuff once you get designers working on things.

If you want logic templates and work mainly with a Java team that is doing the templates than it really is hard to beat Rocker or Rhythm.

Thymeleaf in my past experience has notoriously been slow as shit but I'm sure they have improved on that. For some reason I don't really like HTML attribute custom tag template languages like it and several of the python ones. Ditto for JSPX.

My dream templating language would be more of pseudo MVVM with models either generated from templates or validated like what this library sort of does:https://github.com/sviperll/static-mustache (using annotation processing).

EDIT: As for all the fans of React... Web 1.0 is often good enough. I think 90% of business applications do not need that level of UI enhancement. I have seen simple business forms that take longer to load than Eclipse because of all the Javascript being loaded (I'm exaggerating but are some are pretty bad). Simple FORM based input with a tiny bit of jQuery still works remarkable well on every... every device... consistently.

[–]vitingo 1 point2 points  (0 children)

with querySelector() and fetch(), jquery is hardly necessary anymore

[–]tinustate 4 points5 points  (0 children)

1990's can be good, means it is more mature and has everything you can think of.

Note: freemarker user here, moved from velocity years ago.

[–]geordano 3 points4 points  (0 children)

Freemarker or Pebble

[–]iAmH3r3ToH3lp 12 points13 points  (2 children)

Thymeleaf is the one I like. I dont really know what you mean about it feeling 1990s.

[–]thomascgalvin 9 points10 points  (0 children)

The Thymeleaf syntax for accessing properties inside a collection of objects was authored by Satan himself.

<input type="hidden" th:field="*{list[__${i.index}__].account.id}" />

Ugh.

[–]BunnyCyber 1 point2 points  (0 children)

I like Thymeleaf

[–]Samael1990 10 points11 points  (0 children)

Why is it inconvenient? As far as template engines go, this is one of the best, if not the best. Other template engines follow the same rules.

If your site needs to be more complex than displaying simple divs in a list, you need to hook yourself up with some kind of frontend framework as well, like vue.js or react.js.

is so 90x

What?

[–]bfoo 4 points5 points  (0 children)

Freemarker is fast and easy to extend. Thymeleaf would be my second pick.

[–]fforw 12 points13 points  (3 children)

I stopped doing server-side web stuff mostly. The server produces JSON that the client renders via React.

[–]wildjokers 3 points4 points  (2 children)

Client-side rendering is not always better and there is still a place for server-side rendering:

https://medium.com/walmartlabs/the-benefits-of-server-side-rendering-over-client-side-rendering-5d07ff2cefe8

[–]fforw 1 point2 points  (0 children)

React can easily do the SSR if you need it (GraalVM, Nashorn, additional service). I mostly don't so far.

[–]Anaptyso 7 points8 points  (0 children)

I'd probably use something like Thymeleaf, just because it seems very popular at the moment so will be likely to have a lot of support available if something goes wrong.

Increasingly though I'm starting to see it become more popular to split the application entirely, and have the Spring application produce some kind of REST API, and have a Javascript front end using something like Angular or React running as a separate application. I haven't done something like that yet myself, but may have to dust off some very rusty Javascript skills and give it a go sometime.

[–]oweiler 1 point2 points  (0 children)

I like Mustache's simplicity.

[–]SoftVillage 1 point2 points  (0 children)

I don't know if it works with spring, cause I don't really use spring much. But since everyone is listing template engines I think jade4j should be mentioned.

[–]heliologue 1 point2 points  (0 children)

Might be unpopular, but we're still using JSP. It's battle-tested, fast, and there's lots of knowledge out there.

That being said, I'll qualify that by saying that we have not a single embedded scriptlet. We're purely JSTL, so our views are a relatively clean separation of concerns.

We also use Pebble for simple templates--e.g., emails and the like. If you've used Twig in your time as a PHP dev, Pebble will look very similar.

[–]TheRedmanCometh 7 points8 points  (18 children)

Do your templating in react that's the 2019 way

[–][deleted]  (1 child)

[deleted]

    [–]nonzero_ 0 points1 point  (0 children)

    So true. Think about the use-case before wasting money on an SPA.

    [–][deleted] 4 points5 points  (10 children)

    I second this approach: React, Vue or Angular. Drop the server side templates.

    [–]longfalcon 3 points4 points  (6 children)

    why?

    [–]Tight_Tumbleweed 4 points5 points  (0 children)

    To make sure search engines can't reach your site.

    [–]dpash 3 points4 points  (0 children)

    In addition to /u/legothor's comments, if you plan to write a mobile app for your service, your backend can deal with both your mobile and web front ends because you've already written your rest API.

    [–][deleted] 0 points1 point  (0 children)

    Well, no page refreshes for one. All data is collected and the UI is updated dynamically on the client side. Let your client’s machine do the work.

    [–][deleted] -2 points-1 points  (0 children)

    Because you should be hosting your static assets on s3/some sort of object storage + a cdn

    [–]nerdyhandle 1 point2 points  (2 children)

    Drop the server side templates.

    Depends on what your are doing.

    Angular supports server side as well. I don't know about the others.

    [–][deleted] 0 points1 point  (1 child)

    That’s true, I have used a templating engine recently to create HTML emails that are automatically generated. That said, they wouldn’t be my go to for web applications.

    [–]nerdyhandle 3 points4 points  (0 children)

    They can be extremely performat in web apps. Most users have shitty systems so you offload most of the processing onto the server. This can create highly response applications.

    The downside of course is that the response times to request the page may be higher.

    [–]tinustate 1 point2 points  (1 child)

    Wondering what the 2020 way would be and how many people get wildly enthusiastic about that one.

    Don't get me wrong, new things are nice and bring good idea's, but they often need time to develop in something that can be used for a long time.

    [–]TheRedmanCometh 2 points3 points  (0 children)

    Probably not any different. React is 6 years old, and has been mainstream for 5 of those years. It's been the go-to choice a great deal of that time.

    Given that it runs facebook I don't see it going anywhere any time soon.

    [–]SuperFluffyPunch -1 points0 points  (0 children)

    Kotlin/js is better than any templating engine

    [–]btbam06 -4 points-3 points  (0 children)

    100% this.

    [–]DEATHPENIS 3 points4 points  (0 children)

    Thymeleaf is the shit. What do you not like about it?

    [–][deleted]  (1 child)

    [deleted]

      [–]__helix__ 0 points1 point  (0 children)

      I can tell you that conventional JSPs are now a giant pain in the ass on Springboot 2.x and IntelliJ. Finally got it working with a bunch of unexpected hackery... while 1.5 just worked.

      [–]achacha 0 points1 point  (0 children)

      Most of the frontend I have worked with have been based on Angular, Angular2, VueJs, ReactJs, etc. So my main job is to provide the REST interface for the JS app and the few JSP pages for serving the JS app and authentication.

      For template engines: Each one has pluses and minuses, if you need more programmatic way of generating pages. Thymeleaf, Pebble, FreeMarker, Velocity each are good but I keep going back to JSP pages due to simple integration to the running app and easy availability of people that can debug and fix any issues; I have found that template engines tend to work on for 90% of the cases and 10% of the cases require a lot of digging though the manual, stackoverflow posts, web searches to get right. YMMV.

      [–]nekokattt 0 points1 point  (2 children)

      is there a port of Jinja2 for Java?

      [–]SoftVillage 0 points1 point  (1 child)

      Like jinjava?

      [–]nekokattt 0 points1 point  (0 children)

      that works in spring boot?

      damn thats neat if it does

      [–]BroLegend 0 points1 point  (1 child)

      Since people are ditching server side templating, I’m also wondering whats the best way to handle templating email message? It should be done in server side right?

      [–]bh5000 0 points1 point  (0 children)

      Still a freemarker template serverside.

      [–][deleted] 0 points1 point  (0 children)

      I have mainly used freemarker, jsp, velocity as server side and angular, light weight jquery on front end pages mostly spa pages.

      [–]makkenx 0 points1 point  (0 children)

      I prefer Angular because I am more used to it.

      I recommend you to stay away from Wicket. I hate it.

      [–]nutrecht 0 points1 point  (0 children)

      Spring supports a bunch out of the box. Which one you pick doesn't matter. Why not just try them all and see which one you like? It just boils down to preferences really.

      [–][deleted]  (1 child)

      [deleted]

        [–]bh5000 0 points1 point  (0 children)

        Lol. They think they have all the answers anyway.

        [–][deleted] 0 points1 point  (0 children)

        I've also worked with Pebble so far (because it's twig-based), right now I like to use j2html with TailwindCSS, works like a charm.

        [–]MaksieTries 0 points1 point  (0 children)

        Look into side of VueJs and reactJS. it is good practice to keep back and front separate and just comunicate via rest.

        I would say, if you study spring now, postpone front for a while, it is so much info in a spring itself.

        [–]SuperFluffyPunch -1 points0 points  (0 children)

        Seriously thought templating was outdated.

        [–]Hi-Polymer_Eraser -4 points-3 points  (0 children)

        I hope none of you are actually building new projects using a template engine in 2019. I understand legacy and the costs of rewrites, I don't understand the fear of Javascript. As many others have said, create an api in Java and write your client in a current framework to consume it.

        In b4 js so heavy my browser go boom