Results 1 to 5 of 5

Thread: Default toString() appears upon validation errors.

  1. #1
    Join Date
    Nov 2004
    Posts
    16

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    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
    Alef Arendsen
    SpringSource
    http://www.springsource.com

  3. #3
    Join Date
    Nov 2004
    Posts
    16

    Default

    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.

  4. #4
    Join Date
    Nov 2004
    Posts
    16

    Default 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.

  5. #5
    Join Date
    Aug 2004
    Location
    Montreal, Canada
    Posts
    35

    Default

    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

Similar Threads

  1. Replies: 46
    Last Post: Jan 19th, 2011, 01:15 PM
  2. Validation and displaying errors in jsp
    By jkookie in forum Web
    Replies: 3
    Last Post: Jun 5th, 2008, 03:28 PM
  3. Replies: 17
    Last Post: Jan 2nd, 2007, 01:43 PM
  4. Validation Errors will not display
    By thus in forum Web
    Replies: 1
    Last Post: Oct 18th, 2005, 04:40 PM
  5. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •