Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Tiles set html tag attribute using <put-attribute> value

Tags:

apache

tiles2

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.

like image 718
wr1472 Avatar asked Aug 27 '26 23:08

wr1472


1 Answers

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

like image 200
tkane2000 Avatar answered Aug 30 '26 12:08

tkane2000