thymeleaf/thymeleaf-spring

Thymeleaf only renders <form> element when there is an empty <form></form> tag before it.

ChrisHilborne opened this issue · 0 comments

Hello!

I'm not sure if this is the right place to post this but I've looked on Stackoverflow etc. and I couldn't find any reference to it.

I have been trying to make a simple GET <form>

This code did not render the form element as expected:

<!DOCTYPE html>

<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head th:replace="fragments/head::head(title='Film Fanaticos')"></head>
<body>
<header th:replace="fragments/header :: header"></header>

<main>
    <br><br>
    <div class="container-md">
        <div class="alert alert-danger" role="alert">
            <p class="text-centre">
                <strong>Are you sure you want to delete yourself permanently?</strong>
                <br>
                <small>All of your films, scores and reviews will also be deleted.</small>
            </p>
            
            <form class="mx-2" th:method="GET" th:action="@{/user/delete}"}>
                <button class="btn btn-danger profile-button mx-2" type="submit">Delete Profile</button>
                <a href="#" class="alert-link mx-2" onclick="history.back()">Go Back</a>
            </form>
        </div>
    </div>
</main>
<footer th:replace="fragments/footer :: footer"></footer>
</body>
</html>

This was the rendered HTML in the browswer:

<main>
    <br><br>
    <div class="container-md">
        <div class="alert alert-danger" role="alert">
            <p class="text-centre">
                <strong>Are you sure you want to delete yourself permanently?</strong>
                <br>
                <small>All of your films, scores and reviews will also be deleted.</small>
            </p>
            
            
                <button class="btn btn-danger profile-button mx-2" type="submit">Delete Profile</button>
                <a href="#" class="alert-link mx-2" onclick="history.back()">Go Back</a>
            
        </div>
    </div>
</main>

However, when I add an empty <form></form> tag before the <form> I want, it does render:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html">
<head th:replace="fragments/head::head(title='Film Fanaticos')"></head>
<body>
<header th:replace="fragments/header :: header"></header>

<main>
    <br><br>
    <div class="container-md">
        <div class="alert alert-danger" role="alert">
            <p class="text-centre">
                <strong>Are you sure you want to delete yourself permanently?</strong>
                <br>
                <small>All of your films, scores and reviews will also be deleted.</small>
            </p>
            <form></form>
            <form class="mx-2" th:method="GET" th:action="@{/user/delete}"}>
                <button class="btn btn-danger profile-button mx-2" type="submit">Delete Profile</button>
                <a href="#" class="alert-link mx-2" onclick="history.back()">Go Back</a>
            </form>
        </div>
    </div>
</main>
<footer th:replace="fragments/footer :: footer"></footer>
</body>
</html>

Is rendered as:

<main>
    <br><br>
    <div class="container-md">
        <div class="alert alert-danger" role="alert">
            <p class="text-centre">
                <strong>Are you sure you want to delete yourself permanently?</strong>
                <br>
                <small>All of your films, scores and reviews will also be deleted.</small>
            </p>
            
            <form class="mx-2" method="GET" action="/user/delete" }="">
                <button class="btn btn-danger profile-button mx-2" type="submit">Delete Profile</button>
                <a href="#" class="alert-link mx-2" onclick="history.back()">Go Back</a>
            </form>
        </div>
    </div>
</main>

I am using Spring Boot version 2.6.1 as well as the spring-boot-starter-thymeleaf, thymeleaf-extras-springsecurity5 and thymeleaf-extras-java8time dependencies.

Here is 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.6.1</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>io.chilborne</groupId>
	<artifactId>film-fanatic</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>film-fanatic</name>
	<description>Proyecto Final Para Spring Boot Curso de Tokio School</description>
	<properties>
		<java.version>11</java.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-jdbc</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-security</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.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
			<optional>true</optional>
		</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>org.springframework.security</groupId>
			<artifactId>spring-security-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>1.18.22</version>
		</dependency>
		<dependency>
			<groupId>com.google.guava</groupId>
			<artifactId>guava</artifactId>
			<version>31.0.1-jre</version>
		</dependency>
		<dependency>
			<groupId>org.webjars</groupId>
			<artifactId>bootstrap</artifactId>
			<version>5.1.3</version>
		</dependency>

		<dependency>
			<groupId>org.webjars</groupId>
			<artifactId>jquery</artifactId>
			<version>3.5.1</version>
		</dependency>
		<dependency>
			<groupId>org.thymeleaf.extras</groupId>
			<artifactId>thymeleaf-extras-springsecurity5</artifactId>
		</dependency>
		<dependency>
			<groupId>org.thymeleaf.extras</groupId>
			<artifactId>thymeleaf-extras-java8time</artifactId>
		</dependency>
		<dependency>
			<groupId>io.jsonwebtoken</groupId>
			<artifactId>jjwt</artifactId>
			<version>0.9.1</version>
		</dependency>
		<dependency>
			<groupId>org.hibernate.validator</groupId>
			<artifactId>hibernate-validator</artifactId>
			<version>7.0.1.Final</version>
		</dependency>
		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
			<scope>runtime</scope>
		</dependency>
	</dependencies>

	<profiles>
		<profile>
			<id>test</id>
			<properties>
				<activatedProperties>test</activatedProperties>
			</properties>
		</profile>
	</profiles>


	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<profiles>
						<profile>test</profile>
					</profiles>
				</configuration>
			</plugin>
			<plugin>
			    <groupId>org.apache.maven.plugins</groupId>
			    <artifactId>maven-compiler-plugin</artifactId>
			    <configuration>
			        <source>11</source>
			        <target>11</target>
			    </configuration>
			</plugin>
		</plugins>
	</build>

</project>

Thanks!

EDIT: code formatting