[ 
https://issues.apache.org/struts/browse/WW-1815?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Don Brown updated WW-1815:
--------------------------

      Priority: Major  (was: Minor)
    Issue Type: New Feature  (was: Improvement)
       Summary: Custom parameter name prefixes for the ActionMapper   (was: 
Make ActionMapper ParameterActions more easily extensible)

> Custom parameter name prefixes for the ActionMapper 
> ----------------------------------------------------
>
>                 Key: WW-1815
>                 URL: https://issues.apache.org/struts/browse/WW-1815
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Dispatch
>    Affects Versions: 2.0.6
>            Reporter: Jasper Rosenberg
>             Fix For: 2.1.0
>
>
> It would be great if DefaultActionMapper made it easy to add additional 
> ParameterActions to the prefixTrie.
> All it would take is making ParameterAction protected, and then adding a 
> method like:
> protected void addParameterAction(String prefix, ParameterAction 
> parameterAction) {
>     prefixTrie.put(prefix, parameterAction);
> }
> We had the need to add our own prefix support for redirecting w/o appending 
> the context, and, just so you can feel my pain, here is what I currently have 
> to do:
>     /** Submission redirect parameter that doesn't automatically include 
> context. */
>     static final String REDIRECT_NO_CONTEXT_PREFIX = "redirect-nocontext:";
>     public MyActionMapper() {
>         try {
>             /*
>              * The list of ParameterActions is private, so we have
>              * to bust through using reflection.
>              */
>             Field prefixTrieField = 
> DefaultActionMapper.class.getDeclaredField("prefixTrie");
>             prefixTrieField.setAccessible(true);
>             PrefixTrie prefixTrie  = (PrefixTrie) prefixTrieField.get(this);
>             Object sample = prefixTrie.get("action:");
>             // The ParameterAction interface is package protected, so use a 
> dynamic
>             // proxy to get around it.
>             Class[] interfaces = sample.getClass().getInterfaces();
>             Object parameterActionProxy = 
>                 Proxy.newProxyInstance(
>                     Thread.currentThread().getContextClassLoader(),
>                     interfaces,
>                     new InvocationHandler() {
>                         public Object invoke(Object proxy, Method method, 
> Object[] args)
>                             throws Exception {
>                             if (method.getName().equals("execute")) {
>                                 String key = (String) args[0];
>                                 ActionMapping mapping = (ActionMapping) 
> args[1];
>                                 ServletRedirectResult redirect =
>                                     new ServletRedirectResult();
>                                 redirect.setPrependServletContext(false);
>                                 redirect.setLocation(
>                                     key.substring(
>                                         REDIRECT_NO_CONTEXT_PREFIX.length()));
>                                 mapping.setResult(redirect);
>                                 return null;
>                             } else {
>                                 throw new RuntimeException(
>                                     "Unknown parameter action method: "
>                                     + method.getName());
>                             }                            
>                         }
>                     });
>             
>             prefixTrie.put(REDIRECT_NO_CONTEXT_PREFIX, parameterActionProxy);
>         } catch (Exception e) {
>             LogFactory.getLog(MyActionMapper.class).error(
>                 "Failed to add custom parameter action mapping.", e);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to