Note that there are some explanatory texts on larger screens.

plurals
  1. POJSTL/JSP EL (Expression Language) in a non JSP (standalone) context
    text
    copied!<p>Can anyone recommend a framework for templating/formatting messages in a standalone application along the lines of the JSP EL (Expression Language)?</p> <p>I would expect to be able to instantiate a an object of some sort, give it a template along the lines of</p> <pre><code>Dear ${customer.firstName}. You order will be dispatched on ${order.estimatedDispatchDate} </code></pre> <p>provide it with a context which would include a value dictionary of parameter objects (in this case an object of type Customer with a name 'customer', say, and an object of type Order with a name 'order').</p> <p>I know there are many template frameworks out there - many of which work outside the web application context, but I do not see this as a big heavyweight templating framework. Just a better version of the basic Message Format functionality Java already provides </p> <p>For example, I can accomplish the above with java.text.MessageFormat by using a template (or a 'pattern' as they call it) such as</p> <pre><code>Dear {0}. You order will be dispatched on {1,date,EEE dd MMM yyyy} </code></pre> <p>and I can pass it an Object array, in my calling Java program</p> <pre><code>new Object[] { customer.getFirstName(), order.getEstimatedDispatchDate() }; </code></pre> <p>However, in this usage, the code and the pattern are intimately linked. While I could put the pattern in a resource properties file, the code and the pattern need to know intimate details about each other. With an EL-like system, the contract between the code and the pattern would be at a much higher level (e.g. customer and order, rather then customer.firstName and order.estimatedDispatchDate), making it easier to change the structure, order and contents of the message without changing any code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload