2010-09-22 52 views
3

我使用Apache Tiles 2.1作爲我的模板框架(與Spring MVC一起)。Apache Tiles使用<put-attribute>設置html標記屬性值

我想知道如何最好地從我的瓷磚定義文件中設置HTML屬性值。例如,我有一個文本框,並希望能夠在我的定義中設置maxlength屬性。我希望下面的工作 - 使用這個定義

<input id="nameField" type="text" 
    maxlength="<tiles:insertAttribute name='maxlength' />" /> 

-

<definition name="sprint-goal" > 
     <put-attribute name="maxlength" value="100" /> 
</definition> 

但似乎瓷磚忽略< insertAttribute/>標籤如果放在一個HTML標籤內。否則它工作正常。

注意:我已經嘗試使用ViewPreparer來設置請求範圍的值。這將工作,但不是我正在尋找。我想從Tiles定義中輕鬆設置HTML屬性值。

回答

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

I型沒有被定義爲「串」將它視爲一個URL包括...

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/JSPIntro7.html