Giter VIP home page Giter VIP logo

test-nested-springel-conversion's Introduction

Test: Thymeleaf nested conversion with SpringEL

This repository checks a reported change in behaviour for the conversion (via a Spring Formatter) of a nested property, depending on whether the property is declared in the containing bean as of being of its specific type, or a superclass (which has no registered Formatter).

See thymeleaf/thymeleaf-spring#128

Contents

This repository contains two folders with almost exactly the same application code, except one of them uses Thymeleaf 2.1.5 and the other one Thymeleaf 3.0.3.

Both applications are based on Spring Boot 1.4.3.

The Thymeleaf 2.1.5 app starts on port 8080. The Thymeleaf 3.0.3 app starts on port 8081, so they can be started at the same time.

Both apps can be started with:

$ mvn -U clean compile spring-boot:run

Implementation

The Bean class contains two fields:

    private AbstractField fieldAbs = null;
    private Field fieldConc = null;

The Field class extends AbstractField. At the controller a bean variable of this Bean class is initialised as:

    @RequestMapping("/")
    public String main(final Model model) {

        final Bean bean = new Bean();
        bean.setFieldAbs(new Field(100));
        bean.setFieldConc(new Field(500));

        model.addAttribute("bean", bean);

        return "main";

    }

Using a browser and pointing to the root of the web apps, the main.html template will show all the possible combinations for SpringEL conversion being applied:

<section>
    <h3>Outside Form</h3>
    <p>Abstract Field: </p>
    <ul>
        <li>Without <kdb>th:object</kdb>: <span th:text="${{bean.fieldAbs}}">...</span></li>
        <li th:object="${bean}">With <kdb>th:object</kdb>: <span th:text="*{{fieldAbs}}">...</span></li>
    </ul>
    <p>Concrete Field: </p>
    <ul>
        <li>Without <kdb>th:object</kdb> <span th:text="${{bean.fieldConc}}">...</span></li>
        <li th:object="${bean}">With <kdb>th:object</kdb> <span th:text="*{{fieldConc}}">...</span></li>
    </ul>
</section>

<section>
    <h3>Inside Form</h3>
    <form th:object="${bean}">
        <fieldset>
            <p>
                <label for="fieldAbs">Abstract field:</label>
                <input th:field="*{fieldAbs}" />
            </p>
            <p>
                <label for="fieldConc">Concrete field:</label>
                <input th:field="*{fieldConc}" />
            </p>
        </fieldset>
    </form>
</section>

Both applications show the same results, so the reported differences in behaviour between 2.1.5 and 3.0.3 could not be confirmed.

test-nested-springel-conversion's People

Contributors

danielfernandez avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.