- Instant help with your Java coding problems

Create new dialect in Thymeleaf

How to create new dialect in Thymeleaf?
public class FormDialect extends AbstractProcessorDialect {

    private static final String DIALECT_NAME = "Form Dialect";

    public FormDialect() {
        super(DIALECT_NAME, "my-form-prefix", StandardDialect.PROCESSOR_PRECEDENCE);

    public Set<IProcessor> getProcessors(String dialectPrefix) {
        final Set<IProcessor> processors = new HashSet<IProcessor>();

        processors.add(new FormTagProcessor(dialectPrefix));
        processors.add(new HiddenTagProcessor(dialectPrefix));
        processors.add(new PasswordTagProcessor(dialectPrefix));

        processors.add(new LabelClassAttributeProcessor(dialectPrefix));
        processors.add(new ElementClassAttributeProcessor(dialectPrefix));
        processors.add(new InputClassAttributeProcessor(dialectPrefix));

        return processors;

You can define your own set of attributes (or tags) with the names you wish and use them in Thymeleaf to process your templates. You can define your own dialects.

Dialects are objects implementing the org.thymeleaf.dialect.IDialect interface. The only core requirement of a dialect is to have a name that can be used for its identification. But this alone is of little use, so dialects will normally implement one or several subinterfaces of IDialect

Share "How to create new dialect in Thymeleaf?"
thymeleaf dialect, tag processor, attribute processor, dialect, java, spring, spring-boot
Technical term:
Create new dialect in Thymeleaf