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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| //extrait de ma vue : test.jsp
<html:form action="operations" focus="reference">
<table align="center">
<tr>
<td>
<bean:message key="libelle.reference"/> :
</td>
<td>
<html:text property="reference"/>
</td><br/>
<td>
<bean:message key="libelle.quantite"/> :
</td>
<td>
<html:text property="quantite"/>
</td><br/>
<td>
<bean:message key="libelle.montant"/> :
</td>
<td>
<html:text property="montant"/>
</td><br/>
</tr>
<tr>
<td colspan="2" align="center">
<html:submit value="ajouter" />
</td>
</tr>
</table>
<table align="center" border="0">
<thead align="center">
<th> </th>
<th><bean:message key="libelle.reference"/></th>
<th><bean:message key="libelle.quantite" /> </th>
<th><bean:message key="libelle.montant" /> </th>
</thead>
<tbody>
<tr><td align="center">
<c:forEach items="${sessionScope.liste}" var="elem">
<c:out value="${elem}"/><br/>
</c:forEach>
</td></tr>
<tr><td align="center"><bean:message key="Liste.Number" /></td><td align="center"><input type="text" align="center" value="<c:out value="${sessionscope.taille}"/>"/></td></tr>
</tbody>
</table>
</html:form>
//mon action
public class action extends org.apache.struts.action.Action {
/* forward name="success" path="" */
private static final String SUCCESS = "Ajouter";
private static final String ECHEC = "";
produit leproduit =new produit();
List<produit> liste=new ArrayList<produit>();
HttpSession session=null;
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionForm StrutsActionForm = (ActionForm)form;
if(Securitywork.isnertelem(StrutsActionForm.getreference(),StrutsActionForm.getmontant(),StrutsActionForm.getmontant())){
session=request.getSession();
liste=Securitywork.getliste();
session.setAttribute("liste",liste);
session.setAttribute("taille",liste.size());
return mapping.findForward(SUCCESS);
}
return mapping.findForward(ECHEC);
}
}
//ma classe securitywork
public class Securitywork {
static produit leproduit =null;
static List<produit> liste=new ArrayList<produit>();
public Securitywork () {
}
public static boolean isnertelem(String a,int b,int c) {
leproduit.setreference(a);
leproduit.setquantite(b);
leproduit.setmontant(c);
liste.add(leproduit);
return true;
}
public static List<produit> getliste(){
return liste;
}
}
//mon fichier struts_config.xml
<action input="/test.jsp" name="ActionForm" path="/operations" scope="session" type="com.myapp.struts.action">
<forward name="Ajouter" path="/test.jsp"/>
</action> |
Partager