Html5 validation error with title tag - validation

Hello I am validating my source against html 5.
But I am getting this error and have now idea how to solve it:
<meta charset="utf-8"><title>Rode kruis Vrijwilligers applicatie</title><link href="/css/blitzer/jquery-ui-1.8.11.custom.css" media="screen" rel="stylesheet" type="text/css" >
This is the error:
XHTML element title not allowed as child of XHTML element meta in this context. (Suppressing further errors from this subtree.)
Any idea's?

In XHTML which is strict about XML rules, every tag that is opened should be nested and closed properly, tags such as <area />,<base />,<basefont />,<br />,<hr />,<input />,<img />,<link />,<meta /> are only usefull with attributes so you have to close them by "/>" instead of ">"
In XML thats how you open and close a tag in the same tag, this is what your html should look like:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Rode kruis Vrijwilligers applicatie</title>
<link href="/css/blitzer/jquery-ui-1.8.11.custom.css" media="screen" rel="stylesheet" type="text/css" >
</head>
<body>
Test.
</body>
</html>

You need to close your meta tag - it is an empty tag:
<meta charset="utf-8" />
XHTML is an XML dialect, so empty elements should be closed (so <br> is not valid XHTML, but <br /> is).

As mentioned in comments to the first answer (which should also solve the problem) another approach is to use plain HTML5 without the XML requirement. For example the following code would get validated:
<!doctype html><html><head>
<meta charset="utf-8"><title>Rode kruis Vrijwilligers applicatie</title><link href="/css/blitzer/jquery-ui-1.8.11.custom.css" media="screen" rel="stylesheet" type="text/css" >
</head><body>Test.</body></html>
With the middle line being the original code.
Validated with direct input here:
http://validator.w3.org/

Related

extending fragments in Thymeleaf

I have the following fragment. I'm trying to extend the base fragment "head" with the open graph tags... but the rendered page contains only tags from fragments/head, with the og ones.
How can I add more tags to a fragment?
<head th:include="fragments/head :: head">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="GUApp" />
<meta property="og:description" th:content="${description}" />
<!--<meta property="og:image" content="http://www.your-domain.com/path/image.jpg" />-->
</head>
<head th:fragment="head" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
....
</head>
The easiest option is to pass additional tags as in Flexible layouts documentation demo.
Thanks to fragment expressions, we can specify parameters for
fragments that are not texts, numbers, bean objects… but instead
fragments of markup.
This allows us to create our fragments in a way such that they can be
enriched with markup coming from the calling templates, resulting in a
very flexible template layout mechanism.
index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="header :: head(~{::meta})">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description" th:content="${description}"/>
</head>
...
header.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:fragment="head(meta)">
<!-- some default styles -->
<link href="base.css" rel="stylesheet" />
<!--/* Per-page placeholder for additional meta tags */-->
<th:block th:replace="${meta}" />
</head>
...
Result html:
<!DOCTYPE html>
<html lang="en">
<head>
<link href="base.css" rel="stylesheet" />
<meta property="og:url"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description"/>
</head>
...

IntelliJ Spring Boot project can't find my CSS files with Thymeleaf

I'm new to Spring Boot and my problem is that I have Spring Boot project and I am intending to view my HTML pages with Thymeleaf but Spring can't resolve my JavaScript and CSS files.
Full picture of my IDE:
Those are my Thymeleaf configurations
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=true
This is my HTML page head:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head>
<title>404 Page</title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lt IE 9]>
<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta charset="UTF-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1"/>
<meta name="viewport" content="width=device-width"/>
<!-- Css Files Start -->
<link href="/src/main/resources/static/css/style.css" rel="stylesheet" type="text/css" media="screen"/><!-- All css -->
<link href="/src/main/resources/static/css/bs.css" rel="stylesheet" type="text/css" media="screen"/><!-- Bootstrap Css -->
<link rel="stylesheet" type="text/css" href="/src/main/resources/static/css/main-slider.css" media="screen"/><!-- Main Slider Css -->
<!--[if lte IE 10]>
<link rel="stylesheet" type="text/css" href="/static/css/customIE.css" media="screen"/><![endif]-->
<link href="/src/main/resources/static/css/font-awesome.css" rel="stylesheet" type="text/css" media="screen"/><!-- Font Awesome Css -->
<link href="/src/main/resources/static/css/font-awesome-ie7.css" rel="stylesheet" type="text/css" media="screen"/><!-- Font Awesome iE7 Css -->
<noscript>
<link rel="stylesheet" type="text/css" href="/static/css/noJS.css"/>
</noscript>
<!-- Css Files End -->
</head>
You should use relative path to your JavaScript and CSS files:
<link href="../../static/css/style.css" rel="stylesheet" type="text/css" media="screen"/>
or you can use th:href Thymeleaf's tag as well:
<link th:href="#{css/style.css}" href="../../static/css/style.css"
rel="stylesheet" type="text/css" media="screen"/>
I have found that Spring automatically searches for: /resources/.
So what I did was removed all the pre-directories by using find all.
So, in my case what used to be for example: /static/css/style.css & /templates/index.html
became: /css/style.css & /index.html
Now the question remains how does Spring boot know what folder to look in without you defining it: Spring looks at the extension. When spring boot sees .html, it looks for it in a folder called /templates.

How can I correctly import an header and a footer page into a FreeMarker page?

I am working on a Spring MVC application that use FreeMarker for my views.
I am absolutly new in FreeMarker and I have the following problem: in my projct I have 3 files that have to be assemblet togheter into a single page.
So I have:
1) header.ftl representing the header of all my pages, somthing like:
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js is-ie8"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Registrazione - MY WEBSITE</title>
<meta name="robots" content="noindex,nofollow">
<link rel="stylesheet" href="resources/css/webfont.css">
<link rel="stylesheet" href="resources/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="resources/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="resources/plugins/bs-select/bootstrap-select.min.css">
<link rel="stylesheet" href="resources/plugins/bs-dialog/bootstrap-dialog.min.css">
<link rel="stylesheet" href="resources/css/style.css" />
</head>
<body id="main">
<!-- versione per popup. non prendere in considerazione -->
<!--
<div class="container page-header">
<h1>MY WEBSITE</h1>
</div>
2) footer.ftl representing the footer of all my pages:
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="assets/plugins/bs-select/bootstrap-select.min.js"></script>
<script src="assets/plugins/bs-select/i18n/defaults-it_IT.min.js"></script>
<script src="assets/plugins/bs-dialog/bootstrap-dialog.min.js"></script>
<script src="assets/plugins/jq-form-validation/jquery.validation.js"></script>
<script src="assets/js/functions.lib.js"></script>
<script src="assets/js/form-validation.js"></script>
</body>
</html>
3) Then I have my specific page (named myPage.ftl that represent only the content, something like this:
<h1>This is the content</h1>
<p>Some inforamation</p>
The header.ftl and the footer.ftl are into this directory **\WEB-INF\freemarker\layout** of my project.
So my problem is: how can I import the header.ftl content above the content of the myPage.ftl and the footer.ftl under the content of myPage.ftl page?
I did this using user-defined macros for page layouts, e.g. let's call your layout standardPage.ftl:
<#macro standardPage title="">
<!DOCTYPE html>
<html lang="en">
<head>
<title>${title}</title>
</head>
<body>
<#include "/include/header.ftl">
<#nested/>
<#include "/include/footer.ftl">
</body>
</html>
</#macro>
Then you can call this macro in each of your pages, e.g. homePage.ftl:
<#include "/pages/standardPage.ftl" />
<#standardPage title="Home">
<h1>Home Page</h1>
<p>This bit replaces the nested tag in the layout</p>
</#standardPage>

Meta Tags Inside MasterPage Output On One Line

I like clean code and I'm sure most developers do. I am coming across an issue where my Meta tags are all appearing on ONE line all together and not on separate lines.
I have a file called "client.master" and here is code for the header:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta name="format-detection" content="telephone=no" />
<script src="/scripts/script1.min.js" type="text/javascript"></script>
<script src="/scripts/script2.min.js" type="text/javascript"></script>
<link rel="apple-touch-icon" href="/images/home-screen.png" />
<link rel="apple-touch-startup-image" href="/images/home-startup.png" />
<link href="/css/thirdparty/xxxxx.min.css" type="text/css" rel="stylesheet" />
<link href="/css/design.css" type="text/css" rel="stylesheet" />
<asp:ContentPlaceHolder ID="headContent" runat="server">
</asp:ContentPlaceHolder>
</head>
That looks very clean and nice. However, when I view the source of the page, the output shows the <meta> tags and the <link> tags all on one line. The script tags are not.
Here is the output of my code:
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="default" /><meta name="format-detection" content="telephone=no" />
<script src="/scripts/script1.min.js" type="text/javascript"></script>
<script src="/scripts/script2.min.js" type="text/javascript"></script>
<link rel="apple-touch-icon" href="/images/home-screen.png" /><link rel="apple-touch-startup-image" href="/images/home-startup.png" /><link href="/css/thirdparty/xxxxx.min.css" type="text/css" rel="stylesheet" /><link href="/css/design.css" type="text/css" rel="stylesheet" />
<title>
Login
</title></head>
Notice the <meta> and <link> tags are both on a single line AND the <title> tag has line breaks.
Here is the HTML for the default.aspx page for the Title:
<asp:Content ID="title" runat="server" ContentPlaceHolderID="title">
Login
</asp:Content>
My assumption is because the <meta> tags and <link> tags are self enclosed and the <script> tags end with </script>.
Is the only way to resolve this issue to close my <meta> tags with </meta>. Which way is to be considered the standard when closing meta and link tags? or script tags?
Thanks in advance for your help!
If you really want to follow the spec, link and meta are void elements, they can't have a closing tag, if your DOCTYPE is HTML5, you can use the selfclosing tag <meta ..../> but the default way would be to use it only as a start tag, that is a correct conforming use as empty elements don't need an end tag (void ones, as I said, can't have it).
Script is not a void element, but is an empty one, so you can use only the start tag, the self-closing tag or both start and end tags.
Note that for an element to have a content model of type empty really means it may be empty, not that it should; that would probably be what it is called void.
As to why the asp parser does that to your metas, I can't think of a reason. I understand your preference for clean code, but if it is of any help, try to think that at least that bug contributes to a filesize decrease :o)
Bear in mind that all of this applies to HTML5, XHTML treats void and empty models differently.

Xpather does not evaluate the XPath on firefox 3.5 but works fine on firefox 3.6

I am working on a richface application and trying to evaluate the following xpath with xpather on firefox3.5. XPather does not evaluate any of the xpath though the same xpath works perfectly fine on firefox 3.6.
The page which I am testing is like -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:o="http://openfaces.org">
<head>
<script src="some source" type="text/javascript"></script>
<script src="some source" type="text/javascript"></script>
<link class="component" href="some source" rel="stylesheet" type="text/css" />
<link class="component" href="some source"
media="rich-extended-skinning" rel="stylesheet" type="text/css" />
<link class="component" href="some source" rel="stylesheet" type="text/css" />
<script type="text/javascript">window.RICH_FACES_EXTENDED_SKINNING_ON=true;</script>
<link type="text/css" href="some source" rel="stylesheet"/>
<body class="Banner" onresize="setTreePnlHeight()" onload="loadApp();">
<input type="hidden" id="dsTreeScrollPos" value="0" />
<div id="a" class="application"><form id="form" name="form" method="post" action="...">
....
</body>
</html>
If I use xpather(v1.4.5) to evaluate the simple xpath on FF3.5 like //input, it does not return any result. Is namespace causing this issue? How can i verify my xpath on FF3.5?
simple xpath on FF3.5 like //input, it
does not return any result. Is
namespace causing this issue?
Yes. If you look at your document, you have a default namespace definition there.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:o="http://openfaces.org">
This means that //input is looking for an element <input> without a namespace, whereas you should look for <input> that is in the http://www.w3.org/1999/xhtml namespace. You need to define that namespace and bind it to a prefix and then use that prefix in your XPath. like //x:input

Resources