From f0b1ccfcba0e78ed84e44f12e984ac93bb1ecdaf Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Sun, 12 Dec 2021 13:49:57 +0200 Subject: [PATCH] Fix creation template model using Map.of (for java 9+) --- pippo-core/src/main/java/ro/pippo/core/Response.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pippo-core/src/main/java/ro/pippo/core/Response.java b/pippo-core/src/main/java/ro/pippo/core/Response.java index c0c45ac8..01faf730 100644 --- a/pippo-core/src/main/java/ro/pippo/core/Response.java +++ b/pippo-core/src/main/java/ro/pippo/core/Response.java @@ -1043,18 +1043,21 @@ public String renderToString(String templateName, Map model) { throw new PippoRuntimeException("You must set a template engine in your application"); } + // extended model (add extra fields) + Map extendedModel = new HashMap<>(model); + // merge the model passed with the locals data - model.putAll(getLocals()); + extendedModel.putAll(getLocals()); // add session (if exists) to model Session session = Session.get(); if (session != null) { - model.put("session", session); + extendedModel.put("session", session); } // render the template using the merged model StringWriter stringWriter = new StringWriter(); - templateEngine.renderResource(templateName, model, stringWriter); + templateEngine.renderResource(templateName, extendedModel, stringWriter); return stringWriter.toString(); }