XWork
  1. XWork
  2. XW-201

visitor validation doesnt work if the object to be validated is null

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.0.1
    • Fix Version/s: 1.2
    • Component/s: Validators
    • Labels:
      None

      Description

      when using a visitor validator on my action that has a property model.name if model is null the validator wont add the error message for model.name

      the exact same action but with the model instanciated works as its supposed to, either instanciated in the class field or if it is submitted using foo.action?model.name=

      public class TestAction extends ActionSupport {
      //public Model model = new Model(); // works with visitor
      public Model model; // doesnt work with visitor

      public Model getModel()

      { return model; }

      public void setModel(Model model)

      { this.model = model; }

      }

      public class Model {
      private String name;

      public String getName()

      { return name; }

      public void setName(String name)

      { this.name = name; }

      }

      TestAction-validation.xml

      <validators>
      <!-- this doesnt work -->
      <field name="model">
      <field-validator type="visitor">
      <message></message>
      </field-validator>
      </field>
      <!-- this works -->
      <!--
      <field name="model.name">
      <field-validator type="requiredstring">
      <message>Name Required</message>
      </field-validator>
      </field>
      -->

      </validators>

      Model-validation.xml

      <validators>
      <field name="name">
      <field-validator type="requiredstring">
      <message>Name Required</message>
      </field-validator>
      </field>
      </validators>

        Activity

        Hide
        tm_jee added a comment -

        marking this as 'won't fix'. Please do comment / reopen if you disagree Francisco.

        Show
        tm_jee added a comment - marking this as 'won't fix'. Please do comment / reopen if you disagree Francisco.
        Hide
        tm_jee added a comment -

        I absolutely agree with Jason, we could maybe print a warning message indicating the model is null and hence visitor validation if it is used will not be functioning. This could be done in VisitorValidator itself and is pretty straight forward to do. Is this ok with you, Francisco ?

        Show
        tm_jee added a comment - I absolutely agree with Jason, we could maybe print a warning message indicating the model is null and hence visitor validation if it is used will not be functioning. This could be done in VisitorValidator itself and is pretty straight forward to do. Is this ok with you, Francisco ?
        Hide
        Jason Carreira added a comment -

        I'm inclined to close this as "will not fix". How can we find the validations for an object if it's null? I suppose with Xwork 2.0 if we make the ModelDriven interface generic we could try to figure out what type it's supposed to be at runtime, but still... I think if you want visitor validations then make sure you've got a Model object. It's just like trying to set values into the properties of the model... if getModel() returns null then you can't set those either.

        Show
        Jason Carreira added a comment - I'm inclined to close this as "will not fix". How can we find the validations for an object if it's null? I suppose with Xwork 2.0 if we make the ModelDriven interface generic we could try to figure out what type it's supposed to be at runtime, but still... I think if you want visitor validations then make sure you've got a Model object. It's just like trying to set values into the properties of the model... if getModel() returns null then you can't set those either.
        Hide
        tm_jee added a comment -

        I suppose we could create a proxy to replace the vistor object, it it is retrived as null. That would solve the bit where the errors are not registered.

        Another problem is, when the model is null for example, and the user key in some valid value, what is to happen? If the method above is implemented, since the model is null, a proxy will be created that just returns null if any property is access, and the error will still exists.

        Pat, Jason, what do you guys think?

        Show
        tm_jee added a comment - I suppose we could create a proxy to replace the vistor object, it it is retrived as null. That would solve the bit where the errors are not registered. Another problem is, when the model is null for example, and the user key in some valid value, what is to happen? If the method above is implemented, since the model is null, a proxy will be created that just returns null if any property is access, and the error will still exists. Pat, Jason, what do you guys think?
        Hide
        Francisco Hernandez added a comment -

        appendPrefix isnt what i needed, i spoke to patrick about this and he said it would be fixed untill 1.1, for now i'll just always instanciate the variable in class like the example i attached works

        Show
        Francisco Hernandez added a comment - appendPrefix isnt what i needed, i spoke to patrick about this and he said it would be fixed untill 1.1, for now i'll just always instanciate the variable in class like the example i attached works
        Hide
        Mark Woon added a comment -

        Francisco,

        What does your JSP page look like? My guess is that you just need to use the "appendPrefix" parameter to the VisitorFieldValidator. See http://wiki.opensymphony.com/display/XW/Standard+Validators#Standard+Validators-VisitorFieldValidator for details.

        Let us know if this does what you want.

        Show
        Mark Woon added a comment - Francisco, What does your JSP page look like? My guess is that you just need to use the "appendPrefix" parameter to the VisitorFieldValidator. See http://wiki.opensymphony.com/display/XW/Standard+Validators#Standard+Validators-VisitorFieldValidator for details. Let us know if this does what you want.
        Hide
        Patrick Lightbody added a comment -

        I have verified your test cases reproduce this issue, but the issue hasn't come up due to a regression, so i'm pushing this out to 1.1

        Show
        Patrick Lightbody added a comment - I have verified your test cases reproduce this issue, but the issue hasn't come up due to a regression, so i'm pushing this out to 1.1
        Hide
        Patrick Lightbody added a comment -

        i'm having a hard time duplicating this in other places. I'll try out your testcase in a bit.

        Show
        Patrick Lightbody added a comment - i'm having a hard time duplicating this in other places. I'll try out your testcase in a bit.

          People

          • Assignee:
            Jason Carreira
            Reporter:
            Francisco Hernandez
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development