views:

1147

answers:

2

I have an action with an empty string for name defined in the root namespace, and I want to redirect to that action from another action if a certain result is found, but it doesn't seem to work.

Here's the default action

<action name="" class="com.example.actions.HomeAction">
    <result name="success" type="freemarker">freemarker/home.ftl</result>
</action>

And I'm defining the redirect in the global-results for the package:

<global-results>
    <result name="sendToRouting" type="redirectAction">
        <param name="actionName"></param>
        <param name="namespace">/</param>
    </result>
</global-results>

I've tried taking out the actionName parameter, but that doesn't work. If I put a name in for the HomeAction and reference it by name in the global-results it works, so I'm assuming the problem is lack of action name for the redirect.

Any thoughts?

+1  A: 

I think that what you want to do is use <default-action-ref />:

<package name="home" namespace="/" extends="struts-default">
    <default-action-ref name="home" />

    <action name="home" class="com.example.actions.HomeAction">
        <result name="success" type="freemarker">freemarker/home.ftl</result>
    </action>

</package>

Sorry...misread the question:

Try changing type="redirectAction" to type="redirect", I'm fairly sure that redirectAction is now redirect.

Thomas
A: 

Were you getting a NullPointerException because the actionName parameter is blank? I hacked around this by providing a string which evaluates to an empty string:

<param name="actionName">${}</param>

Still looking for a more "correct" solution though...

Todd Owen
Hmm, that's an interesting work around. I'll have to give that a try as well
topher-j