1

One thing I learned today is "there is no selected property in

<html:option>

like plain old option" , we can give value in

<html:select>

that matches the value against each option and if match found marks the option selected.

but I want to make multiple options pre-selected on page load(am using

<html:select multiple="true">

How can it be achieved?

GingerHead
  • 8,130
  • 15
  • 59
  • 93
Just_another_developer
  • 5,737
  • 12
  • 50
  • 83
  • http://struts.apache.org/1.x/struts-taglib/tagreference.html#html:select - set `multiple="true"` and pass array to `html:select` – Victor Nov 26 '12 at 23:09

1 Answers1

0

Implement the following:

  1. If possible use JavaScript to make the selected entries true for the multiple entries u had made in that select list
  2. Make it selected by using Java-script first by calling javascript function before any action OR with that action :

function callSelectAll(selectName)  
{   
    var i;  
    for(i=0;i<...) {  
        document.getElementById(selectName).options[i].selected = true;
    }  

}

And use String[] array name as a property name for that html:select property form bean property. And the name of that array as a property of that html:select in jsp page.

You will ultimatly gate the all selected values un the that string array of form bean.

GingerHead
  • 8,130
  • 15
  • 59
  • 93
  • First of all much gratitude .. but I have a scenario that on 'update click', values in this multiSelect component should be set and the value in the form of a list is coming from database. how can I achieve that? Because if I use javascript , values will be set even before fetching from database, as far as I know javascript run first and than java code. – Just_another_developer Aug 31 '12 at 04:42
  • There is no such thing as `JavaScript run first and than java code.` When the JSP page is loaded to the browser already, all java code would have been converted to JavaScript at the servlet engine on the server. so they will be executed equally. – GingerHead Aug 31 '12 at 06:57