File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Portals and Portlets and the fly likes converter and validator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Portals and Portlets
Bookmark "converter and validator" Watch "converter and validator" New topic

converter and validator

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830

I have a field named 'Dog' I want user to enter input in following way:

dog name-owner name

For example: tommy-micheal is valid, doggie-ramlal is also valid, whereas pappi is not valid.

I have written a validator for this:

I also want to convert it into following format:

'tommy-micheal' will get converted to 'micheal has a dog tommy'. I do have written convertor for this:

But I am facing issues because of strange behavior of framework.

It "converts" first and then "validate".

Now if user enters something inappropriate. It doesn't validate, goes into convertor (in gerAsObject() method) and gives 'ArrayIndexOutOfBoundsException' becuase of that split method. I can put a check here but why it doesn't validate first?

Because of this error, dog object doesn't get constructed properly and I get 'ClassCastException' in getAsString method of convertor. Otherwise I don't get any 'ClassCastException' in this method in user enters value in proper format.

I know people who has faced similar problem will understand this.

Let me know what you suggest.


[ January 25, 2008: Message edited by: ankur rathi ]
I agree. Here's the link:
subject: converter and validator
It's not a secret anymore!