struts2 problème validation formulaire
Bonjour à tous,
je suis actuellement en train de tester struts2 en association avec spring et hibernate et je rencontre un problème lorsque je provoque une erreur de validation de formulaire.
Voici le scénario du problème :
- Je rempli le formulaire avec une erreur et je valide le formulaire
- Le message d'erreur s'affiche sur le champ correspondant (normal)
- Je modifie ma saisie pour qu'il n'y ai plus d'erreur et je revalide le formulaire
- L'action n'est plus appelée !!
La classe action concernée contient plusieurs méthodes et est utilisée pour une autre jsp. Une fois l'erreur de validation provoquée, cette classe action n'est plus appelée même sur les autres méthodes qui ne sont pas soumises à la validation. Je précise qu'il ne s'agit pas d'un problème de syntaxe du fichier xml de validation puisque ce scénario se produit même lorsque je provoque une erreur de conversion de type par défaut.
Sinon deuxième problème à part, struts ne m'affiche rien dans la console. Donc si quelqu'un voit pourquoi dans ma config...
Je vous mets les sources de ma configuration :
Struts.xml
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
| <?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" />
<package name="default" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<global-results>
<result name="error" type="tiles">erreur</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception"/>
</global-exception-mappings>
<action name="accueil" class="helloWorldClass">
<result name="success" type="tiles">accueil</result>
</action>
<action name="valider_creer" class="messageAction" method="valider_creer">
<result name="success" type="tiles">list_message</result>
<result name="input" type="tiles">creer_message</result>
</action>
<action name="*_message" class="messageAction" method="{1}">
<result name="success" type="tiles">{1}_message</result>
<result name="input" type="tiles">{1}_message</result>
</action>
<action name="confirm_add_personnage" class="personnageAction" method="confirmAdd">
<result name="success" type="tiles">add_personnage</result>
<result name="input" type="tiles">add_personnage</result>
</action>
<action name="*_personnage" class="personnageAction" method="{1}">
<result name="success" type="tiles">{1}_personnage</result>
<result name="input" type="tiles">{1}_personnage</result>
</action>
</package>
</struts> |
web.xml
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
| <!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>1000</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter>
<filter-name>JpaFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>JpaFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app> |
applicationContext.xml
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
| <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.steria.essaistruts" />
<bean id="project-properties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders">
<value>true</value>
</property>
<property name="locations">
<list>
<value>
classpath*:database.properties
</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
<property name="driverClassName" value="${hibernate.connection.driver_class}"/>
<property name="url" value="${hibernate.connection.url}"/>
<property name="username" value="${hibernate.connection.username}"/>
<property name="password" value="${hibernate.connection.password}"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaDialect">
<bean class="${jpa.dialect}" />
</property>
<property name="jpaVendorAdapter">
<bean class="${jpa.vendor.adapter}">
<property name="showSql" value="${hibernate.show_sql}" />
<property name="databasePlatform" value="${hibernate.dialect}" />
<!-- On ne genere pas la BDD au demarrage -->
<property name="generateDdl" value="true" />
</bean>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="txManager" />
</beans> |
log4j.properties
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| log4j.rootLogger=INFO,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-5p [%t]: %m%n
# Struts2
log4j.logger.freemarker=INFO
log4j.logger.com.opensymphony=INFO
log4j.logger.com.opensymphony.xwork2.ognl=ERROR
log4j.logger.org.apache.struts2=WARN
log4j.logger.org.apache.struts2.components=INFO
log4j.logger.org.apache.struts2.dispatcher=INFO
log4j.logger.org.apache.struts2.convention=INFO |
Ma classe 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 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
| package com.steria.essaistruts.pres.actions;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionSupport;
import com.steria.essaistruts.domaine.modele.Personnage;
import com.steria.essaistruts.metier.IPersonnageService;
@Controller("personnageAction")
public class PersonnageAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
@Autowired
private IPersonnageService personnageService;
private List<Personnage> personnages;
private Personnage personnage;
public IPersonnageService getPersonnageService() {
return personnageService;
}
public void setPersonnageService(IPersonnageService personnageService) {
this.personnageService = personnageService;
}
public List<Personnage> getPersonnages() {
return personnages;
}
public void setPersonnages(List<Personnage> personnages) {
this.personnages = personnages;
}
public Personnage getPersonnage() {
return personnage;
}
public void setPersonnage(Personnage personnage) {
this.personnage = personnage;
}
public String list() {
personnages = personnageService.getAllPersonnages();
return SUCCESS;
}
public String edit() {
String id = ServletActionContext.getRequest().getParameter("id");
personnage = personnageService.getPersonnage(Integer.parseInt(id));
return SUCCESS;
}
public String delete() {
String id = ServletActionContext.getRequest().getParameter("id");
personnageService.deletePersonnage(Integer.parseInt(id));
personnages = personnageService.getAllPersonnages();
return SUCCESS;
}
public String add() {
personnage = new Personnage();
return SUCCESS;
}
public String confirmAdd() {
personnageService.savePersonnage(personnage);
return SUCCESS;
}
} |
Le formulaire
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <s:form method="post" action="confirm_add_personnage">
<s:textfield name="personnage.nom" label="Nom du personnage"/>
<s:textfield name="personnage.pv" label="PV du personnage"/>
<s:textfield name="personnage.mana" label="Mana du personnage"/>
<s:textfield name="personnage.niveau" label="Niveau du personnage"/>
<sx:datetimepicker name="personnage.dateCreation" label="Date de création du personnage" displayFormat="dd/MM/yyyy" />
<s:textfield name="personnage.arme.nom" label="Nom de l'arme" />
<s:textfield name="personnage.arme.degats" label="Dégats de l'arme"/>
<s:iterator value="personnage.vetements">
<s:property value="nom"/><br/>
</s:iterator>
<s:submit value="Valider"></s:submit>
</s:form> |
Merci d'avance pour vos réponses