[Struts-Layout] insertion des éléments selectionnés
Bonsoir,
dans ma jsp , j'ai un datagrid :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <%@ taglib uri="/WEB-INF/struts-layout.tld" prefix="layout" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<layout:html>
<layout:form action="/datagrid" styleClass="FORM">
<layout:row>
<layout:datagrid property="datagrid" selectionAllowed="true" multipleSelectionAllowed="false" styleClass="LIST" model="datagrid">
<layout:datagridColumn title="identifiant" property="identifiant"/>
<layout:datagridColumn title="password" property="passe"/>
<layout:datagridCheckbox title="ok" property="ok"/>
</layout:datagrid>
<layout:column>
<layout:submit reqCode="update" >Save</layout:submit>
</layout:column>
</layout:row>
</layout:form>
</layout:html> |
- le bean :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| public class DatagridForm extends ActionForm {
private Datagrid datagrid;
public Datagrid getDatagrid() {
return datagrid;
}
public void setDatagrid(Datagrid datagrid) {
this.datagrid = datagrid;
}
public DatagridForm() {
ArrayList liste = new ArrayList();
try {
liste = (ArrayList)Dispatcher.getInstance().execute(Dispatcher.LIST_USER_UC);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
datagrid = Datagrid.getInstance();
datagrid.setDataClass(User.class);
datagrid.setData(liste);
}
/*
public class DatagridAction extends DispatchAction {
public ActionForward display(ActionMapping in_mapping, ActionForm in_form, HttpServletRequest in_request, HttpServletResponse in_reponse) {
DatagridForm lc_form = (DatagridForm) in_form;
// Get an object list.
List aList = getAListFromSomwhere();
// Create a datagrid.
Datagrid lc_datagrid = Datagrid.getInstance();
// Set the bean class for new objects. We suppose SomeBean is the class of the object in the List aList.
lc_datagrid.setDataClass(SomeBean.class);
// Set the data
lc_datagrid.setData(aList);
// Initialize the form
lc_form.setDatagrid(lc_datagrid);
// Forward to the jsp.
return in_mapping.findFoward("jsp");
* */
} |
-l'action :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| public class DatagridAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException,ServletException {
DatagridForm lc_form = (DatagridForm) form;
ArrayList alist=new ArrayList();
// Get an object list.
try {
alist = (ArrayList)Dispatcher.getInstance().execute(Dispatcher.LIST_USER_UC);
System.out.println("La taille de la liste"+alist.size());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Create a datagrid.
Datagrid lc_datagrid = Datagrid.getInstance();
// Set the bean class for new objects. We suppose SomeBean is the class of the object in the List aList.
lc_datagrid.setDataClass(User.class);
// Set the data
lc_datagrid.setData(alist);
// Initialize the form
lc_form.setDatagrid(lc_datagrid);
// Forward to the jsp.
return mapping.findForward("success");
}
} |
Je veux que lorsque je selectionne des éléments dans le datagrid (au moyen des layout:datagridCheckbox ) que j'ai mis dans le datagrid, je veux modifier un champs du bean selectionné et l'inserer dans la table.
j'ai par exemple :
user(id,identifiant,passe,accusé) avec(1,aaa,bbb,false)
quand je selectionne des element du datagrid et je clik sur le bouton update, je veux obtenir dans la table de la base de données ainsi que sur le datagrid ça: (1,aaa,bbb,true)
Je ne sais pas comment récupérer les éléments cochés dans le datagrid et les modifier
Merci pour vos aides