Hey everyone. I was following this tutorial. But I have problem with Template Renderer. What is new way to do it ? For testing I use directly html tags to print on page. But now I wanna do it in way it does in tutorial.
public class OutPutServlet extends HttpServlet {
private static final Logger log = LoggerFactory.getLogger(OutPutServlet.class);
private static final String TEST_TEMPLATE_FILE = "/templates/test.vm";
/*
// Example of tutorial
List<Issue> issues = getIssues(req);
Map<String, Object> context = Maps.newHashMap();
context.put("issues", issues);
resp.setContentType("text/html;charset=utf-8");
// Pass in the list of issues as the context
templateRenderer.render(LIST_BROWSER_TEMPLATE, context, resp.getWriter());
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
String p = "</br>List of Projects : </br> ";
String s = req.getRemoteUser(); // ( It display user )
resp.setContentType("text/html");
if(s == null) {
resp.getWriter().write("<html><body> You need to LogIn before using Displaying Projects and Issues </body></html>");
} else {
// Get all Projects
List<Project> projects = getAllProjects();
if (projects != null) {
for (Project project : projects) {
p = p + project.getName() + " - " + project.getKey() + " </br> ";
}
} else
p = "Projects == NULL ! ";
// Print to screen
resp.getWriter().write("<html><head><style>table, th, td {border: 1px solid black;}</style>"
+ "</head><body>Currently loggedIn USER is : "
+ s
+ "</br>"
+ p
+ "</table></body></html>");
}
} // End of doGet method!
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
} // End of doPost method
// Custom functions
private List<Project> getAllProjects () {
return ComponentAccessor.getProjectManager().getProjects();
}