IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Struts 1 Java Discussion :

[Validator] erreur client+serveur lors de la validation


Sujet :

Struts 1 Java

  1. #1
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut [Validator] erreur client+serveur lors de la validation
    Bonjour à tous,

    je voudrais tester la validation de struts mais je n'y arrive pas

    j'ai lu pas mal de chose sur internet et j'en ai retenu qu'il y avait 3 choses à parametrer :
    - struts-config.xml
    - validation.xml
    - jsp

    voilà ce que j'ai fait :

    struts-config.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    <?xml version="1.0" encoding="UTF-8"?>
    <!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-beans>
        <form-bean name="testForm" type="com.it.framework2.cinematique.DynaValidatorForm">
          <form-property name="test" type="java.lang.String" />
        </form-bean>   
      </form-beans>
      <action-mappings>
        <action name="testForm" include="/GN/jsp/test.jsp" parameter="method" path="/test" type="org.apache.struts.action.Action" validate="true">
          <forward name="success" path="/GN/jsp/test.jsp" />
        </action>
      </action-mappings>
      <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>
    validation.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <?xml version="1.0" encoding="UTF-8"?>
    <!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>
      <global>
      </global>
      <formset>
          <form name="testForm">
           <field property="test" depends="required">
           <arg0 key="test" resource="false"/>
          </field>
        </form>
      </formset>
    </form-validation>
    test.jsp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
    <html:errors/> 
    <html:form action="test.do" method="post" enctype="multipart/form-data" onsubmit="return validateTestFormt(this);">
      <html:javascript formName="testForm" />
      <html:text property="test" value=""></html:text>
      <html:submit title="sumbit" value="ok"></html:submit>
    </html:form>
    Ai-je oublié quelque chose ? Parce que quand je test cette page, la validation ne marche pas

    la validation javascript (coté client) jette l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    required is not defined (Ligne 143)
    la validation java (coté serveur) jette l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    org.apache.struts.util.StrutsValidator
    org.apache.commons.validator.ValidatorException: org.apache.struts.util.StrutsValidator
    	at org.apache.commons.validator.ValidatorAction.loadValidationClass(ValidatorAction.java:646)
    	at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:555)
    	at org.apache.commons.validator.Field.validateForRule(Field.java:827)
    ...
    Quelqu'un saurait me tirer d'affaire ?

    PoichOU

  2. #2
    Membre averti
    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Mai 2003
    Messages
    921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence

    Informations forums :
    Inscription : Mai 2003
    Messages : 921
    Points : 449
    Points
    449
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    html:form action="test.do" method="post" enctype="multipart/form-data" onsubmit="return validateTestFormt(this);">
    Erreur de frappe ?
    Quand on n'a pas d'tête, on a ...

  3. #3
    Membre averti
    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Mai 2003
    Messages
    921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence

    Informations forums :
    Inscription : Mai 2003
    Messages : 921
    Points : 449
    Points
    449
    Par défaut
    Citation Envoyé par PoichOU
    Ai-je oublié quelque chose ? Parce que quand je test cette page, la validation ne marche pas

    la validation javascript (coté client) jette l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    required is not defined (Ligne 143)
    la validation java (coté serveur) jette l'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    org.apache.struts.util.StrutsValidator
    org.apache.commons.validator.ValidatorException: org.apache.struts.util.StrutsValidator
    	at org.apache.commons.validator.ValidatorAction.loadValidationClass(ValidatorAction.java:646)
    	at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:555)
    	at org.apache.commons.validator.Field.validateForRule(Field.java:827)
    ...
    Quelqu'un saurait me tirer d'affaire ?
    Fait voir tes fichiers :
    validator-rules.xml
    MessagesResources.properties
    Quand on n'a pas d'tête, on a ...

  4. #4
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    oui pardon j'ai merdé dans mon copier-coller

    mais c'est pas ça le problème

  5. #5
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    y a pas besoin de MessagesResources.properties ?!


    validator-rules.xml (1ère partie)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    <!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">
    <!--
     
       This file contains the default Struts Validator pluggable validator
       definitions.  It should be placed somewhere under /WEB-INF and
       referenced in the struts-config.xml under the plug-in element
       for the ValidatorPlugIn.
     
          <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
                                                      /WEB-INF/validation.xml"/>
          </plug-in>
     
       These are the default error messages associated with
       each validator defined in this file.  They should be
       added to your projects ApplicationResources.properties
       file or you can associate new ones by modifying the
       pluggable validators msg attributes in this file.
     
       # Struts Validator Error Messages
       errors.required={0} is required.
       errors.minlength={0} can not be less than {1} characters.
       errors.maxlength={0} can not be greater than {1} characters.
       errors.invalid={0} is invalid.
     
       errors.byte={0} must be a byte.
       errors.short={0} must be a short.
       errors.integer={0} must be an integer.
       errors.long={0} must be a long.
       errors.float={0} must be a float.
       errors.double={0} must be a double.
     
       errors.date={0} is not a date.
       errors.range={0} is not in the range {1} through {2}.
       errors.creditcard={0} is an invalid credit card number.
       errors.email={0} is an invalid e-mail address.
     
    -->
     
    <form-validation>
     
       <global>
     
          <validator name="required"
                classname="org.apache.struts.util.StrutsValidator"
                   method="validateRequired"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                      msg="errors.required">
     
             <javascript><![CDATA[
                function validateRequired(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oRequired = new required();
                    for (x in oRequired) {
     
     
                        if ((form[oRequired[x][0]].type == 'text' ||
                             form[oRequired[x][0]].type == 'textarea' ||
                             form[oRequired[x][0]].type == 'select-one' ||
                             form[oRequired[x][0]].type == 'radio' ||
                             form[oRequired[x][0]].type == 'password' ||
                             form[oRequired[x][0]].type == 'hidden') &&
                            (form[oRequired[x][0]].value == '')) {
                            if (i == 0) {
                            	if (form[oRequired[x][0]].type != 'hidden'){
                                	focusField = form[oRequired[x][0]];
                               }else{focusField=null;}
                            }
                            fields[i++] = oRequired[x][1];
                            bValid = false;
                        }
                    }
                    if (fields.length > 0) {
                       if (focusField != null){
                       focusField.focus();}
                       alert(fields.join('\n'));
                    }
                    return bValid;
                }]]>
             </javascript>
     
          </validator>
     
          <validator name="requiredif"
                     classname="org.apache.struts.validator.FieldChecks"
                     method="validateRequiredIf"
                     methodParams="java.lang.Object,
                                   org.apache.commons.validator.ValidatorAction,
                                   org.apache.commons.validator.Field,
                                   org.apache.struts.action.ActionErrors,
                                   org.apache.commons.validator.Validator,
                                   javax.servlet.http.HttpServletRequest"
                     msg="errors.required">
          </validator>
     
          <validator name="minlength"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateMinLength"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.minlength">
     
             <javascript><![CDATA[
                function validateMinLength(form) {
                    var isValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oMinLength = new minlength();
                    for (x in oMinLength) {
                        var field = form[oMinLength[x][0]];
     
                        if (field.type == 'text' ||
                            field.type == 'textarea') {
     
                            var iMin = parseInt(oMinLength[x][2]("minlength"));
                            if ((trim(field.value).length > 0) && (field.value.length < iMin)) {
                                if (i == 0) {
                                    focusField = field;
                                }
                                fields[i++] = oMinLength[x][1];
                                isValid = false;
                            }
                        }
                    }
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    }
                    return isValid;
                }]]>
             </javascript>
     
          </validator>
     
     
          <validator name="maxlength"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateMaxLength"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.maxlength">
     
             <javascript><![CDATA[
                function validateMaxLength(form) {
                    var isValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oMaxLength = new maxlength();
                    for (x in oMaxLength) {
                        var field = form[oMaxLength[x][0]];
     
                        if (field.type == 'text' ||
                            field.type == 'textarea') {
     
                            var iMax = parseInt(oMaxLength[x][2]("maxlength"));
                            if (field.value.length > iMax) {
                                if (i == 0) {
                                    focusField = field;
                                }
                                fields[i++] = oMaxLength[x][1];
                                isValid = false;
                            }
                        }
                    }
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    }
                    return isValid;
                }]]>
             </javascript>
     
          </validator>
     
     
          <validator name="mask"
                classname="org.apache.struts.util.StrutsValidator"
                   method="validateMask"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends="required"
                      msg="errors.invalid">
     
             <javascript><![CDATA[
                function validateMask(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oMasked = new mask();
                    for (x in oMasked) {
                        if ((form[oMasked[x][0]].type == 'text' ||
                             form[oMasked[x][0]].type == 'textarea' ||
                             form[oMasked[x][0]].type == 'password') &&
                            (form[oMasked[x][0]].value.length > 0)) {
                            if (!matchPattern(form[oMasked[x][0]].value, oMasked[x][2]("mask"))) {
                                if (i == 0) {
                                    focusField = form[oMasked[x][0]];
                                }
                                fields[i++] = oMasked[x][1];
                                bValid = false;
                            }
                        }
                    }
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    }
                    return bValid;
                }
     
                function matchPattern(value, mask) {
                   var bMatched = mask.exec(value);
                   if (!bMatched) {
                       return false;
                   }
                   return true;
                }]]>
             </javascript>
     
          </validator>
     
     
          <validator name="byte"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateByte"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.byte"
           jsFunctionName="ByteValidations">
     
             <javascript><![CDATA[
                function validateByte(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oByte = new ByteValidations();
                    for (x in oByte) {
                    	var field = form[oByte[x][0]];
     
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'select-one' ||
    						field.type == 'radio') {
     
    						var value = '';
    						// get field's value
    						if (field.type == "select-one") {
    							var si = field.selectedIndex;
    							if (si >= 0) {
    								value = field.options[si].value;
    							}
    						} else {
    							value = field.value;
    						}
     
                            if (value.length > 0) {
                                if (!isAllDigits(value)) {
                                    bValid = false;
                                    if (i == 0) {
                                        focusField = field;
                                    }
                                    fields[i++] = oByte[x][1];
     
                                } else {
     
    	                            var iValue = parseInt(value);
    	                            if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) {
    	                                if (i == 0) {
    	                                    focusField = field;
    	                                }
    	                                fields[i++] = oByte[x][1];
    	                                bValid = false;
    	                            }
                                }
    						}
     
                        }
                    }
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    }
                    return bValid;
                }]]>
             </javascript>
     
          </validator>
     
     
          <validator name="short"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateShort"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.short"
           jsFunctionName="ShortValidations">
     
             <javascript><![CDATA[
                function validateShort(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oShort = new ShortValidations();
                    for (x in oShort) {
                    	var field = form[oShort[x][0]];
     
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'select-one' ||
                            field.type == 'radio') {
     
                            var value = '';
    						// get field's value
    						if (field.type == "select-one") {
    							var si = field.selectedIndex;
    							if (si >= 0) {
    								value = field.options[si].value;
    							}
    						} else {
    							value = field.value;
    						}
     
                            if (value.length > 0) {
                                if (!isAllDigits(value)) {
                                    bValid = false;
                                    if (i == 0) {
                                        focusField = field;
                                    }
                                    fields[i++] = oShort[x][1];
     
                                } else {
     
    	                            var iValue = parseInt(value);
    	                            if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) {
    	                                if (i == 0) {
    	                                    focusField = field;
    	                                }
    	                                fields[i++] = oShort[x][1];
    	                                bValid = false;
    	                            }
    	                       }
                           }
                        }
                    }
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    }
                    return bValid;
                }]]>
             </javascript>
     
          </validator>
     
     
          <validator name="integer"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateInteger"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.integer"
           jsFunctionName="IntegerValidations">
     
             <javascript><![CDATA[
                function validateInteger(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oInteger = new IntegerValidations();
                    for (x in oInteger) {
                    	var field = form[oInteger[x][0]];
     
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'select-one' ||
                            field.type == 'radio') {
     
                            var value = '';
    						// get field's value
    						if (field.type == "select-one") {
    							var si = field.selectedIndex;
    						    if (si >= 0) {
    							    value = field.options[si].value;
    						    }
    						} else {
    							value = field.value;
    						}
     
                            if (value.length > 0) {
     
                                if (!isAllDigits(value)) {
                                    bValid = false;
                                    if (i == 0) {
    	                                focusField = field;
    	                            }
    						        fields[i++] = oInteger[x][1];
     
                                } else {
    	                            var iValue = parseInt(value);
    	                            if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
    	                                if (i == 0) {
    	                                    focusField = field;
    	                                }
    	                                fields[i++] = oInteger[x][1];
    	                                bValid = false;
    	                           }
                               }
                           }
                        }
                    }
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    }
                    return bValid;
                }
     
                function isAllDigits(argvalue) {
                    argvalue = argvalue.toString();
                    var validChars = "0123456789";
                    var startFrom = 0;
                    if (argvalue.substring(0, 2) == "0x") {
                       validChars = "0123456789abcdefABCDEF";
                       startFrom = 2;
                    } else if (argvalue.charAt(0) == "0") {
                       validChars = "01234567";
                       startFrom = 1;
                    } else if (argvalue.charAt(0) == "-") {
                        startFrom = 1;
                    }
     
                    for (var n = startFrom; n < argvalue.length; n++) {
                        if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
                    }
                    return true;
                }]]>
             </javascript>
     
          </validator>
     
     
          <validator name="long"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateLong"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.long"/>

  6. #6
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    validator-rules.xml (2ème partie)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
     
          <validator name="float"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateFloat"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.float"
           jsFunctionName="FloatValidations">
     
             <javascript><![CDATA[
                function validateFloat(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oFloat = new FloatValidations();
                    for (x in oFloat) {
                    	var field = form[oFloat[x][0]];
     
                        if (field.type == 'text' ||
                            field.type == 'textarea' ||
                            field.type == 'select-one' ||
                            field.type == 'radio') {
     
                        	var value = '';
    						// get field's value
    						if (field.type == "select-one") {
    							var si = field.selectedIndex;
    							if (si >= 0) {
    							    value = field.options[si].value;
    							}
    						} else {
    							value = field.value;
    						}
     
                            if (value.length > 0) {
                                // remove '.' before checking digits
                                var tempArray = value.split('.');
                                var joinedString= tempArray.join('');
     
                                if (!isAllDigits(joinedString)) {
                                    bValid = false;
                                    if (i == 0) {
                                        focusField = field;
                                    }
                                    fields[i++] = oFloat[x][1];
     
                                } else {
    	                            var iValue = parseFloat(value);
    	                            if (isNaN(iValue)) {
    	                                if (i == 0) {
    	                                    focusField = field;
    	                                }
    	                                fields[i++] = oFloat[x][1];
    	                                bValid = false;
    	                            }
                                }
                            }
                        }
                    }
                    if (fields.length > 0) {
                       focusField.focus();
                       alert(fields.join('\n'));
                    }
                    return bValid;
                }]]>
             </javascript>
     
          </validator>
     
     
          <validator name="double"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateDouble"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.double"/>
     
     
          <validator name="date"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateDate"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.date"
           jsFunctionName="DateValidations">
     
             <javascript><![CDATA[
                function validateDate(form) {
                   var bValid = true;
                   var focusField = null;
                   var i = 0;
                   var fields = new Array();
                   oDate = new DateValidations();
                   for (x in oDate) {
                       var value = form[oDate[x][0]].value;
                       var datePattern = oDate[x][2]("datePatternStrict");
                       if ((form[oDate[x][0]].type == 'text' ||
                            form[oDate[x][0]].type == 'textarea') &&
                           (value.length > 0) &&
                           (datePattern.length > 0)) {
                         var MONTH = "MM";
                         var DAY = "dd";
                         var YEAR = "yyyy";
                         var orderMonth = datePattern.indexOf(MONTH);
                         var orderDay = datePattern.indexOf(DAY);
                         var orderYear = datePattern.indexOf(YEAR);
                         if ((orderDay < orderYear && orderDay > orderMonth)) {
                             var iDelim1 = orderMonth + MONTH.length;
                             var iDelim2 = orderDay + DAY.length;
                             var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                             var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                             if (iDelim1 == orderDay && iDelim2 == orderYear) {
                                dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
                             } else if (iDelim1 == orderDay) {
                                dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
                             } else if (iDelim2 == orderYear) {
                                dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
                             } else {
                                dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
                             }
                             var matched = dateRegexp.exec(value);
                             if(matched != null) {
                                if (!isValidDate(matched[2], matched[1], matched[3])) {
                                   if (i == 0) {
                                       focusField = form[oDate[x][0]];
                                   }
                                   fields[i++] = oDate[x][1];
                                   bValid =  false;
                                }
                             } else {
                                if (i == 0) {
                                    focusField = form[oDate[x][0]];
                                }
                                fields[i++] = oDate[x][1];
                                bValid =  false;
                             }
                         } else if ((orderMonth < orderYear && orderMonth > orderDay)) {
                             var iDelim1 = orderDay + DAY.length;
                             var iDelim2 = orderMonth + MONTH.length;
                             var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                             var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                             if (iDelim1 == orderMonth && iDelim2 == orderYear) {
                                 dateRegexp = new RegExp("^(\\d{2})(\\d{2})(\\d{4})$");
                             } else if (iDelim1 == orderMonth) {
                                 dateRegexp = new RegExp("^(\\d{2})(\\d{2})[" + delim2 + "](\\d{4})$");
                             } else if (iDelim2 == orderYear) {
                                 dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})(\\d{4})$");
                             } else {
                                 dateRegexp = new RegExp("^(\\d{2})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{4})$");
                             }
                             var matched = dateRegexp.exec(value);
                             if(matched != null) {
                                 if (!isValidDate(matched[1], matched[2], matched[3])) {
                                     if (i == 0) {
                                         focusField = form[oDate[x][0]];
                                     }
                                     fields[i++] = oDate[x][1];
                                     bValid =  false;
                                  }
                             } else {
                                 if (i == 0) {
                                     focusField = form[oDate[x][0]];
                                 }
                                 fields[i++] = oDate[x][1];
                                 bValid =  false;
                             }
                         } else if ((orderMonth > orderYear && orderMonth < orderDay)) {
                             var iDelim1 = orderYear + YEAR.length;
                             var iDelim2 = orderMonth + MONTH.length;
                             var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                             var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                             if (iDelim1 == orderMonth && iDelim2 == orderDay) {
                                 dateRegexp = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
                             } else if (iDelim1 == orderMonth) {
                                 dateRegexp = new RegExp("^(\\d{4})(\\d{2})[" + delim2 + "](\\d{2})$");
                             } else if (iDelim2 == orderDay) {
                                 dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})(\\d{2})$");
                             } else {
                                 dateRegexp = new RegExp("^(\\d{4})[" + delim1 + "](\\d{2})[" + delim2 + "](\\d{2})$");
                             }
                             var matched = dateRegexp.exec(value);
                             if(matched != null) {
                                 if (!isValidDate(matched[3], matched[2], matched[1])) {
                                     if (i == 0) {
                                         focusField = form[oDate[x][0]];
                                      }
                                      fields[i++] = oDate[x][1];
                                      bValid =  false;
                                  }
                              } else {
                                  if (i == 0) {
                                      focusField = form[oDate[x][0]];
                                  }
                                  fields[i++] = oDate[x][1];
                                  bValid =  false;
                              }
                         } else {
                             if (i == 0) {
                                 focusField = form[oDate[x][0]];
                             }
                             fields[i++] = oDate[x][1];
                             bValid =  false;
                         }
                      }
                   }
                   if (fields.length > 0) {
                      focusField.focus();
                      alert(fields.join('\n'));
                   }
                   return bValid;
                }
     
    	    function isValidDate(day, month, year) {
    	        if (month < 1 || month > 12) {
                        return false;
                    }
                    if (day < 1 || day > 31) {
                        return false;
                    }
                    if ((month == 4 || month == 6 || month == 9 || month == 11) &&
                        (day == 31)) {
                        return false;
                    }
                    if (month == 2) {
                        var leap = (year % 4 == 0 &&
                                   (year % 100 != 0 || year % 400 == 0));
                        if (day>29 || (day == 29 && !leap)) {
                            return false;
                        }
                    }
                    return true;
                }]]>
             </javascript>
     
          </validator>
     
    <!-- range is deprecated use intRange instead -->
          <validator name="range"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateIntRange"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends="integer"
                      msg="errors.range">
     
             <javascript><![CDATA[
                function validateRange(form) {
                    return validateIntRange(form);
                }]]>
             </javascript>
     
          </validator>
     
          <validator name="intRange"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateIntRange"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends="integer"
                      msg="errors.range">
     
             <javascript><![CDATA[
                function validateIntRange(form) {
                    var isValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oRange = new intRange();
                    for (x in oRange) {
                        var field = form[oRange[x][0]];
     
                        if ((field.type == 'text' ||
                             field.type == 'textarea') &&
                            (field.value.length > 0)) {
     
                            var iMin = parseInt(oRange[x][2]("min"));
                            var iMax = parseInt(oRange[x][2]("max"));
                            var iValue = parseInt(field.value);
                            if (!(iValue >= iMin && iValue <= iMax)) {
                                if (i == 0) {
                                    focusField = field;
                                }
                                fields[i++] = oRange[x][1];
                                isValid = false;
                            }
                        }
                    }
                    if (fields.length > 0) {
                        focusField.focus();
                        alert(fields.join('\n'));
                    }
                    return isValid;
                }]]>
             </javascript>
     
          </validator>
     
          <validator name="floatRange"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateFloatRange"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends="float"
                      msg="errors.range">
     
             <javascript><![CDATA[
                function validateFloatRange(form) {
                    var isValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oRange = new floatRange();
                    for (x in oRange) {
                        var field = form[oRange[x][0]];
     
                        if ((field.type == 'text' ||
                             field.type == 'textarea') &&
                            (field.value.length > 0)) {
     
                            var fMin = parseFloat(oRange[x][2]("min"));
                            var fMax = parseFloat(oRange[x][2]("max"));
                            var fValue = parseFloat(field.value);
                            if (!(fValue >= fMin && fValue <= fMax)) {
                                if (i == 0) {
                                    focusField = field;
                                }
                                fields[i++] = oRange[x][1];
                                isValid = false;
                            }
                        }
                    }
                    if (fields.length > 0) {
                        focusField.focus();
                        alert(fields.join('\n'));
                    }
                    return isValid;
                }]]>
             </javascript>
     
          </validator>
     
          <validator name="creditCard"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateCreditCard"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.creditcard">
     
             <javascript><![CDATA[
                function validateCreditCard(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oCreditCard = new creditCard();
                    for (x in oCreditCard) {
                        if ((form[oCreditCard[x][0]].type == 'text' ||
                             form[oCreditCard[x][0]].type == 'textarea') &&
                            (form[oCreditCard[x][0]].value.length > 0)) {
                            if (!luhnCheck(form[oCreditCard[x][0]].value)) {
                                if (i == 0) {
                                    focusField = form[oCreditCard[x][0]];
                                }
                                fields[i++] = oCreditCard[x][1];
                                bValid = false;
                            }
                        }
                    }
                    if (fields.length > 0) {
                        focusField.focus();
                        alert(fields.join('\n'));
                    }
                    return bValid;
                }
     
                /**
                 * Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
                 */
                function luhnCheck(cardNumber) {
                    if (isLuhnNum(cardNumber)) {
                        var no_digit = cardNumber.length;
                        var oddoeven = no_digit & 1;
                        var sum = 0;
                        for (var count = 0; count < no_digit; count++) {
                            var digit = parseInt(cardNumber.charAt(count));
                            if (!((count & 1) ^ oddoeven)) {
                                digit *= 2;
                                if (digit > 9) digit -= 9;
                            };
                            sum += digit;
                        };
                        if (sum == 0) return false;
                        if (sum % 10 == 0) return true;
                    };
                    return false;
                }
     
                function isLuhnNum(argvalue) {
                    argvalue = argvalue.toString();
                    if (argvalue.length == 0) {
                        return false;
                    }
                    for (var n = 0; n < argvalue.length; n++) {
                        if ((argvalue.substring(n, n+1) < "0") ||
                            (argvalue.substring(n,n+1) > "9")) {
                            return false;
                        }
                    }
                    return true;
                }]]>
             </javascript>
     
          </validator>
     
     
          <validator name="email"
                classname="org.apache.struts.validator.FieldChecks"
                   method="validateEmail"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                  depends=""
                      msg="errors.email">
     
             <javascript><![CDATA[
                function validateEmail(form) {
                    var bValid = true;
                    var focusField = null;
                    var i = 0;
                    var fields = new Array();
                    oEmail = new email();
                    for (x in oEmail) {
                        if ((form[oEmail[x][0]].type == 'text' ||
                             form[oEmail[x][0]].type == 'textarea') &&
                            (form[oEmail[x][0]].value.length > 0)) {
                            if (!checkEmail(form[oEmail[x][0]].value)) {
                                if (i == 0) {
                                    focusField = form[oEmail[x][0]];
                                }
                                fields[i++] = oEmail[x][1];
                                bValid = false;
                            }
                        }
                    }
                    if (fields.length > 0) {
                        focusField.focus();
                        alert(fields.join('\n'));
                    }
                    return bValid;
                }
     
                /**
                 * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
                 * http://javascript.internet.com
                 */
                function checkEmail(emailStr) {
                   if (emailStr.length == 0) {
                       return true;
                   }
                   var emailPat=/^(.+)@(.+)$/;
                   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
                   var validChars="\[^\\s" + specialChars + "\]";
                   var quotedUser="(\"[^\"]*\")";
                   var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
                   var atom=validChars + '+';
                   var word="(" + atom + "|" + quotedUser + ")";
                   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
                   var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
                   var matchArray=emailStr.match(emailPat);
                   if (matchArray == null) {
                       return false;
                   }
                   var user=matchArray[1];
                   var domain=matchArray[2];
                   if (user.match(userPat) == null) {
                       return false;
                   }
                   var IPArray = domain.match(ipDomainPat);
                   if (IPArray != null) {
                       for (var i = 1; i <= 4; i++) {
                          if (IPArray[i] > 255) {
                             return false;
                          }
                       }
                       return true;
                   }
                   var domainArray=domain.match(domainPat);
                   if (domainArray == null) {
                       return false;
                   }
                   var atomPat=new RegExp(atom,"g");
                   var domArr=domain.match(atomPat);
                   var len=domArr.length;
                   if ((domArr[domArr.length-1].length < 2) ||
                       (domArr[domArr.length-1].length > 3)) {
                       return false;
                   }
                   if (len < 2) {
                       return false;
                   }
                   return true;
                }]]>
             </javascript>
     
          </validator>
     
       </global>
     
    </form-validation>

  7. #7
    Membre averti
    Homme Profil pro
    Consultant en Business Intelligence
    Inscrit en
    Mai 2003
    Messages
    921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Consultant en Business Intelligence

    Informations forums :
    Inscription : Mai 2003
    Messages : 921
    Points : 449
    Points
    449
    Par défaut
    Citation Envoyé par PoichOU
    y a pas besoin de MessagesResources.properties ?!
    Le .properties te permet de gérer le texte de tes messages d'erreur.

    Peut-être n'utilise pas le fichier de base, mais un autre propre à ton développement ?


    Si le validator-rules.xml n'a pas été modifié, alors à priori le problème ne vient pas de là.
    Quand on n'a pas d'tête, on a ...

  8. #8
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    c'est pour le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
          <form name="testForm">
           <field property="test" depends="required">
           <arg0 key="test" resource="false"/>
          </field>
    que tu demandes ça ? parce que le fait de mettre resource="false" indique qu'il n'y a pas besoin de fichier properties. (enfin j'crois)


    cette partie marche bien, quand je regarde le code html généré de ma page jsp je retombe bien sur le mot test

  9. #9
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Voir ma remarque dans la discussion suivante.
    Modératrice Java - Struts, Servlets/JSP, ...

  10. #10
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    j'ai vu ta remarque mais ça ne change rien à mon problème car j'ai déjà le code javascript présent dans ma page

    (d'ailleurs je ne suis pas sur que ça change quelques choses de mettre le <html:javascript /> avant ou après <html:form />)

    PoichOU

  11. #11
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Ah oui, effectivement, comme tu l'avais codé dans le tag html:form, je ne l'avais pas vu. Désolée.

    Sinon, dans l'attribut type de la balise form-bean, tu as codé ceci :
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    <form-bean name="testForm" type="com.it.framework2.cinematique.DynaValidatorForm">
    Normalement, il faut plutôt coder ceci :
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    <form-bean name="testForm" type="org.apache.struts.validator.DynaValidatorForm">
    A moins que com.it.framework2.cinematique.DynaValidatorForm hérite de org.apache.struts.validator.DynaValidatorForm ?
    Modératrice Java - Struts, Servlets/JSP, ...

  12. #12
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    En fait, je pense avoir trouvé d'où vient le problème.

    Tu n'as pas la bonne version du fichier validator-rules.xml car il référence une méthode ActionErrors qui est dépréciée.

    Tu as ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
          <validator name="required"
                classname="org.apache.struts.util.StrutsValidator"
                   method="validateRequired"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionErrors,
                           javax.servlet.http.HttpServletRequest"
                      msg="errors.required">
    et tu devrais avoir ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
          <validator name="required"
                classname="org.apache.struts.util.StrutsValidator"
                   method="validateRequired"
             methodParams="java.lang.Object,
                           org.apache.commons.validator.ValidatorAction,
                           org.apache.commons.validator.Field,
                           org.apache.struts.action.ActionMessages,
                           javax.servlet.http.HttpServletRequest"
                      msg="errors.required">
    Quelle version de Struts utilises-tu ?
    Modératrice Java - Struts, Servlets/JSP, ...

  13. #13
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    oui oui ça étend bien org.apache.struts.validator.DynaValidatorForm

    j'ai quand même remplacé com.it.framework2.cinematique.DynaValidatorForm par org.apache.struts.validator.DynaValidatorForm histoire d'être sur et j'ai la même erreur.

  14. #14
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    As-tu vu mon message précédent ? peut-être pas vu qu'on a posté presque en même temps.
    Modératrice Java - Struts, Servlets/JSP, ...

  15. #15
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    effectivement je n'avais pas vu ton message . j'utilise struts 1.2.7

    j'ai testé de remplacer le validator-rules.xml comme tu dis, mais ça ne change rien

  16. #16
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Tu as modifié le validator-rules.xml ou tu as copié celui livré avec Struts 1.2.7 ?
    Modératrice Java - Struts, Servlets/JSP, ...

  17. #17
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    non je l'ai récupéré de struts-1.2.7-lib.zip, j'ai juste essayé de modifier le doctype mais pas plus de succès...

  18. #18
    Membre habitué Avatar de PoichOU
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2006
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Associations - ONG

    Informations forums :
    Inscription : Juillet 2006
    Messages : 328
    Points : 161
    Points
    161
    Par défaut
    j'ai trouvé !!!!

    mon erreur se situait dans le struts-config j'ai mis include à la place de input :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <action-mappings>
        <action name="testForm" include="/GN/jsp/test.jsp" parameter="method" path="/test" type="org.apache.struts.action.Action" validate="true">
          <forward name="success" path="/GN/jsp/test.jsp" />
        </action>
      </action-mappings>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <action-mappings>
        <action name="testForm" input="/GN/jsp/test.jsp" parameter="method" path="/test" type="org.apache.struts.action.Action" validate="true">
          <forward name="success" path="/GN/jsp/test.jsp" />
        </action>
      </action-mappings>
    j'me foutrais de baffe des fois ... merci beaucoup c_nvy !

    PoichOU

  19. #19
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Ben, il fallait la voir celle-là.
    Modératrice Java - Struts, Servlets/JSP, ...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 1
    Dernier message: 17/02/2014, 16h49
  2. Réponses: 2
    Dernier message: 04/02/2014, 13h18
  3. Réponses: 3
    Dernier message: 25/03/2011, 17h01
  4. [JDOM] Erreur lors de la validation avec XSD
    Par c-ve dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 14/12/2007, 14h22
  5. Facelets et erreur lors de la validation
    Par sir_gcc dans le forum JSF
    Réponses: 2
    Dernier message: 01/05/2007, 15h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo