 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Curtis Flam Guest
|
Posted: Fri Feb 16, 2007 8:10 am Post subject: [STRUTS] Pb with index properties to retrieve values from a |
|
|
Hi, here is my problem : I'm displaying an html table, and for each row
there is a checkbox; I would like to know what checkboxes have been checked
when user submits the form.
In my class form I created a java.util.List object to store the value of
each checkbox; but at runtime I get an exception BeanUutils.populate ... (I
forgot the stack trace, I can't show it)
Before I add the checkboxes in my form, all was good; then I displayed the
checkboxes with a predefined value (checked/unchecked) and it was ok. But it
bugs when user checks/unchecks checkboxes and submits the form.
Thanks for your answers
Here are samples of code
Class containing the form :
***********************************************************
public class RechercheForm extends ActionForm {
private String site;
private Integer nbResultats;
private List<SiteLigne> resultats;
public List<SiteLigne> getResultats() {
return resultats;
}
public void setResultats(List<SiteLigne> resultats) {
this.resultats = resultats;
}
public SiteLigne getResultats(int i) {
return resultats.get(i);
}
public void setResultats(SiteLigne siteLigne, int index) {
if(this.resultats == null){
this.resultats = new ArrayList();
}
while(index >= this.resultats.size()){
this.resultats.add(new SiteLigne());
}
this.resultats.set(index, siteLigne);
}
// + validate() et reset() and get() et set() methods
********************************************************
JSP containing the form (liste.jsp):
********************************************************
....
<html:form action="/afficheSuppression">
<html:text property="site"/>
<logic:present name="rechercheForm" property="resultats">
<bean:size id="nbresultats" name="rechercheForm" property="resultats"/>
<logic:equal name="nbresultats" value="0">No results</logic:equal>
<logic:greaterThan name="nbresultats" value="0">
<table width="600" border="1" align="center" cellpadding="0"
cellspacing="0" class="Ta">
<logic:iterate id="temp" name="rechercheForm"
property="resultats" indexId="compteur">
<tr>
<td ><html:checkbox property='<%= "resultats[" +
compteur + "].selected" %>'/></td>
<td ><bean:write name="temp"
property="descritpion"/></td>
</tr>
</logic:iterate>
</table>
Supprimer : <html:submit/>
....
********************************************************
Action class:
********************************************************
public class AfficheSuppressionAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RechercheForm rechercheForm = (RechercheForm) form;
String site = rechercheForm.getSite();
System.out.println("site : " + site);
System.out.println("Sites selectionnes : ");
List<SiteLigne> selection= rechercheForm.getResultats();
System.out.println("Sites selectionnes : ");
for(SiteLigne temp : selection) {
if(temp.isSelected()) {
System.out.println(temp.getNom());
}
}
return mapping.findForward("afficheSuppression");
}
}
********************************************************
Strutsconfig.xml sample :
********************************************************
- <struts-config>
- <form-beans>
<form-bean name="rechercheForm" type="RechercheForm" />
</form-beans>
<global-exceptions />
- <global-forwards/>
- <action-mappings>
-
- <action attribute="afficheSuppressionForm" input="/site/liste.jsp"
name="rechercheForm" path="/afficheSuppression" scope="request"
type="AfficheSuppressionAction" validate="false">
<forward name="afficheSuppression" path="/site/suppression.jsp" />
</action>
</action-mappings>
</struts-config>
******************************************************** |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|