문제

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

도움이 되었습니까?

해결책

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> 

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top