我使用自定义的Thymeleaf属性处理器将动态内容包含到视图中,该处理器只需在处理属性本身时添加额外的节点。
我使用的代码与下面的代码非常相似:
final Template template = arguments.getTemplateRepository().getTemplate(
new TemplateProcessingParameters(arguments.getConfiguration(), "name-of-a-view", arguments.getContext()));
final List<Node> children = template.getDocument().getChildren();
// Add to the tree.
for (final Node node : children) {
element.addChild(node);
}这可以很好地工作,但是当包含的节点包含使用th:object和th:field的表单时,就会中断。
我将所需的模型放在节点变量map中,实际上th:object确实找到并检索了该对象,但th:field似乎并不关心,它以一个
Neither BindingResult nor plain target object for bean name 'model' available as request attribute根据我的理解(一步一步调试),在我看来th:字段只在请求上下文中搜索模型。
我是不是漏掉了什么?
提前谢谢你。
发布于 2016-02-06 09:19:41
不,你说对了。我仍然不确定为什么th:field的绑定与其他th:属性的绑定不同,但它的工作方式肯定不同。本质上,您不能使用th:field,除非您的th:对象在模型上。解决方法是停止使用th:字段,只需手动指定输入属性,如:
<form action="#" th:action="@{/process}" th:object="${objectFromList}" method="post">
<input type="text" id="fieldName" name="fieldName" th:value="*{fieldName}" />
</form>我意识到这个帖子太老了。希望这能帮助那些遇到这种怪癖的人。
https://stackoverflow.com/questions/24939413
复制相似问题