-
1. Re: Why is convertRequestParameter protected
sleroux Mar 25, 2008 3:10 PM (in response to sleroux)Ok,
I mis-read the code and thought that the requestParam argument was the name of the parameter. But it's the value.
protected Object convertRequestParameter(String requestParameter, Class type)
So I will use getRequestParameters+convertMultiValueRequestParameter in something like this:
Map<String,String[]> paramMap = parameters.getRequestParameters(); int my_value parameters.convertMultiValueRequestParameter(paramMap, "my_param", Integer.class);
Maybe this behavior should be encapsuled in a class?
SL
-
2. Re: Why is convertRequestParameter protected
pmuir Mar 28, 2008 1:42 PM (in response to sleroux)
Sylvain Leroux wrote on Mar 25, 2008 03:10 PM:
Maybe this behavior should be encapsuled in a class?Huh? It already is, Parameters.
-
3. Re: Why is convertRequestParameter protected
sleroux Mar 28, 2008 10:29 PM (in response to sleroux)I wrote
class
, but I thought more about amissing method
for the Parameters class. Let me explain myself:As far as I understand, I need 2 method calls just to retrieve the value of a parameter. Something like parameters.getRequestParameter("my_param", MyClass.class) sounds definitively more natural...
And if I said that, it was not (only) by laziness: because of those two calls, It's difficult to use the value of a request parameter in an EL expression (like in an action of a jPDL pageflow - that's what I tried to do).
Sylvain.
-
4. Re: Why is convertRequestParameter protected
pmuir Mar 29, 2008 1:33 PM (in response to sleroux)We could create getConvertedRequestParameter(String name, Class<?> type) - file a request in JIRA.
-
5. Re: Why is convertRequestParameter protected
sleroux Mar 31, 2008 4:07 PM (in response to sleroux)Done: JIRA JBSEAM-2801
For now, here's how I resolved this issue by using a custom component in order to access to a request parameter from a jPDL action:
/** * Give access to request parameters from EL expressions. * * @usage * <tt>#{param_helper.getConvertedRequestParameter('paramName', stringClass)}</tt> * * @author Sylvain Leroux * */ @Scope(EVENT) @Name("param_helper") public class ParameterHelper { Map<String, String[]> requestParameters; org.jboss.seam.web.Parameters parameters; @Create public void initParameterHelper() { parameters = org.jboss.seam.web.Parameters.instance(); requestParameters = parameters.getRequestParameters(); } public Object getConvertedRequestParameter(String name, Class<?> type) { return parameters.convertMultiValueRequestParameter(requestParameters, name, type); } public static ParameterHelper instance() { return (ParameterHelper) Component.getInstance(ParameterHelper.class, ScopeType.EVENT); } /** * Give access to <tt>String.class</tt> from an EL expression (which cannot access * <em>static fields</em>). * @return String.class */ @Factory(scope=APPLICATION) public Class<String> getStringClass() { return String.class; } /** * Give access to <tt>Integer.class</tt> from an EL expression (which cannot access * <em>static fields</em>). * @return Integer.class */ @Factory(scope=APPLICATION) public Class<Integer> getIntegerClass() { return Integer.class; } /* ... other class accessors here ... */ }
Please note that getStringClass, getIntegerClass, ... are required since, AFAIK, I cannot access static fields from an EL expression. I certainly should have put those methods in a separate (APPLICATION scoped) component.