-
1. Re: @RequestParameter issue
christian.bauer May 1, 2007 7:13 AM (in response to sammy8306)@RequestParameter conversion from a String request parameter to a Long field or property is working fine in my app. You need to show some code if you want help.
-
2. Re: @RequestParameter issue
sammy8306 May 1, 2007 7:42 AM (in response to sammy8306)I think there's a little misunderstanding... indeed, the conversion is working just fine when I do:
/app/somepage.xhtml?id=1
which is convertible (by parseLong() I guess) to Long and therefore assignable to this field:@RequestParameter("id") private Long id;
However, my problem is with something like this:
/app/somepage.xhtml?id=a
Now, a NumberFormatException is raised in the convertor. I would like to gracefully fail (display a nice error message or something). The question is whether this is possible (without explicitly doing the conversion my self) -
3. Re: @RequestParameter issue
christian.bauer May 1, 2007 8:17 AM (in response to sammy8306)Well, 'a' is not a number! :) You can't gracefully fail, just don't put illegal request arguments into your application logic.
-
4. Re: @RequestParameter issue
sammy8306 May 1, 2007 11:53 AM (in response to sammy8306)Well uhm... what about (ab)users? Of course I'm not going to code such things into the application logic, but it seemed only natural to me that my application could respond to malformed data.
-
5. Re: @RequestParameter issue
christian.bauer May 1, 2007 11:56 AM (in response to sammy8306)It does react to malformed data, it throws a runtime exception. What more do you want? Redirect this exception to an error page.
-
6. Re: @RequestParameter issue
sammy8306 May 1, 2007 4:42 PM (in response to sammy8306)I wasn't trying to be hostile or anything, sorry if I came across like that?
What I want, is some mechanism to create (for example) a facesmessage containing a reference to the parameter name stating that invalid information is entered. However, 1) we are dealing with a GET, so facesmessages are not displayed directly (can work around that using a conditionally rendered div or something) 2) the runtime exception is not being thrown in the context of the component that accesses the requestparameter.
If redirecting based on the exception is the only mechanism available, then I'll use it - if there was an easier solution (which is why I asked the question) I would like to use that. -
7. Re: @RequestParameter issue
p-a May 1, 2007 5:14 PM (in response to sammy8306)How about taking care of the conversion yourself, by letting the requestparam being just a String? A try-catch in your method takes care of any Exceptions, and some static code somewhere which you can call with params like the name of the reqparam, and some errorstring that it will set to the facesmessages?
-
8. Re: @RequestParameter issue
p-a May 1, 2007 5:16 PM (in response to sammy8306)Ahh, guess I shold have read your first post to the end..
"Ofcourse I could make all my RequestParams String and handle the conversion myself, but hey..."
Nvm ;) -
9. Re: @RequestParameter issue
sammy8306 May 2, 2007 3:39 AM (in response to sammy8306)Hm, should I go that route, is there any way to force the facesmessages to be displayed after a GET-request instead of after a POSTback? Right now I'm using <s:div rendered="!#{component.initialized}"> to display an error message, where I manually manage the initialized boolean.
-
10. Re: @RequestParameter issue
christian.bauer May 2, 2007 4:02 AM (in response to sammy8306)You are over-engineering, is all. An error page is perfectly acceptable if a user plays with the URL.