RECHERCHER :
COMMUNAUTE MP
Identifiez vous ...
Devenir Membre
J'ai oublié mon MDP
DOMAINE MP
Bavardages
Langages Généraux
Langages Web
Langages DotNet
Autres langages
Dev. Jeux Video
Sécurité
Sys. Exploitation
Graphismes
Logiciels
Réseaux
Bases de données
Méthodologies
Emplois High-tech
Aide juridique
Articles juridiques
FORUM
Index des forums
Ajouter un sujet
Rechercher sujet
Contact Responsable
Devenir modérateur
CHAT MP IRC
Votre pseudo ...
Srv: irc.moteurprog.com
Chan: #MoteurProg
PARTICIPER
Plus de 3500 emplois.
Rechercher un job
Déposez votre CV
Emplois High-tech

Visiteur MP

 problème struts validator

Forum : JSP ET SERVLET
Sous Catégorie : Aucune
Type du sujet : Sujet Normale
FAQ : FAQ JSP ET SERVLET

SUIVI DES SUJETS PAR MAIL

SUIVI PAR MAIL INACTIF

RESOLUTION DU SUJET SUJET RESOLU
BLOQUAGE DU SUJET SUJET ACTIF
APPARTENANCE A LA FAQ N'APPARTIENT PAS A LA FAQ


PAGE : [1]

POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

FORUM JSP ET SERVLET

PREMIERE PAGE

PAGE PRECEDENTE

Page précedente

Page suivante

PAGE SUIVANTE

DERNIERE PAGE
bigguiz
Membre MP
Avatar de bigguiz
Inscrit : 27/07/2006
Messages : 235
Message
#132520
Posté le 04/05/07 à 08:25
Bonjour,

J'essaie d'utiliser struts validator pour vérifier la validité de mes formulaires.
Seulement j'ai un problème assez étrange voici le fichier de configuration du validator:


<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd"> <form-validation> <formset> <!--Validation d'un binding template --> <form name="FullBindingTemplateForm"> <field property="name" depends="required"> <msg name="required" key="updateBindingTemplate.empty"/> <arg position="0" key="displayBindingTemplate.name"/> </field> <field property="description" depends="maxlength "> <msg name="maxlength" key="updateBindingTemplate.tooLong"/> <arg position="0" name="maxlength" key="displayBindingTemplate.description"/> <arg position="1" name="maxlength" key="${var:maxlength}" resource="false"/> <var> <var-name>maxlength</var-name> <var-value>320</var-value> </var> </field> <field name="ip4" depends="required"> <msg name="required" key="updateBindingTemplate.integer"/> <arg position="0" name="required" key="displayBindingTemplate.ip"/> </field> </form> </formset> </form-validation>


J'essaie de valider 3 champs. Sur les deux premiers pas de soucis. En revanche sur le 3eme...

Quand je fais un controle de type "required", validator empéche systèmatiquement la validation du formulaire, même lorsqu'il est bien remplit.

Quand je fais un controle de type "integer", validator valide le formulaire, même si j'entre des lettres dans les champs. Et j'ai également une erreur dans la console: java.lang.IllegalArgumentException: No name specified


20:14:55,734 WARN [PropertyMessageResources] Resource org/apache/struts/validator/LocalStrings_fr_FR.properties Not Found. 20:14:55,734 WARN [PropertyMessageResources] Resource org/apache/struts/validator/LocalStrings_fr.properties Not Found. 20:14:55,734 ERROR [ValidatorAction] Unhandled exception thrown during validation: No name specified java.lang.IllegalArgumentException: No name specified at org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:635) at org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715) at org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290) at org.apache.commons.validator.util.ValidatorUtils.getValueAsString(ValidatorUtils.java:105) at org.apache.struts.validator.FieldChecks.evaluateBean(FieldChecks.java:333) at org.apache.struts.validator.FieldChecks.validateInteger(FieldChecks.java:436) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:543) at org.apache.commons.validator.Field.validateForRule(Field.java:766) at org.apache.commons.validator.Field.validate(Field.java:846) at org.apache.commons.validator.Form.validate(Form.java:290) at org.apache.commons.validator.Validator.validate(Validator.java:354) at org.apache.struts.validator.DynaValidatorForm.validate(DynaValidatorForm.java:117) at org.dgme.rita.web.form.BindingTemplateForm.validate(BindingTemplateForm.java:46) at org.apache.struts.chain.commands.servlet.ValidateActionForm.validate(ValidateActionForm.java:53) at org.apache.struts.chain.commands.AbstractValidateActionForm.execute(AbstractValidateActionForm.java:100) at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:48) at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304) at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190) at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:280) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1858) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:459) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at javax.servlet.http.HttpServlet.service(HttpServlet.java:810) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112) at java.lang.Thread.run(Unknown Source)


J'en déduit que validator ne parvient pas à trouver le troisiéme champ, mais pourquoi?
__________________________
Eoliennes et informatique sur freresguizmo

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Publicité
Inscrit : X
Messages : X
Message
#Aucun

HAUT DE PAGE

  

bigguiz
Membre MP
Avatar de bigguiz
Inscrit : 27/07/2006
Messages : 235
Message
#132536
Posté le 04/05/07 à 10:13
C'est bon j'ai trouvé: il fallait mettre <field property=... et non pas <field name=...
__________________________
Eoliennes et informatique sur freresguizmo

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

david123
Nouveau membre
Inscrit : 30/05/2007
Messages : 5
Message
#134817
Posté le 30/05/07 à 12:17
Ok c bon. peut tu m'envoyer un exemple de page jsp avec appel au validator? Merci

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

bigguiz
Membre MP
Avatar de bigguiz
Inscrit : 27/07/2006
Messages : 235
Message
#134818
Posté le 30/05/07 à 12:45
Voila


<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %> <html:javascript formName="DocumentDescriptionForm" /> <h2><bean:message key="documentDescriptionGeneral.title1"/></h2> <html:errors/> <html:form action="publishDocumentExecute" enctype="multipart/form-data" onsubmit="return validateDocumentDescriptionForm(this);"> <table class="rech-fiche"> <tr> <th><bean:message key="publishDocument.documentType"/></th> <td> <html:select property="type" value="${documentDescription.refDocumentType.documentTypeId}"> <html:options collection="documentTypeList" property="documentTypeId" labelProperty="lbl"/> </html:select> </td> </tr> <tr> <th><bean:message key="publishDocument.label"/></th> <td><html:text property="label" value="${documentDescription.lbl}" maxlength="40"/></td> </tr> <tr> <th><bean:message key="publishDocument.path"/></th> <td><html:file property="file" value="" maxlength="80"></html:file></td> </tr> <tr> <th><bean:message key="publishDocument.comment"/></th> <td><html:textarea property="description" value="${documentDescription.description}"/></td> </tr> <tr> <th><bean:message key="publishDocument.version"/></th> <td><html:text property="version" maxlength="10" value="${documentDescription.version}"/></td> </tr> <tr> <th>&nbsp;</th> <td><html:submit><bean:message key="documentDescriptionGeneral.update"/></html:submit> </td> </tr> </table> </html:form>


Les lignes importantes sont: <html:javascript formName="DocumentDescriptionForm" /> pour inclure les fonction javascrit du validator

<html:errors/> pour qu'il affiche les erreurs

et <html:form action="publishDocumentExecute" onsubmit="return validateDocumentDescriptionForm(this);"> pour lancer l'appel

Peux tu à ton tour mettre le code que tu m'as envoyé en MP pour que la discution soit compréhensible par tous?
__________________________
Eoliennes et informatique sur freresguizmo

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

david123
Nouveau membre
Inscrit : 30/05/2007
Messages : 5
Message
#134826
Posté le 30/05/07 à 13:12
Oui.VOILA BIGGUIZ a répondu au problème suivant
Je veux utiliser validation.xml
moi j'ai fait la régle required(obligatoire) sur deux champs (nom,type). mais rien ne se passe pire encore sans remplir les champs je passe à la page succé.
Pour cela, j'ai:
configuré le struts-config.xml(+plugin)

<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> <struts-config> <!-- ========== Form Bean Definitions =================================== --> <form-beans> <form-bean name="animalForm" type="fr.edition.eni.actionform.AnimalForm"/> </form-beans> <!-- ========== Action Mapping Definitions ============================== --> <action-mappings> <action name="animalForm" path="/InputAnimal" attribute="animal" type="org.apache.struts.actions.ForwardAction" input="/pages/animal.jsp" parameter="/pages/afficheAnimal.jsp"/> </action-mappings> <!-- ======================ressources=========================================================== --> <message-resources parameter="ressources"/> <!-- ======================Plugin validator =====================================================--> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml"/> </plug-in> </struts-config>

j'ai fait hérité le plugin animalform de ValidatorForm

/* * Created on 29 mai 2007 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ package fr.edition.eni.actionform; import org.apache.struts.validator.ValidatorForm; /** * @author brahim * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class AnimalForm extends ValidatorForm{ private String nom; private String type; public String getType(){ return type; } public void setType(String type){ this.type=type; } public String getNom(){ return nom; } public void setNom(String nom){ this.nom=nom; } }

et j'ai mis validation.xml et validator-rules sous web-inf
et j'ai ajouter les conditions au fichier validation.xml

<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"> <form-validation> <formset> <form name="animalForm"> <field property="nom" depends="required"> <arg key="animal.errors.nom"/> </field> <field property="type" depends="required"> <arg key="animal.errors.type"/> </field> </form> </formset> </form-validation>

et mon fichier jsp

<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.0//EN" "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd"> <form-validation> <formset> <form name="animalForm"> <field property="nom" depends="required"> <arg key="animal.errors.nom"/> </field> <field property="type" depends="required"> <arg key="animal.errors.type"/> </field> </form> </formset> </form-validation>

A plus

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

david123
Nouveau membre
Inscrit : 30/05/2007
Messages : 5
Message
#134829
Posté le 30/05/07 à 13:22
ca marche. c top.
juste que l'erreur s'affiche sur une autre fenetre, mois je veux que l'erreur s'affiche sur la meme page que le formulaire. pour cela j'ai mis le tag suivant mais ca marche pas:

<%@ taglib uri="/tags/struts-html" prefix="html" %> <%@ taglib uri="/tags/struts-bean" prefix="bean" %> <%@ taglib uri="/tags/struts-logic" prefix="logic" %> <%@ taglib uri="/tags/struts-nested" prefix="nested" %> <html:html> <head> <title><bean:message key="animal.titre"/></title> </head> <body bgcolor="white"> <html:errors /> <html:form action="/InputAnimal" onsubmit="return validateAnimalForm(this);"> <bean:message key="animal.nom"/> <html:text property="nom"/> <html:errors property="nom"/> <br> <bean:message key="animal.type"/> <html:text property="type"/> <html:errors property="type"/> <br> <html:submit/> </html:form> <html:javascript formName="AnimalForm"/> </body> </html:html>

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

bigguiz
Membre MP
Avatar de bigguiz
Inscrit : 27/07/2006
Messages : 235
Message
#134850
Posté le 30/05/07 à 15:53
Je comprends pas ton problème...

Normalement l'erreur s'affiche d'abord dans une popup javascript puis, si l'erreur est trop complexe pour être traitée coté client, ou si le javascript et désactivé, l'erreur s'affiche dans ta page html.

Si tu ne veux pas de controles javascript, il faut configurer le plugin validator je ne sais plus comment.
__________________________
Eoliennes et informatique sur freresguizmo

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

david123
Nouveau membre
Inscrit : 30/05/2007
Messages : 5
Message
#134853
Posté le 30/05/07 à 16:04
Ce que je veux c après l'affichage sur popup javascript, on a un affichage sur ma page html.

en fait pour ta solution de desactivé le javascript. ta stp une idée comment le faire?

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

bigguiz
Membre MP
Avatar de bigguiz
Inscrit : 27/07/2006
Messages : 235
Message
#134857
Posté le 30/05/07 à 16:21
Non désolé j'ai laissé la config par défaut.

Tu devrais aller voir sur le site de struts pour chercher les différentes configurations possibles (et aprés mettre la solution sur le forum).
__________________________
Eoliennes et informatique sur freresguizmo

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

david123
Nouveau membre
Inscrit : 30/05/2007
Messages : 5
Message
#134859
Posté le 30/05/07 à 16:34
OK je vais chercher de mon coté. Merci. A plusSmiley

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 
POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

PREMIERE PAGE

PAGE PRECEDENTE Page précédente

Page suivante

PAGE SUIVANTE DERNIERE PAGE

FORUM JSP ET SERVLET



    PAGE : [1]



.: Site Web développé par Julien Pichot et l'équipe MPWG avec www.evolvia-web.com :.