【问题标题】:Thymeleaf: read atributes from custom tagThymeleaf:从自定义标签中读取属性
【发布时间】:2014-12-13 21:50:41
【问题描述】:

在我目前的春季项目中,如果我有这样的标签:

<thform:form attr1="..." attr2="...">
...
</thform:form>

由这个百里香处理器处理:

public class Form extends AbstractProcessor {
  @Override
  public ProcessorResult doProcess(Arguments arguments,ProcessorMatchingContext context,Node node) {
    Element form = new Element("form");
    form.setProcessable(true);
    form.setAttribute("role", "form");
    form.setAttribute("class", "form");
    form.setAttribute("action", "");
    form.setAttribute("method", "post");
    node.getParent().insertBefore(node, form);
    return ProcessorResult.OK;
  }

  @Override
  public int getPrecedence() {
    return 0;
  }

  @Override
  public IProcessorMatcher<? extends Node> getMatcher() {
    return new ElementNameProcessorMatcher("form");
  }
}

我如何读取attr1 和attr2 的值?

【问题讨论】:

    标签: spring thymeleaf


    【解决方案1】:

    我发现可以这样做:

    Element parent = (Element) node;
    setAction( parent.getAttributeValue("action") );
    

    在这种情况下,action 是处理器类的一个属性。

    【讨论】:

      猜你喜欢
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 2021-05-25
      • 1970-01-01
      相关资源
      最近更新 更多