<s:select /> - Récupérer les éléments sélectionnés
Bonjour à tous,
J'ai un model comprenant une liste d'objet. Ce modele s'affiche dans un JSP et je peu faire afficher ma liste complete. Par contre j'ai plusieurs bouton dans mon formulaire dont 2 qui supprime ou ajoute des objet a cette liste. Je n,ai pas de problème pour ajouter des objet, mais supprimer je ne sais absolument pa scomment le faire. Je vous donne des boute de code.
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
| <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Client</title>
</head>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<tr>
<td align="center">
<s:form>
<s:hidden name="id" />
<table border="0">
<tr>
<td align="left" valign="top">Urls:</td>
<td align="left" valign="top" colspan="3">
<table border="0" width="100%">
<tr>
<td align="left" width="95%"><s:textfield label="Url" name="url" style="width:100%" /></td>
<td align="left" width="5%">
<s:submit action="ajouterURL" type="image" src="../images/plusicon.gif" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<s:select listKey="id" listValue="url" list="urls" size="5" multiple="true" style="width:100%" />
</td>
<td align="left" valign="top">
<s:submit action="supprimerURL" type="image" src="../images/minus_icon.gif" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right" colspan="4">
<s:if test="action == 'create'">
<s:submit value="Ajouter" action="save" />
</s:if>
<s:else>
<s:submit value="Update" action="update" />
<s:submit value="Delete" action="delete" />
</s:else>
<s:submit value="Cancel" action="cancel" />
</td>
</tr>
</table>
</s:form>
</td>
</tr>
</table>
</body>
</html> |
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 57 58 59 60 61 62 63 64 65
| public class ClientCRUDAction extends ActionSupport implements ModelDriven<Client>, Preparable, ServletRequestAware {
public static final long serialVersionUID = 0L;
private HttpServletRequest request;
private FicheService service = (FicheService)SpringService.getBean("ficheService");
private int id;
private String url, action;
private Client client;
public void prepare() throws Exception {
System.out.println("Call prepare()");
HttpSession session = request.getSession();
if (session.getAttribute("client") == null) {
if (this.id == 0) client = new Client(id); //new Client
else client = service.chargerClientDetailler(id); //load
}
else client = (Client)session.getAttribute("client"); //Modify
printClient(client);
}
public String ajouterURL() {
System.out.println("call ajouterURL()");
Url newUrl = new Url(service.getNextId(Url.class), url, client);
if (client.getUrls().contains(newUrl)) {
int newId = 0;
for (Url current : client.getUrls())
if (current.getId() > newId) newId = current.getId();
newUrl.setId(newId + 1);
}
this.url = "";
client.getUrls().add(newUrl);
request.getSession().setAttribute("client", client);
printClient(client);
return SUCCESS;
}
public String supprimerURL() {
System.out.println("call supprimerURL()");
for (Url current : selectedUrls)
System.out.println(current);
request.getSession().setAttribute("client", client);
printClient(client);
return SUCCESS;
}
public Client getModel() {
return client;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| <package name="client" namespace="/client" extends="struts-default">
<default-interceptor-ref name="defaultStack"/>
<action name="ajouterURL" class="com.myCompagnie.fict.struts.action.ClientCRUDAction" method="ajouterURL">
<result>/jsp/client.jsp</result>
</action>
<action name="supprimerURL" class="com.myCompagnie.fict.struts.action.ClientCRUDAction" method="supprimerURL">
<result>/jsp/client.jsp</result>
<interceptor-ref name="paramsPrepareParamsStack"/>
</action>
</package> |