Hi everybody (and happy new year :-)
I have a jsp page with multibox. When i check some boxes and submit the
form, then setter of my form is never used ! So i can not get the selected
values, Can anybody help me please ?
I'm using Struts 1.02
thanks for you help,
Marc
Here are my codes :
_______________struts-config.xml :
...
<form-beans>
<form-bean name="exportUtilsForm"
type="cus.baza.action.ExportUtilsForm"/>
...
</form-beans>
....
<global-forwards>
<forward name="choix_export_util" path="/choix_export_util.jsp"/>
...
</global-forwards>
...
<action-mappings>
<action path="/realExportUtil"
type="cus.baza.action.RealiserExportUtilAction"
name="exportUtilsForm"
scope="request"/>
...
</action-mappings>
...
_______________JSP : choix_export_util.jsp:
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
...
<html:form action="/realExportUtil.do" name="exportUtilsForm"
type="cus.baza.action.ExportUtilsForm">
...
<logic:iterate id="annuaire" property="annuaires" name="exportUtilsForm">
<tr align="left">
<td width="100%">
<html:multibox property="selectedAnnuaires">
<bean:write name="annuaire"/>
</html:multibox>
<bean:write name="annuaire"/>
</td>
</tr>
</logic:iterate>
...
</html:form>
_______________ActionForm: ExportUtilsForm.java :
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
public class ExportUtilsForm extends ActionForm {
protected String[] selectedAnnuaires = new String[0]; //{"REF"};
protected String[] annuaires = {"REF", "SIGAGIP", "NT", "EXCHANGE",
"INMS", "TEL", "ORACLE"};
public String[] getSelectedAnnuaires() {
return selectedAnnuaires;
}
public void setSelectedAnnuaires(String[] selectedAnnuaires) {
System.out.println("--------------------->
ExportUtilsForm.setSelectedAnnuaires(selectedAnnuaires)");
this.selectedAnnuaires = selectedAnnuaires;
}
public String[] getAnnuaires() {
return annuaires;
}
public void setAnnuaires(String[] annuaires) {
this.annuaires=annuaires;
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
selectedAnnuaires = new String[0];
annuaires = new String[] {"REF", "SIGAGIP", "NT", "EXCHANGE", "INMS",
"TEL", "ORACLE"};
}
_______________Perfom :
String[] selectedAnnuaires = form.getSelectedAnnuaires();
for (int i=0; i<selectedAnnuaires.length; i++) {
System.out.println("\t\t"+i+" : "+selectedAnnuaires[i]); // Here i
obtain a zero for the length of the array....
}