3

我使用 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>

但是如果放置在 HTML 标记中,Tiles 似乎会忽略 <insertAttribute/> 标记。否则它工作正常。

注意:我尝试使用 ViewPreparer 设置请求范围的值。这会起作用,但不完全是我想要的。我想从 Tiles 定义中轻松设置 HTML 属性值。

4

2 回答 2

2

要设置 html 元素属性的值,最好的办法是使用表达式语言。首先,使用tiles useAttribute 标记将tile 属性公开为java 变量。然后使用 '${}' 打印变量。

例子:

<tiles:useAttribute name="myMaxLength" id="maxLength" />

<input id="nameField" type="text" maxlength="${myMaxLength}" />

更多信息: - 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

于 2013-01-25T22:21:18.000 回答
0
 <put-attribute name="maxlength" value="100" type="string" />

我键入的内容未定义为“字符串”,它将被视为要包含的 URL...

于 2010-11-08T18:33:11.550 回答