Apache Tiles 使用设置 html 标签属性价值
我使用 Apache Tiles 2.1 作为我的模板框架(以及 Spring MVC)。
我想知道如何最好地从 Tiles 定义文件中设置 HTML 属性值。例如,我有一个文本框,希望能够在我的定义中设置 maxlength 属性。我期望以下内容能够工作 -
<input id="nameField" type="text"
maxlength="<tiles:insertAttribute name='maxlength' />" />
使用这个定义 -
<definition name="sprint-goal" >
<put-attribute name="maxlength" value="100" />
</definition>
但 Tiles 似乎忽略了
注意:我尝试使用 ViewPreparer 来设置请求范围的值。这会起作用,但不完全是我想要的。我想在 Tiles 定义中轻松设置 HTML 属性值。
I am using Apache Tiles 2.1 as my templating framework (along with Spring MVC).
I want to know how best to be able to set HTML attribute values from within my Tiles definitions file. For example I have a text box and want to be able to set the maxlength attribute from within my definition. I expected the following to work -
<input id="nameField" type="text"
maxlength="<tiles:insertAttribute name='maxlength' />" />
using this definition -
<definition name="sprint-goal" >
<put-attribute name="maxlength" value="100" />
</definition>
But it seems that Tiles ignores the <insertAttribute/> tag if placed within a HTML tag. It works fine otherwise.
Note: I have tried using a ViewPreparer to set request-scoped values. This will work but is not exactly what I am looking for. I would like to easily set HTML attribute values from within a Tiles definition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要设置 html 元素属性的值,最好的选择是使用表达式语言。首先,使用tiles useAttribute 标签将tile 属性公开为java 变量。然后使用“${}”打印变量。
示例:
更多信息:
- 2014 年 6 月更新:https://tiles.apache。 org/2.2/framework/tiles-jsp/tlddoc/tiles/useAttribute.html
- http://docs.oracle.com/javaee/1.4/tutorial/ doc/JSIntro7.html
To set the value of html element attributes, your best bet is to use Expression Language. First, expose the tile attribute as a java variable using the tiles useAttribute tag. Then use '${}' to print the variable.
Example:
More info:
- updated June 2014: https://tiles.apache.org/2.2/framework/tiles-jsp/tlddoc/tiles/useAttribute.html
- http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html
我输入的内容未定义为“字符串”,它将被视为要包含的 URL...
I type isn't defined as "string" it would be taken as a URL to include...