Announcement Announcement Module
Collapse
No announcement yet.
Problem with custom PropertyEditor.... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with custom PropertyEditor....

    Hey everyone!

    Didn't get a reply on my last post, so I am more or less just going with my gut instinct.

    Last I posted, I was trying to create a form that could handle the composition of private messages. It's slightly more complex that I'll describe here, but that is my own problem.

    Basically, the form is backed by a domain object containing
    id, User, subject, content

    I've made a custom UserPropertyEditor, which basically takes in the String representation of a Username and then fetches the object from the database (via a hibernate dao)

    This leads me to question one -- 1) should I be doing this sort of database interaction inside my PropertyEditor? or is this better left for a validation class? Where is it proper to put the logic to check whether the desination username is a valid one?

    2) Am I making things way more difficult that they should be by binding to complex domain objects? Should I just create myself a PrivateMessageCommand object made of strings and then worry about composing the complex object to write inside onSubmit? If I do that, how do I then report validation errors inside onSubmit? And if I have an associated validation class -- will that get called before the onSubmit method?

    As you can see, I'm still a little confused. I've looked in all the demo apps inside the spring distribution, but couldn't really find anything that answered my questions.

    Thank you all for your time.

    Jay - http://www.pixelknowledge.com

  • #2
    1) should I be doing this sort of database interaction inside my PropertyEditor? or is this better left for a validation class? Where is it proper to put the logic to check whether the desination username is a valid one?
    This should go in the validation class. Property editors are generally used to check that binding is OK (e.g. valid date). The validator does additional logic, for example to check whether a date is within a certain range, or to check whether the username is already in use.

    2) Am I making things way more difficult that they should be by binding to complex domain objects?
    Generally this will save you difficulties. Where was the post original post?

    If I do that, how do I then report validation errors inside onSubmit?
    Generally you can do all validation in the validator. Take a look at the samples (e.g. AccountValidator in JPetStore). You'll generally have code like:
    Code:
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username",
                "required", "is required");
    And if I have an associated validation class -- will that get called before the onSubmit method?
    Yes

    Comment


    • #3
      Originally posted by katentim
      This should go in the validation class. Property editors are generally used to check that binding is OK (e.g. valid date). The validator does additional logic, for example to check whether a date is within a certain range, or to check whether the username is already in use.
      I believe that what he wants to do is to have a property of type MyObject but have the user pass in a key field, then have the property editor convert the key field into an actuall object. That is what I do in my apps.

      In you case, in which command object property does validator store the retrieved object?

      Comment


      • #4
        1) should I be doing this sort of database interaction inside my PropertyEditor? or is this better left for a validation class? Where is it proper to put the logic to check whether the desination username is a valid one?
        Personally I believe the property editor is exactly the right place for this, and I do this sort of thing all the time. Its pretty standard practice to the best of my knowledge.

        2) Am I making things way more difficult that they should be by binding to complex domain objects? Should I just create myself a PrivateMessageCommand object made of strings and then worry about composing the complex object to write inside onSubmit? If I do that, how do I then report validation errors inside onSubmit? And if I have an associated validation class -- will that get called before the onSubmit method?
        The whole data binder / custom property editor arrangement is geared towards doing exactly this. I find this to be a very successful approach, and much less complex than the alternative. Dealing with strings all over the place is quite a backward step and reminds me of the sort of thing you used to end up with in struts.

        Comment

        Working...
        X