Récupération formulaire null
Bonjour à tous,
J'ai des problème lors de la récupération d'un formulaire avec Struts2... lorsque je valide ce formulaire, je suis normalement redirigé vers l'action et la méthode concernée, mais là mes variables sont toujours à null et je n'arrive pas à trouver ce qui cloche (malgré de multiples recherches sur le web).
Voilà mon code :
Action : (j'ai commencé par la faire extends ActionSupport et sans le Serializable, mais même résultat)
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 66
|
/**
* Action for the service management.
* @author PBO11082
*
*/
public class ServiceAdminAction implements Action, Serializable {
/** serialVersionUID. */
private static final long serialVersionUID = -7065593870222917624L;
/** List of object for services. */
private List<ServiceAdmin> serviceList;
/**
* Default constructor.
*/
public ServiceAdminAction() {
}
@Override
public String execute() throws Exception {
return SUCCESS;
}
/**
* Method to get and display the list of Service.
* @return
* @throws Exception
*/
public String list() throws Exception {
serviceList = new ArrayList<ServiceAdmin>();
//Ici mon traitement pour remplir ma liste, tout est ok ensuite à l'affichage
return SUCCESS;
}
/**
* Method to save the new status of services.
* @return
* @throws Exception
*/
public String save() throws Exception {
//Ici mon traitement pour sauvegarder les valeurs en BDD...
//Sauf que serviceList est toujours à null !
return SUCCESS;
}
/**
* @return serviceList
*/
public List<ServiceAdmin> getServiceList() {
return serviceList;
}
/**
* @param serviceList serviceList à définir
*/
public void setServiceList(List<ServiceAdmin> serviceList) {
this.serviceList = serviceList;
}
} |
Configuration Struts
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
|
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<global-results>
<result name="error">/pages/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>
</package>
<package name="service" extends="default" namespace="/service">
<action name="list" class="administration.action.ServiceAdminAction" method="list">
<result>/pages/services/index.jsp</result>
</action>
<action name="save" class="administration.action.ServiceAdminAction" method="save">
<result name="input">/pages/services/index.jsp</result>
<result type="redirect">list.action</result>
</action>
</package>
</struts> |
Page jsp :
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
|
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Liste des services</title>
</head>
<body>
<s:form action="save" theme="simple" validate="false" method="post" >
<table>
<tr>
<th>Service</th>
<th>Activé</th>
</tr>
<s:iterator value="serviceList">
<tr>
<td><s:property value="%{serviceName}" /></td>
<td><s:checkbox name="serviceAdmin" value="%{status}" fieldValue="%{status}" /></td>
</tr>
</s:iterator>
</table>
<s:submit value="Enregistrer"/>
</s:form>
</body>
</html> |
Objet ServiceAdmin :
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 ServiceAdmin {
protected String serviceName;
protected Boolean status;
/**
* Gets the value of the serviceName property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getServiceName() {
return serviceName;
}
/**
* Sets the value of the serviceName property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setServiceName(String value) {
this.serviceName = value;
}
/**
* Gets the value of the status property.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isStatus() {
return status;
}
/**
* Sets the value of the status property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setStatus(Boolean value) {
this.status = value;
}
} |
Si quelqu'un a une piste, ce serait très appréciable !
J'ai beau cherché dans des projets d'exemple ou des tutos, tout m'a l'air normal alors je dois rater quelque chose.
N'hésitez pas à me demander plus d'info s'il le faut.