One or more resources has the target of 'head' but not 'head' component has been defined within the view - user-interface

I created a JSF page with PrimeFaces components. The project runs fine, but the PrimeFaces UI look and feel is completely missing. I'm only noticing below message in server log:
One or more resources has the target of 'head' but not 'head' component has been defined within the view
What does this mean and how can I fix the PrimeFaces UI styling?

This means that you're using plain HTML <head> instead of JSF <h:head> in your XHTML template. The JSF <h:head> allows automatic inclusion of CSS/JS resources in the generated HTML <head> via #ResourceDependency annotations. PrimeFaces as being a jQuery based JSF component library needs to auto-include some jQuery/UI JS/CSS files and this really requires a <h:head>.
So, search for a
<head>
<title>Some title</title>
...
</head>
in your templates and replace it by
<h:head>
<title>Some title</title>
...
</h:head>
See also:
What's the difference between <h:head> and <head> in Java Facelets?
Unable to understand <h:head> behaviour
How to programmatically add JS and CSS resources to <h:head>
How to include another XHTML in XHTML using JSF 2.0 Facelets?

Related

Spring Boot Security + GWT, static resources access 403 error

I am fighting the css/js access problem in my gwt+spring security simple application. So, i have secutiy controller with the next method:
#GetMapping(value = "/notes")
public ModelAndView index(ModelAndView modelAndView) {
modelAndView.setViewName(VIEW_NOTES);
return modelAndView;
}
By the way, I integrated these technologies according to this article. So, thanks to this controller method (I use RestController) we've got resolved view (simple as ****):
<!DOCTYPE html>
<html lang="en">
<head>
<title>Notes</title>
<link rel="stylesheet" type="text/css" media="all"
href="../static/css/notes-main.css"></link>
</head>
<body>
<!-- This script tag is what actually loads the GWT module. The -->
<!-- 'nocache.js' file (also called a "selection script") is -->
<!-- produced by the GWT compiler in the module output directory -->
<!-- or generated automatically in development mode. -->
<script language="javascript" src="notesgwtapp/notesgwtapp.nocache.js">
</script>
<!-- Include a history iframe to enable full GWT history support -->
<!-- (the id must be exactly as shown) -->
<iframe src="javascript:''" id="__gwt_historyFrame"
style="width:0;height:0;border:0"></iframe>
<div id="notes"></div>
</body>
</html>
Now is the most interesting thing that I have these two errors:
GET http://localhost:8080/static/css/notes-main.css 403
GET http://localhost:8080/notesgwtapp/notesgwtapp.nocache.js 403
I dont have problems with resolving resources for other views, btw.
Please help, how can I handle it? If i miss some important part of code, I will add it. Just ask. Thank you in advance.
By default Sprint Boot permits all access to /js/**, /css/**, /images/**. But you try to access /static/** and /notesgwtapp/** which will result in the 403 error (see here).
There are two solutions:
Make sure that the notesgwtapp.nocache.js and the notes-main.css file end up in one of the above folders or
Override the SecurityConfig of your Spring Boot app and add the /static/** and /notesgwtapp/** folder to the permitted locations.

How to implement layout template with spring boot and mustache

I have a Sprint Boot Web Maven project created from Spring Initlializer with Mustache templating engine.
So far, its working and I can do the basic things but I want to set a layout (template) that will include the main body of html e.g. <html>...</html> whilst my view template will only include the page content e.g. <h1>Hello World</h1>
I can get partials to work so I could do {{>header}}<h1>Hello World</h1>{{>footer}}
What I want to be able to do is:
index.html
{{>header}}{{>content}}{{>footer}}
home.html
<h1>Hello World</h1>
I can't find any tutorial or documentation how do this.
If it helps, I found some reference documentation here:
https://spring.io/blog/2016/11/21/the-joy-of-mustache-server-side-templates-for-the-jvm
See the section on Natural Templates.
{{!
<!doctype html>
<html lang="en">
<body>
}}
{{>header}}
<h1>Demo</h1>
<div>Hello World</div>
{{>footer}}
{{!
</body>
</html>
}}

i18n with ReloadableResourceBundleMessageSource in Spring - <spring:message> tag not parsed

i set up ReloadableResourceBundleMessageSource as shown in spring documentation. I am using the following page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
xmlns:spring="http://www.springframework.org/tags"
xmlns:ui="http://java.sun.com/jsf/facelets">
...
<b><spring:message code="general.welcome"/></b> ${user.firstName} ${user.lastName}
...
When running the application and inspecting the source code i still see:
<b><spring:message code="general.welcome"/>
without rendering the message defined in the messages_en.properties file.
How can i get more information to track what is happening and the tag is not rendered as mentioned message output?
Thanks & kindest regards,
ArnKor

Using Spring's theme resolvers and themes with a Thymeleaf template

I would like to use Spring theme resolvers' feature (see: here) in my Thymeleaf template.
What is the Thymeleaf's equivalent to the spring:theme JSP tag?
See JSP code sample below:
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<link rel="stylesheet" href="<spring:theme code='styleSheet'/>" type="text/css"/>
</head>
<body style="background=<spring:theme code='background'/>">
...
</body>
</html>
I don't think this was the case at the time that you asked your question, but the current version of thymeleaf-spring3 (2.0.18 as of this writing) has as part of the SpringStandard dialect a themes function, which can be used like this:
<body th:style="'background-color: ' + ${#themes.code('backgroundColor')}">

Spring tags and facelets

Can I use Spring tags with facelets? I have one JSP page, and there is a directive:
<%# taglib prefix="s" uri="http://www.springframework.org/tags"%>
Then I can insert the tag <s:theme code='css' /> (I'm using theme resolver.) Now I need to use theme resolver in another project using facelets instead JSP. There is a namespace declaration instead the JSP directive, isn't?
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:em="http://java.sun.com/jsf/composite/emcomp"
xmlns:st="http://www.springframework.org/tags">
But in Eclipse the namespace is labeled with the warning marker and on server it does not work, because the tag library is missing, althought I have put the library Spring Web MVC in the lib directory of Eclipse Internal Glassfish server. The JAR really contains META-INF/spring.tld.
I'm unable to find, what's wrong.
No, unfortunately you cannot. Spring tags are based on a JSP taglib. Facelet taglibs are different from JSP taglibs. The reason you can use the old-fashioned jsp core tags (c:forEach etc) in facelets is because they have been ported to facelet taglibs. AFAIK, there has not been any port done yet of the Spring JSP taglib to a facelet taglib.

Resources