Thymeleaf not displaying fragments - html

I am trying to learn Thymeleaf and when using th:fragment and th:replace or th:insert, nothing is displayed on the page. This is in intellij Idea using the spring boot framework.
What I've tried:
Changing routing on th:insert (ex. th:insert="fragments/test::test">)
Trying different code in the fragment
Changing test.html to include / not include "xmlns:th="http://www.thymeleaf.org""
Stopping / restarting Apache Tomcat for every single change I make
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>SC2Hub</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SC2Hub</name>
<description>SC2Hub</description>
<properties>
<java.version>18</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
index.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Title</title>
</head>
<body>
<div th:insert="test::test"></div>
<div th:replace="test::test"></div>
</body>
</html>
test.html:
<div th:fragment="test">
<h1>Hello from the fragment!</h1>
</div>
File structure:
project
--src
----resources
------static
--------index.html
------templates
--------fragments
----------test.html

From the given code I see 2 issues. The first is that your index.html is not inside the templates folder, all files used by thymeleaf should be inside this folder unless you've overriden the default value of where thymeleaf looks for files.
After that as mentioned by #andrewJames fragment calls should be relative to the thymeleaf source folder (by default src/main/resources/templates) and in your case that would be <div th:replace="fragments/test::test"></div>

Related

Spring Boot Applying Older Version of CSS File to JSP

I have a Spring Boot project which has a MainMenu.jsp which is as follows:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<title>Test</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<div class="navheader">
<h2>Test</h2>
<c:if test="${pageContext.request.userPrincipal.name != null}">
<form id="logoutForm" method="POST" action="${contextPath}/logout">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<h2>Welcome ${pageContext.request.userPrincipal.name} | <a onclick="document.forms['logoutForm'].submit()">Logout</a></h2>
</c:if>
</div>
</head>
<body>
<ul>
<li>Groups</li>
<li>Frameworks</li>
</ul>
</body>
</html>
I'm using a style.css file located under resources/static/css, and my browser locates it successfully as it does not return a 404 error. However any changes I make are not reflected - it appears to be using an older version of the CSS. I suspect it is using the CSS from style.css before I changed the style sheet's href from
"/css/style.css" to "${pageContext.request.contextPath}/css/style.css"
If the path is correct, why isn't it applying my CSS? If the path isn't correct, why is it using an older version and not giving a 404 for not finding the file?
Edit: my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>samuelB</groupId>
<artifactId>capripol</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Capripol</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Browsers cache css files based on settings, in your development setup you can disable cache in the browser to always load the new files when the site loads. For example if you are using Chrome you can do so by ticking the Disable Cache box in Developer tools, network tab.
For production system, you can avoid css caching by using a version number in the css filename.
also read : Browser Caching of CSS files

Bootstrap 4 webjar css not working with Spring Boot + Thymeleaf

I am making a Spring Boot web app using Thymeleaf. I have been experimenting with Webjars to use things like JQuery and Bootstrap on my web page. Using Spring Boot 2.2.6.RELEASE, and attempting to use Bootstrap Webjar version 4.1.1-1.
I have several different webjars in my pom, but I realized that none of the css files are loading. The Javascript files from the webjars are loading fine, but none of the css is being applied. When looking in the web developer debugger tool, I can see the Javascript files are all there, but none of the css files are present.
Currently, I am specifically trying to get Bootstrap tabs to work, but obviously, without any of the Bootstrap styles, none of the Bootstrap features will work.
This is basically what my controller looks like:
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
#Controller
public class MyController {
#RequestMapping(value = "/stats", method = {RequestMethod.GET, RequestMethod.POST})
public String stats(
Model model) {
// some code adding simple attributes to the model
return "stats";
}
}
I have this web configuration class:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
#Configuration
public class WebConfig implements WebMvcConfigurer {
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/")
.resourceChain(false);
}
}
A sample of my pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!-- artifact info... -->
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- some other dependencies -->
<!-- Webjars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.4.1-1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap-datepicker</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>popper.js</artifactId>
<version>1.16.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>font-awesome</artifactId>
<version>5.13.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.40</version>
</dependency>
<!-- Spring -->
<!-- some other Spring deps... -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Here is a sample of my html page (stats.html):
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>My Web App</title>
<link th:rel="stylesheet" th:href="#{webjars/bootstrap/css/bootstrap.min.css}" type="text.css"/>
<!--<link th:rel="stylesheet" th:href="#{webjars/bootstrap-datepicker/css/bootstrap-datepicker.min.css}" type="text/css"/>-->
<link th:rel="stylesheet" th:href="#{webjars/bootstrap-datepicker/css/bootstrap-datepicker.standalone.css}" type="text/css"/>
<link th:rel="stylesheet" th:href="#{webjars/font-awesome/css/all.css} " type="text/css"/>
<link href="../static/css/custom-styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<script th:src="#{webjars/jquery/jquery.min.js}" type="text/javascript"></script>
<script th:src="#{webjars/popper.js/1.14.3/umd/popper.min.js}" type="text/javascript"></script>
<script th:src="#{webjars/bootstrap/js/bootstrap.min.js}" type="text/javascript"></script>
<script th:src="#{webjars/bootstrap-datepicker/js/bootstrap-datepicker.min.js}" type="text/javascript"></script>
<!-- Other simple web content... -->
<!-- Example straight from Bootstrap 4 documentation https://getbootstrap.com/docs/4.4/components/navs/#tabs -->
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">...</div>
<div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">...</div>
<div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">...</div>
</div>
</body>
The tab titles (or nav-items) just get displayed as a normal unordered list, with all the actual tabs' contents being displayed all together below that.
As I said, as far as I can tell, the script files are getting loaded properly. I have a Bootstrap datepicker set up and working on the same page, but without the Bootstrap styles. I need to use the bootstrap-datepicker.standalone.css file, because bootstrap-datepicker.min.css doesn't work.
Things I have tried that did not work:
Deleting the WebConfig class
Moving the css links into the body of the HTML document
Putting a '/' in front of the #{webjars/...} in the link tags. That does technically work for the Javascript stuff, but it made no difference with the css links. Furthermore, I need to leave the leading '/' off so the app will use page relative links, or else the app doesn't work when deployed to our staging environment
Specifying the version inside the th:href like so: #{/webjars/bootstrap/4.1.1-1/css/bootstrap.min.css}
Taking other things out of the main HTML page until it's pretty much only testing the Bootstrap tabs (i.e. only importing the Bootstrap css and the Javascript files)
Removing the th: from the link element
The one thing I've done that does work is using the BootstrapCDN as seen on https://getbootstrap.com/ : <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
If I use that instead of the link I actually have in the HTML above, the styles are applied and everything works (as far as I can tell). However, I would like to know why I can't get the webjar to work, and if anyone else has had this problem. Or perhaps I am doing something obviously wrong which I am too close to see?
Just had the same (or very similar) problem using Bootstrap 4.5.0 The below worked for me:
In pom I have:
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
<version>0.40</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.5.0</version>
</dependency>
I do not have the #Configuration class - it actually started working when I removed it.
My html starts with:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" th:href="#{/webjars/bootstrap/css/bootstrap.min.css}" type="text/css"/>
<script th:src="#{/webjars/bootstrap/js/bootstrap.min.js}"></script>
<script th:src="#{/webjars/jquery/jquery.min.js}"></script>
</head>
Hope this helps.
EDIT: Just had a look at your code again. You have type="text.css" instead of type="text/css"
B.

Images not displaying on web page in simple Spring Boot application

I'm trying to load a basic homepage just to try out Spring Boot and the images are not being loaded.
I've tried all sorts of different URL combinations to check whether the class path is wrong. Earlier I had an images folder within the static folder but this did not work either. I've removed adblock extensions, I've tried on both Firefox and Chrome browsers, I inspected the elements on the page for the image path and the response header. I have added no configuration to application.properties. I tried with and without the #EnableAutoConfiguration annotation as per https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#getting-started-first-application-auto-configuration
The one thing I noticed was that the GET requests are all returning 200OK, as opposed to 404, and the type on the network tab is listed as text/html, whereas the Spring icon image used in the webpage title is listed as image/x-icon, but I don't know if that's the issue.
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
#Controller
#EnableAutoConfiguration
public class HomeController {
#GetMapping
public String home2() {
return "home2";
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>PuppR Home</title>
</head>
<body>
<h1>Homepage</h1>
<img src="jpx10.jpg"/>
<img src="/jpx10.jpg"/>
<img src="static/jpx10.jpg"/>
<img src="/static/jpx10.jpg"/>
<img src="../static/jpx10.jpg"/>
<img src="/../static/jpx10.jpg"/>
</body>
</html>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
I'm including links to images of my project structure as I don't have enough reputation to post images
https://i.imgur.com/gHdyS74.png
an image of the actual webpage generated with broken links, and the network console
https://i.imgur.com/0pXpyMQ.png
Try this, <img src="../static/jpx10.jpg" width="1000" th:src="#{/jpx10.jpg}"/>

Liferay: jsf portlet and navigation from commandButton with view params

I am using Lifreay 6.2 with primefaces 6.0.
I have these two simple views:
view.xhtml
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head />
<f:metadata>
<f:viewParam name="fromPlace"
value="#{modelBean.fromPlace}" />
</f:metadata>
<h:body>
<h:form>
<p:inputText id="foo"
value="#{modelBean.fromPlace}" />
<p:commandButton value="submit"
action="search?faces-redirect=true&includeViewParams=true" />
</h:form>
</h:body>
</f:view>
search.xtml
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head />
<f:metadata>
<f:viewParam name="fromPlace"
value="#{modelBean.fromPlace}" />
</f:metadata>
<h:body>
#{param.fromPlace}
#{modelBean.fromPlace}
</h:body>
</f:view>
The goal of this is simple. Type a value on the inputText element, click the submit button, and then redirect to the second page and show the result. The reason I have a command button is that I want in the future to execute some backing bean action and dynamically return the redirect viewId, but right now is irrelevant.
My question is this.. If I put ajax=false at the command button component, everything works as expected. If I put ajax=true at the command button component, I get a weird error ONLY when my input contains spaces. If it doesn't contain spaces, it works again as expected. Putting the parameters manually at the URL string didn't work either, regadless of various tries of encoding etc. Also, with regular jsf components (like here) same thing happens. In the eclipse console the following lines appear:
14:42:20,856 ERROR [BridgeContextImpl:234] Illegal character in query at index 79: /test-portlet/WEB-INF/views/search.xhtml?fromPlace=123 321&_bridgeAjaxRedirect=true
java.net.URISyntaxException: Illegal character in query at index 79: /test-portlet/WEB-INF/views/search.xhtml?fromPlace=123 321&_bridgeAjaxRedirect=true
Is this behavior normal?
Edit: I created a new jsf portlet project using the archetype provided from liferayfaces.org/ and then I imported it as an existing maven project but a similar error appears.
error
15:54:11,198 ERROR [ExceptionHandlerAjaxImpl:75] javax.portlet.faces.BridgeException: java.net.URISyntaxException: Illegal character in query at index 110: /com.mycompany.my.primefaces.portlet-portlet/WEB-INF/views/search.xhtml?_jsfBridgeRedirect=true&fromPlace=1234 1234
javax.faces.FacesException: javax.portlet.faces.BridgeException: java.net.URISyntaxException: Illegal character in query at index 110: /com.mycompany.my.primefaces.portlet-portlet/WEB-INF/views/search.xhtml?_jsfBridgeRedirect=true&fromPlace=1234 1234
pom.xml
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>com.mycompany.my.primefaces.portlet</artifactId>
<packaging>war</packaging>
<name>com.mycompany.my.primefaces.portlet</name>
<version>1.0-SNAPSHOT</version>
<properties>
<faces.api.version>2.2</faces.api.version>
<liferay.faces.bridge.ext.version>3.0.0</liferay.faces.bridge.ext.version>
<liferay.faces.bridge.version>4.0.0</liferay.faces.bridge.version>
<mojarra.version>2.2.13</mojarra.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-api</artifactId>
<version>${faces.api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>${mojarra.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>com.liferay.faces.bridge.ext</artifactId>
<version>${liferay.faces.bridge.ext.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.faces</groupId>
<artifactId>com.liferay.faces.bridge.impl</artifactId>
<version>${liferay.faces.bridge.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0</version>
</dependency>
</dependencies>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<!-- Seting the JSF 2 PROJECT_STAGE to Development will cause the JSF implementation will do the following at runtime: -->
<!-- 1. Log more verbose messages. -->
<!-- 2. Render tips and/or warnings in the view markup. -->
<!-- 3. Cause the default ExceptionHandler to display a developer-friendly error page. -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- JSF 2.2 now allows for composite components and resources to be hidden under WEB-INF -->
<context-param>
<param-name>javax.faces.WEBAPP_RESOURCES_DIRECTORY</param-name>
<param-value>/WEB-INF/resources</param-value>
</context-param>
<!-- Although the FacesServlet will not be invoked by any portlet requests, it is required to initialize JSF. -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<security-constraint>
<display-name>Prevent direct access to Facelet XHTML</display-name>
<web-resource-collection>
<web-resource-name>Facelet XHTML</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint/>
</security-constraint>
</web-app>
liferay-portlet.xml
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_2_0.dtd">
<liferay-portlet-app>
<portlet>
<portlet-name>com.mycompany.my.primefaces.portlet</portlet-name>
<icon>/resources/images/icon.png</icon>
<requires-namespaced-parameters>false</requires-namespaced-parameters>
<ajaxable>false</ajaxable>
</portlet>
<role-mapper>
<role-name>administrator</role-name>
<role-link>Administrator</role-link>
</role-mapper>
<role-mapper>
<role-name>guest</role-name>
<role-link>Guest</role-link>
</role-mapper>
<role-mapper>
<role-name>power-user</role-name>
<role-link>Power User</role-link>
</role-mapper>
<role-mapper>
<role-name>user</role-name>
<role-link>User</role-link>
</role-mapper>
</liferay-portlet-app>
Edit: FACES-2958 has been fixed as of Bridge Impl 4.1.1 and Bridge Ext 5.0.2.
You are running into a bug: FACES-2958.
As you've found, you can workaround this issue by using the commandButton without ajax.
p:commandButton:
<p:commandButton value="submit"
action="search?faces-redirect=true&includeViewParams=true"
ajax="false" />
h:commandButton:
<h:commandButton value="submit"
action="search?faces-redirect=true&includeViewParams=true" />

Css files treated as html files after merge

I had two branches on github. The second one was for the front integration and worked perfectly untill I merged it with the master.
My index.jsp file:
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="ex" uri="/WEB-INF/custom.tld" %>
<html>
<jsp:include page="pages/headFragment.jsp"/>
<body>
<body>
...
</body>
</html>
The headFragment.jsp is:
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<head>
<!-- Animate.css -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/animate.css">
<!-- Icomoon Icon Fonts-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/icomoon.css">
<!-- Simple Line Icons -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/simple-line-icons.css">
</head>
In a browser's console I have few errors:
SyntaxError: expected expression, got '<'
but they are connected with css files which are not css files. My animate.css is interpreted by the browser as the html file with the body of whole page. The links are interpreted normally, but theirs' body isn't.
I think that's the problem with linking the css stylesheets, but I googled and tried a lot of options and nothing worked. The interesting part is that on a front-integration part it is normally working, but after merge it does not include css files. There's also problem with js files, but I tried to repare css firstly...
And, by the way, I work on Intellij 2016.2.4
Also my pom.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>webpage</groupId>
<artifactId>web_page</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>web</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
<dependencies>
<!-- https://mvnrepository.com/artifact/postgresql/postgresql -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
<!-- http://repo1.maven.org/maven -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
For whom it may concern.
The problem occured bacause of the global welcome path '/' to the loaded servlet. Change of this path to f.e. '/yolo' resolves all of the conflicts.