Using custom data attribute in Struts 2 s:select

wh0 picture wh0 · Nov 19, 2012 · Viewed 8.5k times · Source

I'm trying to use custom data attributes of HTML in Struts2 tags here is my sample code

<s:select list="myList" listKey="myListVal"  listValue="myListDesc"  data-inputs="myListInput" ></s:select>

i was expecting something like this for example

<select >
     <option value="myListVal1" data-inputs="myListInput1">myListDesc1</option>
     <option value="myListVal2" data-inputs="myListInput2">myListDesc2</option>
     <option value="myListVal3" data-inputs="myListInput3">myListDesc3</option>
</select>

instead I'm getting this

<select data-inputs="myListInput" >
     <option value="myListVal1" >myListDesc1</option>
     <option value="myListVal2" >myListDesc2</option>
     <option value="myListVal3" >myListDesc3</option>
</select>

Is it possible to describe data-attribute in struts select tags for Options inside it.

Answer

Aleksandr M picture Aleksandr M · Nov 19, 2012

Override the <s:select> tag template. Or just use HTML tags with <s:iterator>

<select name="list">
   <s:iterator value="myList" status="stat">
      <option value="<s:property value="myListVal"/>" data-inputs="myListInput<s:property value="#stat.index"/>"><s:property value="myListDesc"/></option>
   </s:iterator>
</select>