Hi,

Here is a way to obtain the selected elements of the <html:select> tag:

Imagine JSP page where you set the kind of market sector
(Oil,Telecom,Government,...) of the current compagny you are editing.

In the ActionForm associated with the JSP I have:
        - an attribut listeTypeSociete which is an ArrayList of Bean for all the
kind of market sectors listed in my database (each market sector is a bean)
        - an attribut selectedIdTypeSociete which is a String for the pre-selected
kind of market sectors i get in my JSP when i edit a compagny (the id of the
sector market pre-selected)
        - an attribut socType which is a String for the new selected value of "kind
of market sectors" i will get from my JSP (the id of the sector market newly
selected)

In the JSP I have
        - a <html:select> based on the selectedIdTypeSociete for its value attribut
and whi will set the socType attrubut
        - a <html:options> based on the listeTypeSociete attribut

And it works pretty well:
I retreive in the JSP all the kind of market sectors + the one pre-selected
for this compagny
I receive the new selected king of market through the getSocType() method of
my Action Form.

As an ActionForm can be considered as a Bean I think you should try to do
the same to be able to get the value of the select in a bean : simply give a
"property" corresponding to an attribut of your bean


Bye
Xavier

Here is the code :

____________________________________________________________________________
___
SocieteDetailForm.java

private ArrayList listeSite = new ArrayList();
private String selectedIdTypeSociete = null;
private String socType = null;

////and their getter and setter methods///
____________________________________________________________________________
___
____________________________________________________________________________
___
SocieteDetail.jsp
<TR>
<TD class=Texte width="35%"><B>Choose a compagny </B></TD>
<bean:define name="SocieteDetailForm" property="listeTypeSociete"
id="lidy13"/>
<bean:define name="SocieteDetailForm" property="selectedIdTypeSociete"
id="societeType" type="java.lang.String"/>
<TD colSpan=3>&nbsp;
<html:select size="1" property="socType" value="<%=societeType%>">
   <html:options property="idType" collection="lidy13"
labelProperty="libelleTypeSociete"/>
</html:select>
</TD></TR>
____________________________________________________________________________
___





-----Message d'origine-----
De : Rachel Warburton [mailto:[EMAIL PROTECTED]]
Envoyé : jeudi 26 juillet 2001 17:34
À : Struts-User (E-mail)
Objet : getting all items from a <html:select> to an array bean property


Anyone know how to get all the values from a <html:select> and save them to
a bean property, which is an array?

I already have a solution which uses javascript to get all the values and
save them to a hidden field as one long string to be submit to an
ActionForm, which needs to convert the string to an array of integers.

However, I figure there must be a better way to do this.?

cheers,
Rachel


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


Reply via email to