Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA-40763 Moving some article links on Github - spring-thymeleaf #18112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.baeldung.thymeleaf.formatter;

import java.text.ParseException;
import java.util.Locale;

import org.springframework.format.Formatter;
import org.thymeleaf.util.StringUtils;

/**
*
* Name formatter class that implements the Spring Formatter interface.
* Formats a name(String) and return the value with spaces replaced by commas.
*
*/
public class NameFormatter implements Formatter<String> {

@Override
public String print(String input, Locale locale) {
return formatName(input, locale);
}

@Override
public String parse(String input, Locale locale) throws ParseException {
return formatName(input, locale);
}

private String formatName(String input, Locale locale) {
return StringUtils.replace(input, " ", ",");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.baeldung.thymeleaf.model;

import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;

/**
*
* Simple student POJO with few fields
*
*/
public class Student implements Serializable {

private static final long serialVersionUID = -8582553475226281591L;

@NotNull(message = "Student ID is required.")
@Min(value = 1000, message = "Student ID must be at least 4 digits.")
private Integer id;

@NotNull(message = "Student name is required.")
private String name;

@NotNull(message = "Student gender is required.")
private Character gender;

@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birthDate;

private Float percentage;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Character getGender() {
return gender;
}

public void setGender(Character gender) {
this.gender = gender;
}

public Date getBirthDate() {
return birthDate;
}

public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}

public Float getPercentage() {
return percentage;
}

public void setPercentage(Float percentage) {
this.percentage = percentage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.baeldung.thymeleaf.utils;

public class ArrayUtil {

public static String[] array(String... args) {
return args;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.baeldung.thymeleaf.utils;

import java.util.ArrayList;
import java.util.List;

import com.baeldung.thymeleaf.model.Student;

public class StudentUtils {

private static List<Student> students = new ArrayList<Student>();

public static List<Student> buildStudents() {
if (students.isEmpty()) {
Student student1 = new Student();
student1.setId(1001);
student1.setName("John Smith");
student1.setGender('M');
student1.setPercentage(Float.valueOf("80.45"));

students.add(student1);

Student student2 = new Student();
student2.setId(1002);
student2.setName("Jane Williams");
student2.setGender('F');
student2.setPercentage(Float.valueOf("60.25"));

students.add(student2);
}

return students;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE HTML>
<html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<title>Thymeleaf: Javascript function call</title>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.baeldung.thymeleaf.controller;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc(printOnlyOnFailure = false)
public class FunctionCallIntegrationTest {

@Autowired
private MockMvc mockMvc;

@Test
public void testGetDates() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/function-call"))
.andExpect(status().isOk())
.andExpect(view().name("functionCall.html"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.baeldung.thymeleaf.controller;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc(printOnlyOnFailure = false)
public class ExpressionUtilityObjectsControllerIntegrationTest {

@Autowired
private MockMvc mockMvc;

@Test
public void testGetObjects() throws Exception {
mockMvc.perform(get("/objects")).andExpect(status().isOk()).andExpect(view().name("objects.html"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.baeldung.thymeleaf.controller;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc(printOnlyOnFailure = false)
public class LayoutDialectControllerIntegrationTest {

@Autowired
private MockMvc mockMvc;

@Test
public void testGetDates() throws Exception {
mockMvc.perform(get("/layout")).andExpect(status().isOk()).andExpect(view().name("content.html"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public void setup() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).addFilters(springSecurityFilterChain).build();
}

@Test
public void testGetObjects() throws Exception {
mockMvc.perform(get("/objects").with(testUser()).with(csrf())).andExpect(status().isOk()).andExpect(view().name("objects.html"));
}

@Test
public void testDates() throws Exception {
mockMvc.perform(get("/dates").with(testUser()).with(csrf())).andExpect(status().isOk()).andExpect(view().name("dates.html"));
Expand Down

This file was deleted.

This file was deleted.