79299399

Date: 2024-12-21 12:29:20
Score: 0.5
Natty:
Report link

Solved!

  1. Create custom Dialect:

public class CnmCustomDialect extends AbstractProcessorDialect {

public CnmCustomDialect() {

    super("CNM Tags", "cnmtags", StandardDialect.PROCESSOR_PRECEDENCE);

}

@Override
public Set<IProcessor> getProcessors(String dialectPrefix) {

    Set<IProcessor> processors = new HashSet<>();       
    processors.add(new TableBuilderElementTagProcessor(getPrefix()));
    return processors;

}

}

  1. Register dialect to WebMvcConfigurer

@Bean

public SpringTemplateEngine templateEngine(ITemplateResolver templateResolver, SpringSecurityDialect sec) {

    final SpringTemplateEngine templateEngine = new SpringTemplateEngine();   

    templateEngine.addDialect(new CnmCustomDialect());
    return templateEngine;

}

3.Implement custom AbstractElementTagProcessor

-Use doProcess() method to get inputs from HTML by this tag variable and bind into the handler variable

-String modelType = tag.getAttributeValue("tt");

-Content=”Add html your content as required”

-structureHandler.replaceWith(content, false);

public class TableBuilderElementTagProcessor extends AbstractElementTagProcessor {

private ApplicationContext applicationContext;


public TableBuilderElementTagProcessor(String dialectPrefix) {
    super(TemplateMode.HTML, dialectPrefix, "table", true, null, false, StandardDialect.PROCESSOR_PRECEDENCE);

}

@Override
protected void doProcess(ITemplateContext context, IProcessableElementTag tag,IElementTagStructureHandler structureHandler) {   
        applicationContext = SpringContextUtils.getApplicationContext(context); 

String content=""; structureHandler.replaceWith(content, false);}}

Thanks

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Bean
  • Low reputation (0.5):
Posted by: Mayen