I am new to ThymeLeaf. Am using ThymeLeaf 3.0 + Spring. Need to create email templates. Am using SpringResourceTemplateResolver. Have done a simple include as below:
<div th:include="emailContent"></div>
The emailContent.html file is as below:
<!DOCTYPE html>
<html>
<body>
<div>
© 2011 The Good Thymes Virtual Grocery
</div>
</body>
</html>
This file is present in the correct folder that the parent file is present in.
Latitude-3450:/var/lib/tomcat7/webapps/recruitment/WEB-INF/classes/emailtemplates$ ls -altr emailContent.html
-rw-r--r-- 1 tomcat7 tomcat7 108 May 30 09:31 emailContent.html
However the include cause the exception below:
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/classes/emailtemplates/emailContent]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:141)
at org.thymeleaf.spring3.templateresource.SpringResourceTemplateResource.reader(SpringResourceTemplateResource.java:103)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:223)
Without the include I get the email correctly with the parent file.
Any help would be highly appreciated.
Thanks!
Related
I'm new to orbeon Forms and I have trouble to embed form into my PHP application.
I have virtual machine with ubuntu-server 16.04 with installed:
NGINX + PHP application on https://localhost/
Tomcat8 + Orbeon Forms 2016.3 CE serving simple form on https://localhost:8443/orbeon/testapp/form
Now I want to embed my form into my site so in my index.php I do:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>My form:</h1>
<?php
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
echo file_get_contents('https://localhost:8443/orbeon/testapp/form?orbeon-embeddable=true', false, stream_context_create($arrContextOptions));
foreach ($http_response_header as $header){
$groups = [];
if (preg_match('/Set\-Cookie: JSESSIONID=(.*?);/i', $header, $groups)){
setcookie('JSESSIONID', $groups[1], 0, '/orbeon/', '', true, true);
break;
}
}
?>
</body>
</html>
and this shows me broken form. What I'm doing wrong?
Embedding is much more difficult than that, unfortunately. There is an old document, Embedding and Proxying Orbeon Forms, which covers some of the things to do.
Orbeon Forms puts this in practice in the Java embedding API, which is implemented in Scala here as of 2017-05.
There is also an outdated TYPO3 extension which you could download for inspiration, as it is implemented in PHP.
I'm just trying to setup a very simple controller to return a very simple view (with a very simple layout), however I keep getting errors related to the content type.
class SimpleController {
def index() {
render(view: "simple")
}
}
_simple.gsp:
<html>
<head>
<meta name="layout" content="blank" />
</head>
<body>
Simple test page.
</body>
</html>
blank.gsp:
<!DOCTYPE html>
<html>
<head>
<g:layoutHead />
</head>
<body>
<g:layoutBody />
</body>
</html>
It doesn't get much simpler than that. The controller method is found correctly, the issue seems to be during the rendering. Here's the error I'm getting:
2016-07-05 16:07:14,931 [http-bio-8085-exec-5] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /testApp/simple/
Stacktrace follows:
Message: null
Line | Method
->> 15 | in com.opensymphony.module.sitemesh.filter.HttpContentType
| 49 | build in com.opensymphony.sitemesh.compatability.PageParser2ContentProcessor
| 89 | getContent . . . . . . . . . . in org.codehaus.groovy.grails.web.sitemesh.GrailsContentBufferingResponse
| 107 | obtainContent in org.codehaus.groovy.grails.web.sitemesh.GrailsLayoutView
Debugging confirms that context.contentType is null. I've found four different way to set the content type, but none of them seem to work.
<%# page contentType="text/html;charset=UTF-8" %>
At the top of the view.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
In the head tag of the view.
contentType: "text/html"
Passed to the render method in the controller.
response.setContentType("text/html")
Called in the controller method.
This is in an existing project, where many other controllers and views work perfectly fine. I need to add a new controller and view, which I originally copied existing working pieces. When that didn't work, I tried to reduce the problem down to be as simple as possible, and ended up with the above code, which is still not working.
Btw, this is with Grails 2.5.1 (stuck with this version).
What you have there should work.
If you're using the default URL mappings you should name your view simple.gsp instead of _simple.gsp
If it's not as simple as that you might try recreating a simple app.
Could be even simpler and incidentally solve your problem.
class SimpleController {
def index() {
}
}
Rename _simple.gsp to index.gsp and needs to be located in views/simple/ directory. If blank.gsp its in views/layouts directory it should work now.
As #jmallen said, the page should be named "simple.gsp".
The underscore at the beginning is something I only know for templates, gsp-files, that could be included in other pages with the following statement:
<g:render template="/layouts/menu" />
than the gsp file for the menu is named
_menu.gsp
In my Grails app I need to serve links to actual text (*.txt) files. If the user clicks the link, they should view the text file as plaintext inside their browser:
MyFiles.groovy controller:
==========================
class MyFiles {
def index() {
render(view: "myfiles")
}
}
myfiles.gsp:
============
<!DOCTYPE html>
<html>
<head>
<!-- Omitted for brevity -->
</head>
<body>
Click me to view a file
</body>
</html>
My questions:
Where should I place myfile01.txt inside the Grails project? Directly inside web-app? Inside a web-app/myfiles dir? Inside WEB-INF?; and
What should the link be in the GSP, such that Grails correctly resolves correctly and displays the file? I don't see anything under g:links that stands out as an obvious choice.
I'd recommend creating another folder where you have images/css.
<a href='<g:resource dir="somedirectory" file=myfiles01.txt" absolute="true" />'>my file</a>
I'm trying to get my dummy Dart webapp running in browsers. Here's the code of my html page:
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<!-- Always force latest IE rendering engine or request Chrome Frame -->
<meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'>
</head>
<body>
<div id='button'>hello world</div>
</body>
<script src='my_app.dart' type='application/dart'></script>
<script src='packages/browser/dart.js'></script>
</html>
and this is what I'm getting in js console when trying to open it:
GET http://localhost:4567/my_app.dart.js 404 (Not Found)
(I'm running it on a local server, thus the url - got the same error if simply opening an html file though).
If I open the same url in Dartium, the webapp works. So the problem, I suppose, is that dart.js doesn't work as expected. What could be the problem?
packages/browser/dart.js is a bootstrap script that checks if a Dart VM is available on your browser. If a Dart VM is available, your dart script is executed directly, otherwise packages/browser/dart.js appends to the document a new js script with a url that points to a file with the same name as your dart file but with a appended .js. Depending on how you work you may have to generate this JS file manually with dart2js :
dart2js --out=my_app.dart.js my_app.dart
Try to "Run as Java Script" it should generate additional files like "my_app.dart.js"
I'm trying to get started with Cassette via NuGet. I'm having issues with it in my app so I rolled back and tried it in a new empty ASP.NET MVC 3 web application.
However, the problem persists. Following the documentation page "Easy to use", I simply can't get it to work. Here's the exception along with a bit of the stack:
"Object reference not set to an instance of an object."
[NullReferenceException: Object reference not set to an instance of an object.]
Cassette.CassetteApplicationContainer.get_Application() +6
Cassette.Views.Bundles.Reference(String assetPathOrBundlePathOrUrl, String pageLocation) +14
ASP._Page_Views_Shared__Layout_cshtml.Execute() in d:\Dave\Documents\Visual Studio 2010\Projects\CasetteTest\Views\Shared\_Layout.cshtml:2
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +207
I simply followed the two steps in the documentation and this is what I get. What am I doing wrong?
This is what my _Layout.cshtml file looks like:
#{
Bundles.Reference("Scripts/jquery-1.5.1.min.js");
Bundles.Reference("Scripts/modernizr-1.7.min.js");
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>#ViewBag.Title</title>
<link href="#Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
</head>
<body>
#RenderBody()
#Bundles.RenderScripts();
</body>
</html>
I figured it out.
I included the Cassette.Views package which does not create a default CassetteConfiguration.cs file that bundles each script and each css file in its own bundle. That's what triggered the NullReferenceException. In order to get it to work, you'll need to add the Cassette.Web package instead. In my defense, the package descriptions in the NuGet gallery are not clear and one is led to believe that the Views package is required for MVC and the other for WebForms.
The next problem was that I referenced the minified '.min.js' scripts which are not picked up by the bundler (it seems).
Cannot reproduce the issue.
4 simple steps allowed me to get a fully working prototype in less than 30 seconds:
Create a new ASP.NET MVC 3 project in Visual Studio
Install-Package Cassette.Web
Index.cshtml:
#using Cassette.Web
#{
Bundles.Reference("~/Scripts/jquery-1.5.1.js");
Bundles.Reference("~/Scripts/jquery-ui-1.8.11.js");
Bundles.Reference("~/Content/site.css");
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>Web App</title>
#Bundles.RenderStylesheets()
</head>
<body>
<div>Hello World</div>
#Bundles.RenderScripts()
</body>
</html>
Hit Ctrl+F5 to run the project