Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-1766

[validator] Nice to have: current index in validwhen rule

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.2.2
    • Future
    • Core
    • None
    • Operating System: All
      Platform: All
    • 23351

    Description

      The 'validwhen' rule defines the literal this, which contains the
      value of the field currently being tested.

      It would be nice to have something like this.index or [].count, which
      contains the index of the property being tested.

      That way, I could, for example, create a rule that applies to every
      other indexed property:

      <var-value>((this.index % 2 == '0') and (this != null))</var-value>

      .. or, I could create a more meaniningful validation message, such as:

      "Employment #2: must specify a start date for primary employer 'Motown Music'."

      .. using something like:

      <field property="startDate" indexedListProperty="emps" depends="validwhen">
      <msg name="validwhen" key="errors.startdate.required" />
      <arg0 property="this.index"/>
      <arg1 property="emps[].employerName"/>
      <var>
      <var-name>test</var-name>
      <var-value>(((this.index == '0') and (this != null)) or (this.index
      == '0'))</var-value>
      </var>
      </field>

      There is actually another enhancement disguised in the above. Currently,
      arg0-arg3 only accept the attribute 'key'. I suggest adding another
      attribute called 'property' (for example) that allows me to pass values
      of indexed properties as message params. You should be allowed to use
      this or a similar attribute to pass the index value (this.index) too.

      While I'm at it, here's another suggestion too – how about an 'invalidwhen'
      rule. So that I don't have to have ugly rules like the above:

      <var-value>(((this.index == '0') and (this != null)) or (this.index !
      = '0'))</var-value>

      .. If I had a 'invalidwhen' rule, I could use the following instead:

      ((this.index == '0') and (this == null))

      Just a few suggestions. Let me know what you think.

      -jim

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dprantzalos@yahoo.com Jim Prantzalos
              Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: