Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create servlet for standalone execution of templates #35

Closed
danielfernandez opened this issue Jul 19, 2012 · 11 comments
Closed

Create servlet for standalone execution of templates #35

danielfernandez opened this issue Jul 19, 2012 · 11 comments

Comments

@danielfernandez
Copy link
Member

A specific servlet could enable the standalone execution of thymeleaf templates (à la JSP) for those users that do not want to have any controller-side frameworks. Velocity has something similar to this...

@marceloverdijk
Copy link

+1 would love to see this

@ultraq
Copy link
Member

ultraq commented Apr 1, 2014

@danielfernandez What kind of servlet do you envision for this? I already run a Spring-less Thymeleaf site, so I could just extract my template servlet into its own library (much like I did with the layout dialect) or as an extra?

@jmiguelsamper
Copy link
Member

I think this is the Velocity servlet that Daniel told about http://velocity.apache.org/tools/devel/view.servlet.html

@danielfernandez
Copy link
Member Author

Basically, I thought of this as a way to create thymeleaf-only web applications in a similar fashion to the way people can create ASP-only web applications on an IIS or JSP-only web applications on a Tomcat/Jetty/whatever.

This is, a servlet that takes URLs (probably only .html URLs) and redirects them to thymeleaf templates which will do the processing.

And what processing, you might ask, if by the time we have our thymeleaf template executing itself we will have no context at all? Correct, but we will have two things:

And those should be enough to get data to work with in a Thymeleaf-only way...

@ultraq
Copy link
Member

ultraq commented Apr 1, 2014

I'll see what I can get going for this sometime this week as well. I'll just throw it into one of my own repos for you to evaluate. I should also be able to get it working much more simply than the instructions on the Velocity page if I start with using Servlet 3.0 web fragments (sooo much easier than having to hack together the web.xml yourself), or maybe I'm just being too optimistic.

@ultraq
Copy link
Member

ultraq commented Apr 8, 2014

So I got something going in this repo: https://github.com/ultraq/thymeleaf-template-servlet

It's a web fragment project, so can be imported into any web project and it'll automatically start working as per the config in the annotations here: StandaloneThymeleafServlet.java So the web container should support the Java web app 3.0 spec, and have annotation scanning turned on. (It shouldn't be too hard to create a non-annotation version, but I just went down this route because it's the easiest to get something going.) The init-params can also be overridden by developers in their web.xml files.

I created a mini web app (it's an Eclipse project, so is pretty hard to share right now) that imported this project and then had just HTML files in the web content folder. I could then go http://localhost:8080/test-project/path-to-html-file.html and voila! Thymeleaf template :)

@jmiguelsamper
Copy link
Member

Oh, that's a nice toy!

I will try it at the end of this week, maybe doing an example application.

Regards,
  Zemi


De: Emanuel Rabina notifications@github.com
Para: thymeleaf/thymeleaf thymeleaf@noreply.github.com
CC: Jose Miguel Samper jmiguelss@yahoo.es
Enviado: Martes 8 de abril de 2014 11:36
Asunto: Re: [thymeleaf] Create servlet for standalone execution of templates (#35)

So I got something going in this repo: https://github.com/ultraq/thymeleaf-template-servlet
It's a web fragment project, so can be imported into any web project and it'll automatically start working as per the config in the annotations here: StandaloneThymeleafServlet.java So the web container should support the Java web app 3.0 spec, and have annotation scanning turned on. (It shouldn't be too hard to create a non-annotation version, but I just went down this route because it's the easiest to get something going.) The init-params can also be overridden by developers in their web.xml files.
I created a mini web app (it's an Eclipse project, so is pretty hard to share right now) that imported this project and then had just HTML files in the web content folder. I could then go http://localhost:8080/test-project/path-to-html-file.html and voila! Thymeleaf template :)

Reply to this email directly or view it on GitHub.

@danielfernandez
Copy link
Member Author

@ultraq Oops! I still haven't had a look at that! :-$

@jmiguelsamper
Copy link
Member

The standalone servlet was integrated in the example app at https://github.com/jmiguelsamper/thymeleaf-extras-sqldialect which now is listed on the ecosystem page.

The only outstanding question is whether integrate the servlet into the Thymeleaf core or not.

@ultraq
Copy link
Member

ultraq commented Dec 5, 2015

I think it shouldn't be core, and just get a mention in the ecosystem page like your SQL dialect and then we'll support them like we do with our other Thymeleaf add-on projects.

@danielfernandez
Copy link
Member Author

👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants