Apache Tiles 使用设置 html 标签属性价值

发布于 2024-09-24 23:02:51 字数 611 浏览 1 评论 0原文

我使用 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 似乎忽略了;标签(如果放置在 HTML 标签内)。否则它工作正常。

注意:我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小红帽 2024-10-01 23:02:51

要设置 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

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:

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

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

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

不知在何时 2024-10-01 23:02:51
 <put-attribute name="maxlength" value="100" type="string" />

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

 <put-attribute name="maxlength" value="100" type="string" />

I type isn't defined as "string" it would be taken as a URL to include...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文