[JAVA] What to do when CSS is not applied in JSF and one or more resources have the target of'head', but no'head' component has been defined within the view.

environment OS : macOS Hight Sierra Eclipse : Neon.3 Release (4.6.3) Server : GlassFish 4.1 Java : JDK1.8 JSF : 2.2

Event: JSF should have loaded CSS but it doesn't apply

XHTML before modification


<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core">
<head>
  <title>input screen</title>
  <h:outputStylesheet library="css" name="base.css"/>
</head>
<body>
<h:form>
  <h:outputLabel>Please enter the password.</h:outputLabel>
  <br />
  <h:inputText id="password" value="#{passwordBean.password}">
    <f:validateRequired />
    <f:validateLength minimum="3" maximum="10"></f:validateLength>
  </h:inputText>
  <h:message for="password" errorClass="error" />
<abridgement>

base.css


@CHARSET "UTF-8";
.error {
    color: red;
}

Screen Shot 2017-12-12 at 20.13.28.png

server.log


[2017-12-12T20:29:46.608+0900] [glassfish 4.1] [INFO] [jsf.non_displayed_message] [javax.enterprise.resource.webcontainer.jsf.renderkit] [tid: _ThreadID=32 _ThreadName=http-listener-1(2)] [timeMillis: 1513078186608] [levelValue: 800] [[
  WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=null[severity=(ERROR 2), summary=(One or more resources have the target of 'head', but no 'head' component has been defined within the view.), detail=(One or more resources have the target of 'head', but no 'head' component has been defined within the view.)]]]

Cause: Because you are using <head>

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

Workaround: Use <h: head>

Modified XHTML


<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
  <title>input screen</title>
  <h:outputStylesheet library="css" name="base.css"/>
</h:head>
<abridgement>

Screen Shot 2017-12-12 at 20.19.48.png

Recommended Posts

What to do when CSS is not applied in JSF and one or more resources have the target of'head', but no'head' component has been defined within the view.
What to do when you want to know the source position where the method is defined in binding.pry
What to do when javax.el.ELException: Not a Valid Method Expression: appears when the JSF screen is displayed
What to do when the changes in the Servlet are not reflected
What to do if Operation not permitted is displayed when you execute a command in the terminal
[IOS] What to do when the image is filled with one color
What to do if the prefix c is not bound in JSP
What to do when the value becomes null in the second getSubmittedValue () in JSF Validator
What to do when rails db: seed does not reflect in the database
[Swift] What to do if the app icon is set but not reflected
What to do when "Fail to load the JNI shared library" is displayed in Eclipse
What to do if the breakpoint is shaded and does not stop during debugging