Selecting limited range of node by using comment node as limiter - xpath

I was trying to select nodes between two comment
<ul>
<!-- fromHere -->
<option>a</option>
<option>a</option>
<option>a</option>
<option>a</option>
<option>a</option>
<!-- toHere -->
<option>a</option>
<option>a</option>
<option>a</option>
<option>a</option>
</ul>
$x("//comment()[.=' fromHere ']/following-sibling::* | //comment()[.=' toHere ']/preceding-sibling::*")
Is there anyway doing a AND selection?

Try this xpath:
//option[preceding-sibling::comment()=" fromHere " and following-sibling::comment()=" toHere "]

Related

Error occuring template parsing. (Spring Boot + Thymeleaf) with layout and static

I am getting parsing error when I try to load localhost:8080/.
I can't find any errors in my template, so why have I this mistake?
The file static has folder css and picture with jQuery, js and bootstrap
Error : This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed May 22 13:02:18 CEST 2019
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/RHAjouterDeve.html]")
Code layout index.html:
<!DOCTYPE html>
<html lang="fr" xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial- scale=1">
<link th:href="/webjars/bootstrap/4.3.1/css/bootstrap.css" rel="stylesheet" />
<link rel="icon" th:href="(images/favicon.ico)" type="image/ico" />
<title>Projet Pfa Spring BOOT </title>
<link rel="stylesheet" th:href="{build/css/bootstrap.min.css}" />
</head>
<body class="nav-md">
<div class="container body">
<div class="main_container">
<div class="col-md-3 left_col">
<div class="left_col scroll-view">
<div class="navbar nav_title" style="border: 0;">
</div>
<div class="clearfix"></div>
<div class="profile clearfix">
<div class="profile_pic">
</div>
</div>
<br />
<div id="sidebar-menu" class="main_menu_side hidden-print main_menu">
<div class="menu_section">
<br/>
<br/>
<br/>
<br/>
<br/>
<h3>Menu</h3>
<!-- <ul class="nav side-menu"> -->
<!-- <li><a><i class="fa fa-home"></i> Formation <span class="fa fa-chevron-down"></span></a> -->
<!-- <ul class="nav child_menu"> -->
<!-- <li>Demande Formation</li> -->
<!-- <li>Formation Traité</li> -->
<!-- <li>Formation Accepter</li> -->
<!-- <li>Formation En Cours</li> -->
<!-- <li>Formation Finis</li> -->
<!-- </ul> -->
<!-- </li> -->
<!-- <ul class="nav side-menu"> -->
<!-- <li><a><i class="fa fa-home"></i> Devellopeur <span class="fa fa-chevron-down"></span></a> -->
<!-- <ul class="nav child_menu"> -->
<!-- <li>La Liste Devellopeur</li> -->
<!-- </ul> -->
<!-- </li> -->
<!-- </ul>-->
</div>
</div>
</div>
</div>
<!-- top navigation -->
<div class="top_nav">
<div class="nav_menu">
<nav>
<div class="nav toggle">
<a id="menu_toggle"><i class="fa fa-bars"></i></a>
</div>
<ul class="nav navbar-nav navbar-right">
<li class="">
<a href="javascript:;" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<img th:src="(images/img.jpg)" alt="">
<span class=" fa fa-angle-down"></span>
</a>
<ul class="dropdown-menu dropdown-usermenu pull-right">
<li>
</li>
<li><i class="fa fa-sign-out pull-right"></i> Log Out</li>
</ul>
</li>
<li role="presentation" class="dropdown">
<ul id="menu1" class="dropdown-menu list-unstyled msg_list" role="menu">
<li>
<a>
<span class="image"><img th:src="(images/img.jpg)" alt="Profile Image" /></span>
</a>
</li>
<li>
<a>
<span class="image"><img src="images/img.jpg" alt="Profile Image" /></span>
</a>
</li>
<li>
<a>
</a>
</li>
<li>
<a>
</a>
</li>
<li>
<div class="text-center">
</div>
</li>
</ul>
</li>
</ul>
</nav>
</div>
</div>
<!-- /top navigation -->
<!-- page content -->
<div class="right_col" role="main">
<!-- <div class="row tile_count"> -->
<!-- <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count"> -->
<!-- <span class="count_top"><i class="fa fa-user"></i> Formation en cours</span> -->
<!-- <div class="count">2500</div> -->
<!-- </div> -->
<!-- <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count"> -->
<!-- <span class="count_top"><i class="fa fa-user"></i> Formation Traité </span> -->
<!-- <div class="count">123.50</div> -->
<!-- <span class="count_bottom"><i class="green"> </i></span> -->
<!-- </div> -->
<!-- <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count"> -->
<!-- <span class="count_top"><i class="fa fa-user"></i> Total Finis</span> -->
<!-- <div class="count green">2,500</div> -->
<!-- <span class="count_bottom"><i class="green"></i> </i></span> -->
<!-- </div> -->
<!-- <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count"> -->
<!-- <span class="count_top"><i class="fa fa-user"></i> Total Formateur</span> -->
<!-- <div class="count">4,567</div> -->
<!-- <span class="count_bottom"><i class="red"></i> </i> </span> -->
<!-- </div> -->
<!-- <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count"> -->
<!-- <span class="count_top"><i class="fa fa-user"></i> Total Employé</span> -->
<!-- <div class="count">2,315</div> -->
<!-- <span class="count_bottom"><i class="green"> </span> -->
<!-- </div> -->
<!-- <div class="col-md-2 col-sm-4 col-xs-6 tile_stats_count"> -->
<!-- <span class="count_top"><i class="fa fa-user"></i> Total Chef Projet</span> -->
<!-- <div class="count">7,325</div> -->
<!-- <span class="count_bottom"><i class="green"> </span> -->
<!-- </div> -->
<!-- </div> -->
<section layout:fragment="content" class="container">
</section>
<!-- start of weather widget -->
<!-- end of weather widget -->
</div>
</div>
</div>
<!-- /page content -->
<!-- footer content -->
<!-- /footer content -->
<!-- Custom Theme Scripts -->
<script src="build/js/custom.min.js"></script>
<script src="/webjars/jquery/3.4.1/jquery.js"></script> <script src="/webjars/bootstrap/4.3.1/js/bootstrap.js">
</script>
</body>
</html>
</strike>
Fichier rhajouterdeve.html
<strike><!DOCTYPE html>
<html xmlns:th="http://thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout/default">
<body>
<section layout:fragment="content">
hello
</section>
</body>
</html>
</strike>
le code du controller :
package com.projetpfa.gestionrh.gestionrh.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
#RequestMapping("/Devellopeur")
public class DeveControllers {
//#Autowired
//DeveService dvserv;
#GetMapping("/")
public String AllDeve( )
{
return"RHAjouterDeve";
}
}
mon fichier 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 http://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.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.projet.pfa</groupId>
<artifactId>projetpfa</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projetpfa</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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</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>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</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>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Error in logs:
____org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/RHAjouterDeve.html]")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) [thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362) [thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189) [thymeleaf-spring5-3.0.11.RELEASE.jar:3.0.11.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1370) [spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1116) [spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1055) [spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) [spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) [spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897) [spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) [tomcat-embed-core-9.0.17.jar:9.0.17]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) [spring-webmvc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) [tomcat-embed-core-9.0.17.jar:9.0.17]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-9.0.17.jar:9.0.17]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.17.jar:9.0.17] _ __ _ _
have a Spring Boot for serving images. My Model is included in my ImageController.java. ImageService contains findPage method.
When running my Spring Boot Application I am getting an error.
I want to see me template DASHBOARD to begin my project
How can localhost:8585/Devellopeur find template with static file and layout view with no error,
First of all, you can not access localhost:8080/ because you do not have the right controller. You can access http://localhost:8090/Devellopeur/
package com.projetpfa.gestionrh.gestionrh.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
#Controller
#RequestMapping("/Devellopeur")
public class DeveControllers {
//#Autowired
//DeveService dvserv;
#GetMapping("/")
public String AllDeve( )
{
return"RHAjouterDeve";
}
}
In order to access http://localhost:8090/Devellopeur/ without no thymeleaf parsing errors, you have to create the web page default declared in your rhajouterdeve.html. In general, this file (default.html) is used to to reuse header and footer on all Thymeleaf templates.
<html xmlns:th="http://thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout/default">
Create it in templates package and declare it as follow:
<html xmlns:th="http://thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default">
At last, you should delete the <strike> in your rhajouterdeve.html
Here an example of default page that you can use.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<header>
<div class="container">
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<a class="navbar-brand" href="#">Jeutroll</a>
</div>
<div>
<ul class="nav navbar-nav">
<li class="active"><a th:href="#{/index}">Home</a></li>
</ul>
</div>
</nav>
</div>
</header>
<section layout:fragment="content"></section>
<footer>
<div class="navabar-fixed-bottom">
<small>adress</small>
</div>
</footer>
</body>
</html>

Spring Webflow: Unable to display error messages with jsr 303 validations

I'm working with spring mvc 4.3.8 and spring webflow 2.4.5 along with thymeleaf 3.x. I'm unable to get the error messages from jsr-303 annotations displayed with spring webflow after validation fails. While the view itself is re-rendered, error messages are not displayed. what else do I need to do ? Please help.
<!-- WebFlow Configuration -->
<bean id="viewFactoryCreator"
class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="viewResolver" />
</bean>
<webflow:flow-builder-services id="flowBuilderServices"
view-factory-creator="viewFactoryCreator" validator="validator"/>
<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
<webflow:flow-registry id="flowRegistry"
flow-builder-services="flowBuilderServices" base-path="/WEB-INF/spring/flows">
<webflow:flow-location id="add-locale" path="/locale-flow.xml" />
</webflow:flow-registry>
<!-- the flow executor drives the execution of the flow -->
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>
<!-- Enables FlowHandler URL mapping.
This handler adapter is the bridge between DispatcherServlet and the flow executor -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<!-- Maps request paths to flows in the flowRegistry.
Tells DispatcherServlet to send flow requests to the FlowHandlerAdapter -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry" />
<property name="order" value="0" />
</bean>
locale-flow.xml
<input name="id"/>
<on-start>
<evaluate expression="localeController.newLocaleForm(id)" result="flowScope.localeForm" />
</on-start>
<view-state id="localeForm" view="locale/locale-form-p1" model="flowScope.localeForm">
<transition on="next" to="configureMessageBundle"/>
</view-state>
<view-state id="configureMessageBundle" view="locale/locale-form-p2" model="flowScope.localeForm" />
<view-state id="returnToViewPage" view="externalRedirect:locale-page.html" />
The backing form bean, LocaleForm.java
#NotNull(message = "Locale cannot be blank")
private String code;
#NotBlank(message = "Name cannot be blank")
#Size(min = 3, max = 255, message = "Name must be between 3 and 255 characters")
#Pattern(regexp = "^[\\w-_]+$", message = "Name can contain only alphabets, numbers, hypen and underscore")
private String name;
The form view page, locale-form-p1.html
<form class="form-horizontal" th:action="${flowExecutionUrl}" th:object="${localeForm}" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="control-label col-xs-2">Locale</label>
<div class="col-xs-10">
<select class="selectpicker form-control" tabindex="0" th:field="*{code}">
<option value="en_US" th:each="locale : *{availableLocales}"
th:value="${locale.key}"
th:text="${locale.value}">English (US)</option>
</select>
</div>
</div>
<div class="form-group required">
<label class="control-label col-xs-2">
Name <a role="button" data-toggle="popover" data-trigger="hover" data-html="true" title="" data-content="Provide a unique name for the Locale." data-placement="top"><span class="fa fa-info-circle"></span></a>
</label>
<div class="col-xs-10" th:classappend="${#fields.hasErrors('name')}? has-error">
<input class="form-control" type="text" placeholder="Name" th:field="*{name}" >
<span class="help-block" th:unless="${#fields.hasErrors('name')}">Allowed characters are alphabets, numbers, hyphen and underscore.</span>
<span class="help-block" th:errors="*{name}"></span>
</div>
</div>
<div class="form-group">
<div class="col-xs-2 col-xs-offset-2">
<button class="btn btn-primary btn-sm btn-primary-spacing" type="submit" name="_eventId_next">Next</button>
<button class="btn btn-default btn-sm" type="button" up-href="locale-page.html" up-target="#page-content">Cancel</button>
</div>
</div>
</form>
Resolved it. It turns out that Spring Web Flow has a different way of providing the user with feedback messages. The Spring Web Flow reference documentation says: “Spring Web Flow’s MessageContext is an API for recording messages during the course of flow executions”.
<div class="form-group required">
<label class="control-label col-xs-2">
Name <a role="button" data-toggle="popover" data-trigger="hover" data-html="true" title="" data-content="Provide a unique name for the Locale." data-placement="top"><span class="fa fa-info-circle"></span></a>
</label>
<div class="col-xs-10" th:classappend="${#arrays.length(flowRequestContext.messageContext.getMessagesBySource('name'))>0}? has-error">
<input class="form-control" type="text" placeholder="Name" th:field="*{name}" >
<span class="help-block" th:if="${#arrays.isEmpty(flowRequestContext.messageContext.getMessagesBySource('name'))}">Allowed characters are alphabets, numbers, hyphen and underscore.</span>
<p class="help-block" th:each="err : ${flowRequestContext.messageContext.getMessagesBySource('name')}" th:text="${err.text}">Input is invalid</p>
</div>
</div>

Create pdf having each page background in different color using DOMPDF

I am generating reports using DOMPDF in codeigniter. This pdf have 10 pages in which 3 pages have yellow background (Page #2, #5 and #8 and entire page bgcolor needs to be yellow without margin or spacing) rest pages background color is white.
Also, i am using DOMPDF's html5 parser by setting "DOMPDF_ENABLE_HTML5PARSER" config as true. This is because my report html's contains html5 tags like footer.
I googled this and found one solution as to put each page in separate "body" tag but generated output have all pages in yellow background.
Below is my html template:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Report</title>
<link rel="stylesheet" href="css/reports/styles.css" />
</head>
<!-- Page #1 -->
<body>
<div>
<div class="wrapper">
<h1>Heading</h1>
<ul class="index">
<li>2. report 1</li>
<li>5. report 2</li>
<li>8. report 3</li>
</ul>
</div>
</div>
</body>
<!-- Page #2 -->
<body style="background-color: #f2ab02">
<div>
<div class="wrapper">
<h1>Report 1: Analysis & Results</h1>
<img src="/img/reports/human-face.png" class="imglogo" />
</div>
</div>
</body>
<!-- Page #3 -->
<body>
<div>
<h1>Report 1: (1/2)</h1>
<table>...</table>
<footer>
<img src="/img/reports/logo.png" class="footer-logo" />
<div class="page_number">3</div>
</footer>
</div>
</body>
<!-- Page #4 -->
<body>
<div>
<h1>Report 1: (2/2)</h1>
<table>...</table>
<footer>
<img src="/img/reports/logo.png" class="footer-logo" />
<div class="page_number">4</div>
</footer>
</div>
</body>
<!-- Page #5 -->
<body style="background-color: #f2ab02">
<div>
<div class="wrapper">
<h1>Report 2: Analysis & Results</h1>
<img src="/img/reports/human-face.png" class="imglogo" />
</div>
</div>
</body>
<!-- Page #6 -->
<body>
<div>
<h1>Report 2: (1/2)</h1>
<table>...</table>
<footer>
<img src="/img/reports/logo.png" class="footer-logo" />
<div class="page_number">6</div>
</footer>
</div>
</body>
<!-- Page #7 -->
<body>
<div>
<h1>Report 2: (2/2)</h1>
<table>...</table>
<footer>
<img src="/img/reports/logo.png" class="footer-logo" />
<div class="page_number">7</div>
</footer>
</div>
</body>
<!-- Page #8 -->
<body style="background-color: #f2ab02">
<div>
<h1>Report 3: Analysis & Results</h1>
<img src="/img/reports/human-face.png" class="imglogo" />
</div>
</body>
<!-- Page #9 -->
<body>
<div>
<h1>Report 3: (1/2)</h1>
<table>...</table>
<footer>
<img src="/img/reports/logo.png" class="footer-logo" />
<div class="page_number">9</div>
</footer>
</div>
</body>
<!-- Page #10 -->
<body>
<div>
<h1>Report 3: (2/2)</h1>
<table>...</table>
<footer>
<img src="/img/reports/logo.png" class="footer-logo" />
<div class="page_number">10</div>
</footer>
</div>
</body>
</html>
Any help will be appreciated.
I can't say that I would recommend this method, but it might work if you disable the HTML5 parser. The main use of the HTML5 parser in dompdf is to correct syntactical errors. Multiple BODY elements are not permitted and so after passing through the HTML5 parser the multiple body elements will be merged into a single element.

Can I use spring thymeleaf with layoutdialect?

Like in topic, Can I use Thymeleaf layout dialect with spring?
Do I have to use Spring Standard Dialect?
There is so many materials on web, which makes me really confused.
I've started with Layout dialect, but I cant get to work whole app.
Here is my template main file:
<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml" xml:lang="pl" lang="pl" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title>DERP></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="all" href="../../css/template.css" th:href="#{/css/template.css}" />
<link rel="stylesheet" type="text/css" media="all" href="../../lib/font-awesome-4.2.0/css/font-awesome.min.css" th:href="#{/lib/font-awesome-4.2.0/css/font-awesome.min.css}" />
<link rel="stylesheet" type="text/css" media="all" href="../../lib/bootstrap-3.3.1-dist/css/themes/slate/bootstrap.min.css" th:href="#{/lib/bootstrap-3.3.1-dist/css/themes/slate/bootstrap.min.css}" />
<link rel="stylesheet" type="text/css" media="all" href="../../lib/animate/animate.css" th:href="#{/lib/animate/animate.css}" />
</head>
<body>
<div th:include="fragments/bodyHeader" th:remove="tag">
for prototyping
</div>
<div id="mainMenu">
<div class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">DERP</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
<ul class="nav navbar-nav">
<li class="active">Active</li>
<li>Link</li>
<li class="dropdown">
Dropdown <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li class="dropdown-header">Dropdown header</li>
<li>Separated link</li>
<li>One more separated link</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<i class="fa fa-home"></i> Customer <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
<li class="dropdown">
<i class="fa fa-user"></i> User <b class="caret"></b>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li class="divider"></li>
<li>Separated link</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<!-- #mainMenu ENDS-->
<div layout:fragment="header">Static header</div>
<div layout:fragment="pageContent">Demo static page content</div>
<div id="pageFooter" class="panel panel-default">
<div class="panel-body">Copyright Daniel Korbel 2014</div>
</div>
<div id="javaScriptSection">
<script type="text/javascript" src="../../lib/jquery/jquery-2.1.1.min.js" th:src="#{lib/jquery/jquery-2.1.1.min.js}"></script>
<script type="text/javascript" src="../../js/template.js" th:src="#{/js/template.js}"></script>
<script type="text/javascript" src="../../lib/noty-2.3.1/js/noty/packaged/jquery.noty.packaged.min.js" th:src="#{/lib/noty-2.3.1/js/noty/packaged/jquery.noty.packaged.min.js}"></script>
<script type="text/javascript" src="../../lib/noty-2.3.1/js/noty/layouts/topRight.js" th:src="#{/lib/noty-2.3.1/js/noty/layouts/topRight.js}"></script>
<script type="text/javascript" src="../../js/notyStarter.js" th:src="#{/js/notyStarter.js}"></script>
<script type="text/javascript" src="../../lib/bootstrap-3.3.1-dist/js/bootstrap.min.js" th:src="#{/lib/bootstrap-3.3.1-dist/js/bootstrap.min.js}"></script>
</div>
</body>
</html>
and my sample body file which is returned by controller:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" layout:decorator="layout/template">
<div layout:fragment="pageContent">
<p>LIST</p>
</div>
</html>
But unfortunatelly this code works only with Layout dialect.
Can anyone help me transform that code to work with spring standard dialect?
My thymeleaf config:
public class ThymeleafConfig {
#Bean
public ServletContextTemplateResolver templateResolver() {
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setPrefix("/WEB-INF/view/");
resolver.setSuffix(".html");
resolver.setTemplateMode("HTML5");
resolver.setOrder(1);
resolver.setCacheable(false);
return resolver;
}
#Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver());
templateEngine.setDialect(new SpringStandardDialect());
//templateEngine.setDialect(new LayoutDialect());
return templateEngine;
}
#Bean
public ThymeleafViewResolver viewResolver() {
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine());
viewResolver.setCharacterEncoding("UTF-8");
return viewResolver;
}
}
Adding the layoutdialect to the templateengine should be enough to get it working. Don't use setDialect. You should have an addDialect or setAdditionalDialects method or something like that. (I use the xml config so i don't know the exact names)
UPDATE: added xml config
<beans:bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<beans:property name="templateResolvers">
<beans:set>
<beans:ref bean="servletContextTemplateResolver" />
<beans:ref bean="classLoaderTemplateResolver" />
</beans:set>
</beans:property>
<beans:property name="dialects">
<beans:set>
<beans:ref bean="thymeleafSpringDialect" />
</beans:set>
</beans:property>
<beans:property name="additionalDialects">
<beans:set>
<beans:bean class="nz.net.ultraq.thymeleaf.LayoutDialect" />
<beans:bean
class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect" />
<beans:bean class="ch.mfrey.thymeleaf.extras.with.WithDialect" />
<beans:bean class="ch.mfrey.thymeleaf.extras.cache.CacheDialect" />
</beans:set>
</beans:property>
</beans:bean>

Conditional rendering in "Segments"

So I have the following spark partial
<default extension="null" footer="null" header="null" type="string"/>
<div class="mod ${extension}?{extension != null}">
<div class="inner">
<div class="hd ${header}?{header != null}">
<render segment="hd" />
</div>
<div class="bd">
<render />
</div>
<div class="ft ${footer}?{footer != null}">
<render segment="ft" />
</div>
</div>
</div>
I think that segments are really cool, but I only want it render if I use it. Maybe something like this:
<default extension="null" footer="null" header="null" type="string"/>
<div class="mod ${extension}?{extension != null}">
<div class="inner">
<render segment="hd">
<div class="hd ${header}?{header != null}">
<!-- write content here -->
</div>
</render>
<div class="bd">
<render />
</div>
<render segment="ft">
<div class="ft ${footer}?{footer!= null}">
<!-- write content here -->
</div>
</render>
</div>
</div>
Usage like:
<mod>
<p> My content </p>
<segment name="hd">
<h1> My Header </h1>
</segment>
</mod>
Basically I'm trying to get spark to only render segments that are used. In this instance I wouldn't want the <div class="ft" /> to render and I would want the <h1> wrapped by the <div class="hd">
Does something like this work for you:
<default extension="null" footer="null" header="null" type="string"/>
<div class="mod ${extension}?{extension != null}">
<div class="inner">
<div class="hd ${header}" if="header != null">
<render segment="hd" />
</div>
<div class="bd">
<render />
</div>
<div class="ft ${footer}" if="footer != null">
<render segment="ft" />
</div>
</div>
</div>
This would have the effect of not rendering the divs at all if header or footer was null. You could do the same for extension of course but I assumed you always want to at least render the body so I left it the way you had it. You can put an if="condition" on any node in Spark.
Am I missing something here?
Cheers,
Rob

Resources