I’d like to implement in a Struts2 web application some sort of url “fallback” using an own ActionMapper. This means:
when
does not exist, I want the ActionMapper to try to load e.g.
instead.
Parsing the URL and therefore finding the namespace is not a problem, but I don’t know how to decide if the desired action is present in this namespace (which I have to modify if it is not).
Is there a possibility to check if an action exists within a namespace (/foo/bar in this case)? Or is there another mechanism to perform what I intend to do?
Thanks,
Gregor
I solved my problem. This happens in the custom ActionMapper:
To find out if an action exists, I firstly construct a string of the class name (including the namespace) of the desired action. Then I call
If the action does not exist, an
ClassNotFoundExceptionexception is thrown, which I can check for in atry { ... } catch { ... }block. Within thecatchblock I can change the namespace of the mapping to the fallback namespace. This has some implications to theActionProxy: The namespace has to be changed there, too, ingetMappingFromActionName. Otherwise theActionProxycontains the namespace of the request, which is fine usually. TheDefaultActionProxydoes not have a setter for namespace, so I subclassed it and create it using a customAxtionProxyFactory. Phew.This is not elegant imho, but as long as I don’t come up with a better idea it’ll stay that way. I’d love to hear a better solution!