File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Problem with conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with conversion" Watch "Problem with conversion" New topic
Author

Problem with conversion

Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
I was following a tutorial on doing conversion. If I enter in something wrong, it's supposed to display my error message I think, but instead I get a stacktrace error.

Here is my code:


Here's what I get if I intentionally make a mistake:
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

Did you register CircleTypeConverter as the type converter for Circle class??


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
Yes. It works fine if I type everything correctly. If I intentionally make a mistake though, it gives that error.
Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
any ideas?
Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
Updates:

I forgot an INPUT result type. Now I put it in, and it returns back to the offending JSP page. It still throws a stack trace and the field error it returns is some default field error, not one that I specified.

The first field error it threw was from my global properties file:
xwork.default.invalid.fieldvalue

I commented that out, and then it just returned a generic error message.

1) I would like a stack trace to not be thrown
2) I would like the message that I specify in my code to be shown:
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9313
    
  17

It works fine if I type everything correctly. If I intentionally make a mistake though, it gives that error.

I'm still not getting this statement. What are you trying to say here. The stack trace says that Struts is looking for a setCircle(String[]) method in your CustomConverterTest class which means that your conversion class was not called. Can you show us how you've configured CircleTypeConverter as a custom type converter...
Pj Casaro
Ranch Hand

Joined: Jul 13, 2010
Posts: 47
In the file CustomConverterTest-conversion.properties:

circle=converters.CircleTypeConverter

I'm not really sure how to make it more clear. If I type in a string, that I would like to convert to a Circle object, and I type in the string correctly (as in, its in the correct syntax/format that my converter expects) then it works. If I type in the string incorrectly (wrong format or syntax) then I see that stack trace AND instead of the field errors that I pass as parameters to the TypeConversionException, I get generic error messages.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with conversion