Announcement Announcement Module
Collapse
No announcement yet.
Default toString() appears upon validation errors. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Default toString() appears upon validation errors.

    I have a form that has a few complex objects. I have a property editor that looks them up based on the input string just fine with the "setAsText()" methods in the property editor.

    However, the "getAsText()" method in the property editor doesn't seem to work properly. Essentially the propertyeditor setAsText takes a string logical key of the object and returns it from the database. The getAsText returns the logical key field from the object.

    This all works fine in the forward direction; I enter my string that's the key for the object, and it gets bound correctly. However, if there is a validation error on the page (or if I return to it upon navigation within the FormWizard), the nice, primary key string is replaced by the default toString() for that object (org.evilrob.blah.blah.blah@Af93bb). Certainly I could have the toString() method for my object return its primary key value, but I hate relying on toString() for real functionality within the application.

    Should my property editor be working in the other direction? Is something going wrong that's preventing it from working, or will property editors not work that "direction"?

  • #2
    Have you used the spring:bind tag to display the value of your property in your JSP?? If not, that's the problem. spring:bind ensure a property editor is used when displaying a property. c:out tags will just call the toString() on the object.

    regards,
    Alef

    Comment


    • #3
      yes, I'm using velocity views, so I don't even have c:out. :-) It's all with $spring.bind. It works fine on the form submission, just not on redisplaying.

      Comment


      • #4
        Found the problem

        Stupid mistake on my part...helps if you use the right method signature...I've never used property editors before, and I apparently thought that the opposite of "void setAsText(String) should be "String getAsText(Object)."

        It should of course be "String getAsText()". Then call getValue() within the method.

        Turns out, when you actually override the right method, that it works much better...sorry for the bother.

        Comment


        • #5
          Well, not that stupid buddy. I had the same problem for months and never could figured it out. I copy-pasted some code from some tuturial at the time and it was indeed wrong. Thanks for pointing that out.

          Uze

          Comment

          Working...
          X