Question

i have one struts 2 select tag like below.

<s:select list="myList" listKey="myListVal"  listValue="myListDesc"></s:select>

it rendered as below

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

i want to add one more option field with null value

<option value="" ></option>

to the Option field with modification in the list.

In struts 1 it is possible like below

<html:option value=""></html:option>

like that is it possible in the struts 2

note:i couldn't able to modifiy the list before the page load in the java

Was it helpful?

Solution

There is an Attribute called emptyOption in the select tag. It worked as below.

<s:select list="myList" listKey="myListVal"  listValue="myListDesc" emptyOption="true"  ></s:select> 

OTHER TIPS

if you want to add one more option field with null value at the begining of the list you can use headerKey & headerValue attribute of s:select tag.

Check example given below.

<s:select list="myList" listKey="myListVal"  listValue="myListDesc"  headerKey="0" headerValue="" ></s:select>    

So the first element of your list will be empty & it's value will be 0(zero) here.

It will be render as

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

You can set any value on place of 0 (zero).

Hope this will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top