开发者

Spring Form Taglib and Custom Attributes from Item List

开发者 https://www.devze.com 2023-03-15 09:52 出处:网络
I have a list of items, let\'s say types. I can display a <select> tag like so: <form:select path=\"typeId\" items=\"${types}\" itemLabel=\"name\" itemValue=\"typeId\"/>

I have a list of items, let's say types. I can display a <select> tag like so:

<form:select path="typeId" items="${types}" itemLabel="name" itemValue="typeId"/>

I would like to add the description property from the Type object to a data- attribute on the <option> tag for use with javascript.

This doesn't work, but just to provide an illustration:

<form:select path="typeId"/>
    <form:options items="${types}" itemLabel="name" itemValue="typeId" data-description="description"/>
</form:select>

How can I gain access to the description property to populate the dat开发者_开发问答a-description attribute?


You need to implement your own tag (may on base of form:options), but as far as I know there is no concept of extending tags. (sorry)


data-description is not a valid attribute according to the TLD, so any custom attribute will potentially throw exception.

You can:

  1. Build select and options using standard tag lib using c:forEach OR
  2. Repurpose existing unused attribute for JavaScript. May be "title" attribute?
0

精彩评论

暂无评论...
验证码 换一张
取 消