Struts 2
  1. Struts 2
  2. WW-2923

Allow validator parameters to be set via OGNL rather than hard coding in XML

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.2
    • Fix Version/s: 2.3.12
    • Component/s: XML Validators
    • Labels:
      None
    • Environment:

      Standard

    • Flags:
      Patch

      Description

      I have been experimenting with a softer way to perform validations. I like the idea of externalizing the validations in XML, however, it would be more flexible if the parameters could be "set" using matches from the ValueStack rather than requiring them to be hardcoded in the XML. I have drilled into the validator creation and believe that the ValidatorConfig.Builder(ValidatorConfig cfg) might be the place to check for ${foo}. There are many other places in the framework where this string is searched for and its content replaced by using an OGNL search.

      In my current use case, I am fetching valid ranges from a database according to user inputs. These varying integers are what I would like to use as my min and max values. I realize I could use an expression type validation or just code the validation inside my action. However, it doesn't seem natural to be forced into an alternative technique with the ValueStack being so central to the framework. It seems that if the value stack can be used for the validator message "Age must be between ${min} and ${max}" it should also be available for fetching constraints.

      <field name="age">
      	<field-validator type="int">
      		<param name="min">${minLimit}</param>
      		<param name="max">${maxLimit}</param>
      		<message>Age must be between ${minLimit} and ${maxLimit}</message>
      	</field-validator>
      </field>
      

      Peace,
      Scott

        Activity

        Hide
        Wes Wannemacher added a comment -

        you can use OGNL the way you want, but the validator is atop the value stack, not the action... Can you check to see if you add minLimit and maxLimit properties that they can be accessed.

        Show
        Wes Wannemacher added a comment - you can use OGNL the way you want, but the validator is atop the value stack, not the action... Can you check to see if you add minLimit and maxLimit properties that they can be accessed.
        Hide
        Lukasz Lenart added a comment -

        It should be already solved, need to double check

        Show
        Lukasz Lenart added a comment - It should be already solved, need to double check
        Hide
        Lukasz Lenart added a comment -

        It isn't implemented, but there is a bit of work as each validator must be refactored.

        Show
        Lukasz Lenart added a comment - It isn't implemented, but there is a bit of work as each validator must be refactored.
        Hide
        Hudson added a comment -

        Integrated in Struts2-JDK6 #599 (See https://builds.apache.org/job/Struts2-JDK6/599/)
        WW-2923 adds better support for generics (Revision 1428071)

        Result = SUCCESS
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
        Show
        Hudson added a comment - Integrated in Struts2-JDK6 #599 (See https://builds.apache.org/job/Struts2-JDK6/599/ ) WW-2923 adds better support for generics (Revision 1428071) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
        Hide
        Hudson added a comment -

        Integrated in Struts2-JDK6 #606 (See https://builds.apache.org/job/Struts2-JDK6/606/)
        WW-2923 adds support to be Locale independent (Revision 1431122)
        WW-2923 refactors validators to use dedicated params to define expressions (Revision 1431115)

        Result = SUCCESS
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java

        lukaszlenart :
        Files :

        • /struts/struts2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl
        • /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/DoubleValidationAction-validation.xml
        • /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-24.txt
        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java
        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java
        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DoubleRangeFieldValidator.java
        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java
        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java
        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
        • /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java
        • /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java
        • /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java
        • /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java
        • /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java
        • /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java
        • /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java
        Show
        Hudson added a comment - Integrated in Struts2-JDK6 #606 (See https://builds.apache.org/job/Struts2-JDK6/606/ ) WW-2923 adds support to be Locale independent (Revision 1431122) WW-2923 refactors validators to use dedicated params to define expressions (Revision 1431115) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java lukaszlenart : Files : /struts/struts2/trunk/core/src/main/resources/template/xhtml/form-close-validate.ftl /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/DoubleValidationAction-validation.xml /struts/struts2/trunk/core/src/test/resources/org/apache/struts2/views/jsp/ui/Formtag-24.txt /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/AbstractRangeValidator.java /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidator.java /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/DoubleRangeFieldValidator.java /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidator.java /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidator.java /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java /struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidator.java /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/config/providers/MockConfigurationProvider.java /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/DoubleRangeValidatorTest.java /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/DateRangeFieldValidatorTest.java /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/IntRangeFieldValidatorTest.java /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/LongRangeFieldValidatorTest.java /struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/validators/ShortRangeFieldValidatorTest.java
        Hide
        Lukasz Lenart added a comment -

        All the sub-tasks are done so this also is finished

        Show
        Lukasz Lenart added a comment - All the sub-tasks are done so this also is finished

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Scott Stanlick
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development