2016-11-15 17 views
0

是否有可能与thymeleaf检索输入“生成”的名称属性?thymeleaf如何获得输入支持bean生成的名称属性

我需要创建一个id等于输入名称属性的div。 输入名称通过th:字段生成。

标记:

<input type="radio" id="winterTiresInstalled" th:field="*{winterTiresInstalled.value}" />

生成的标记:

<input id="fld_winterTires" type="radio" name="vehicle.winterTiresInstalled.value" />

我想要什么:

<div th:id="???" />

获得:

<div id="vehicle.winterTiresInstalled.value" />

所以,我怎么能检索生成的名称属性值 “vehicle.winterTiresInstalled.value” 与thymleaf?

我可以在js中完成,但我更愿意在我的模板中完成它。

谢谢。 David

+0

name属性似乎是由类SpringInputRadioFieldAttrProcessor.doProcess方法(String name = bindStatus.getExpression();)生成的。我们如何检索百里香的sp​​ring-mvc bindStatus? – user2069716

+0

使用thymeleaf 2.1.4.RELEASE和spring-mvc 4.3.3.RELEASE – user2069716

回答

0

th-attr最适合这个用例。

<a href="#" th:attr="data-id=${object.getId()}, data-name=${object.getName()}"/> 

以上将导致是这样(没有测试)

<a href="#" data-id="420" data-name="user-link"/> 
+0

我没有访问getName方法的权限。我无法控制如何在我的输入上生成名称属性。它似乎是由spring-mvc BindStatus生成的。它使用backing bean路径来生成名称。我想用thymeleaf访问bindStatus.getExpression()。 – user2069716

0

难道JavaScript中的解决方案了。我在页面加载后更改div的id。 我宁愿直接在我的模板中做,但不能找出一种方法来与百里香一起做。

相关问题