th:field inserts field= attribute

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

th:field inserts field= attribute

giver
Hello!

i'm just upgraded Thymeleaf from 2.1 to 3 and now have some unsolvable problems. For now we are using spring 4.0

    <form method="post" th:object="${item}"> 
        <th:block th:text="*{title}"/>
        <input  type="text" th:field="*{title}"/>
     </form>

this code produces such string:
Real Title <input type="text" field="Real Title"/>

How can i fix it?

i'm using XML syntax mode to achieve best compatability due to lots of <short/> tags. So here is my configuration:

@Bean  ITemplateResolver necmsDevTemplateResolver(
            ServletContext servlet,
            ApplicationContext ctx,
            Settings res
    ) {
        SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
        resolver.setApplicationContext(ctx);
        resolver.setOrder(10);
        resolver.setPrefix("/resources/ne/");
        resolver.setSuffix(".html");
        configure(resolver, res);
        return resolver;
    }
   
    void configure(AbstractConfigurableTemplateResolver resolver, Settings res) {
        resolver.setCharacterEncoding("UTF-8");
        resolver.setTemplateMode(TemplateMode.XML);
        resolver.setCheckExistence(true);
        resolver.setForceTemplateMode(true);
        resolver.setCacheable(res.PRODUCTION.is()); // todo
        resolver.setForceTemplateMode(true);
    }

 @Bean public SpringTemplateEngine templateEngine(
            List<ITemplateResolver> l,
            MessageSource messageSource,
            Settings res
    ) {

        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setMessageSource(messageSource);
        engine.setEnableSpringELCompiler(res.PRODUCTION.is());
        engine.addDialect(new LayoutDialect());
        engine.setMessageSource(messageSource);
       
        for (ITemplateResolver resolver : l)
            engine.addTemplateResolver(resolver);
       
        return engine;
    }
Reply | Threaded
Open this post in threaded view
|

Re: th:field inserts field= attribute

giver
Though it works in HTML mode, should i file a bug? Maybe we need a distinct XHTML mode?
Reply | Threaded
Open this post in threaded view
|

Re: th:field inserts field= attribute

Metroids
As far as I know, the only difference between the new HTML type and what existed in thymeleaf 2 is that the new type no longer requires valid XML.  I think everything should work though.

Are you just missing the validation? I don't think there is any problem using short tags with the HTML type.

https://github.com/thymeleaf/thymeleaf/issues/391