0
我最近添加一些自定义的方言和处理器到我的春天启动的应用程序,但是当我把它们放在页面那样:Thymeleaf不评价定制方言/处理器
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:form="http://form" xmlns:field="http://field">
<body>
<form:form>
...
</form:form>
</body>
</html>
并在打开的页面浏览器中,标签不会被评估为正确的值。该FormDialect是这样的:
public class FormDialect extends AbstractDialect {
public FormDialect() {
super();
}
//
// All of this dialect's attributes and/or tags
// will start with 'hello:'
//
public String getPrefix() {
return "form";
}
//
// The processors.
//
@Override
public Set<IProcessor> getProcessors() {
final Set<IProcessor> processor = new HashSet<IProcessor>();
processor.add(new Form());
return processor;
}
}
和FormProcessor是:
public class Form extends AbstractProcessor {
@Override
public ProcessorResult doProcess(Arguments arguments,ProcessorMatchingContext context,Node node) {
Element form = new Element("form");
node.setProcessable(true);
node.getParent().insertBefore(node, form);
return ProcessorResult.OK;
}
@Override
public int getPrecedence() {
return 0;
}
@Override
public IProcessorMatcher<? extends Node> getMatcher() {
return new ElementNameProcessorMatcher("form");
}
}
什么,我做错了什么?
此示例(http://www.thymeleaf.org/doc/extendingthymeleaf.html#extrathyme-a-website-for-thymelands-football-league)处理<分数:标题attr =“...” – 2014-12-06 19:28:21
@PatrickLC这个例子并不完全符合我的代码,因为使用AbstractMarkupSubstitutionElementProcessor和AbstractAttributeModifierAttrProcessor而不是AbstractProcessor。 – 2014-12-07 11:30:40
也许,你忘了注册方言...就像:'SpringTemplateEngine engine = new SpringTemplateEngine(); engine.addDialect(新的FormDialect());' – 2014-12-08 14:47:50