Soy templates or Velocity?

  1. Using Soy templates states that calling Soy templates from a Java class is “not recommended”; why is that?

  2. Is the use of Soy templates recommended generally for Jira Server development, or should we stick with Velocity? What direction is the Jira development team taking in regard to Soy vs. Velocity?

1 Like

Hi @david.pinn,

Calling a Soy template from Java is not recommended because it often couples your application’s view layer to your business logic layer. For a typical page render, it is best to let Java handle the collection and transformation of data to prepare it for sending to the view layer, then allow the view layer to convert that data in to HTML.

I recommend use of Soy templates internally to our dev teams, for the following reasons:

  • Soy is purpose-built to generate XML/HTML documents. As such, it provides contextual auto-escaping of data, so you have a hard time XSS-ing yourself accidentally. In contrast, Velocity is a general purpose templating language where you need to do a lot of this work yourself.
  • Soy is data-driven; you must generate and pass all data to the template up-front. I consider this an advantage because it encourages better design of data fetching and transforming. In Velocity, you can make calls to Java methods inline in the template, which can hide complex and expensive data fetching. If you were to profile for performance bottlenecks, these things are harder to spot when they are interleaved with template rendering.
  • Soy templates can be compiled to JavaScript functions and used on the client-side. This can be advantageous if you want to create a fat client but still benefit from initial server-side rendering using the same code.

Hope that helps!

Cheers,
Daz

3 Likes

@daz I maybe asking the wrong question as I am not aware of methodology , but if I display data using Vm template how am I suppose to allow user to perform CRUD operations on it.

Hi @saurabh.gupta,

Your choice of templating language doesn’t really affect how you send and receive data to and from the server. The only difference would be in how you push data in to your template such that you can render an HTML response to the browser. The rest of it – showing a form to the user and submitting data back to the server – is the same. If you’re looking for a tutorial on where to start with something like that, I would recommend ComSysto’s KitchenDuty plugin tutorial: Redirecting ....

I may not have understood your question correctly. It would be best if you ask a separate question, though, as this one is primarily about choosing between a templating language.

Cheers,
Daz

1 Like