Struts html:select multiple option
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Akhil_Gupta
Posted On:   Tuesday, February 22, 2005 04:45 PM

Hi I am facing difficulty with using multiple option with html:select button, how do we pass mutiple selected values from a html:select in jsp, i searched the internet and found that i need to have String[] array as the property for getting and setting values for this, is that correct, i tried that but now i don't know how to get values from String[] arrays in html:select it is saying label not found although i am able to do with getting with List object, is it possible i do a getter with List and setter with String array , i tried that but it is not working , Failed to obtain specified collection is the exception i am getting. Can somebody please help , please show some code or links on net to tackle this I am using like this:    More>>

Hi
I am facing difficulty with using multiple option with html:select button, how do we pass mutiple selected values from a html:select in jsp, i searched the internet and found that i need to have String[] array as the property for getting and setting values for this, is that correct, i tried that but now i don't know how to get values from String[] arrays in html:select it is saying label not found although i am able to do with getting with List object, is it possible i do a getter with List and setter with String array , i tried that but it is not working , Failed to obtain specified collection is the exception i am getting. Can somebody please help , please show some code or links on net to tackle this


I am using like this:





--- where userroles is the String array



Thanks so much

   <<Less

Re: Struts html:select multiple option

Posted By:   Ashok_Pokharkar  
Posted On:   Monday, February 28, 2005 11:23 PM

Hi Akhil ,


One option to solve your problem is :
if possible use JavaScript to make the selected entries true for the multiple entries u had made in that select list.



make it selected by using Java-script first by calling javascript function before any action OR with that action . Pass your HTML:SELECT property (name) to this function:



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.Thus u get the selected entries.

Re: Struts html:select multiple option

Posted By:   Ashok_Pokharkar  
Posted On:   Monday, February 28, 2005 11:21 PM

Hi Akhil ,


One option to solve your problem is :
if possible use JavaScript to make the selected entries true for the multiple entries u had made in that select list.



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.



thus u get the sle

Re: Struts html:select multiple option

Posted By:   Rajneesh_Gupta  
Posted On:   Wednesday, February 23, 2005 04:05 AM

Have seperate string arrays
One string array to populate the list box.(arrPop)
And the other for the multiple selection.(arrSel)

Note - U need to have setter and getter methods for the string arrays in your form bean.






Iterate through the selection array(arrSel) to retrieve the values.

Re: Struts html:select multiple option

Posted By:   Kesavan_Nath  
Posted On:   Tuesday, February 22, 2005 09:52 PM

Hi,
Are u passing a vector from ur action class??If so add the elements like,


In the Action Class,
someVector.add(new LabelValueBean("someString","someString))
request.setAttribute("files",someVector);


In the Action Form,
private String[] _nameArray;
public String[] getVectList() {
return this._nameArray;
}
public void setVectList(String[] vecList) {
this._nameArray = vecList;
}


In the JSP,Try this





For me this worked...;)
About | Sitemap | Contact