Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-1967

Dynamic Method Invocation, validator with ActionName-aliasName-validation.xml files.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Not A Problem
    • Affects Version/s: 2.0.6
    • Fix Version/s: 2.3.12
    • Component/s: Core Actions
    • Labels:
      None
    • Environment:

      Fedora 4, tomcat

      Description

      Hello,
      I have been trying to get validation working with dynamic method invocation, using ActionName-aliasName-validation.xml files.

      When the struts.property is set >> struts.enable.DynamicMethodInvocation=true, in the DefaultActionMapper the mapping name is changed by removing !submit from the action eg fieldValidatorsExamples!submit becomes fieldValidatorsExamples. When the validator tries to find FieldValidatorsExampleAction-fieldValidatorsExamples!submit-validator.xml it cannot, as the validator is looking for FieldValidatorsExampleAction-fieldValidatorsExamples-validator.xml. But this is now not linked to a method.

      if (allowDynamicMethodCalls) {
          // handle "name!method" convention.
          String name = mapping.getName();
          int exclamation = name.lastIndexOf("!");
          if (exclamation != -1) {
              mapping.setName(name.substring(0, exclamation)); 
              mapping.setMethod(name.substring(exclamation + 1));
          }
      }
      

      With struts.enable.DynamicMethodInvocation=false, validator works but method name is null.

      This line of code is causing the problem mapping.setName(name.substring(0, exclamation));. Without this line seems to work but I am no expert!

      eg:

      <action name="fieldValidatorsExamples!*" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="{1}" >
          <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
          <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
      </action>
      
      <s:form action="fieldValidatorsExamples!submit" namespace="/validation" method="POST" theme="xhtml">
          <s:textfield label="Required Validator Field" name="requiredValidatorField" />
          <s:textfield label="Required String Validator Field" name="requiredStringValidatorField" />
          <s:textfield label="Integer Validator Field" name="integerValidatorField" />
          <s:textfield label="Date Validator Field" name="dateValidatorField" />
          <s:textfield label="Email Validator Field" name="emailValidatorField" />
          <s:textfield label="URL Validator Field" name="urlValidatorField" />
          <s:textfield label="String Length Validator Field" name="stringLengthValidatorField" />
          <s:textfield label="Regex Validator Field" name="regexValidatorField"/>
          <s:textfield label="Field Expression Validator Field" name="fieldExpressionValidatorField" />
          <s:submit label="Submit" />
      </s:form>
      

      Cheers Greg

        Attachments

        1. patch_WW-1967_xwork_2.txt
          5 kB
          Greg Huber
        2. patch_WW-1967.txt
          1 kB
          Greg Huber

          Activity

            People

            • Assignee:
              lukaszlenart Lukasz Lenart
              Reporter:
              ghuber Greg Huber
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: