Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't i redirect an action to another action in Struts2?

Tags:

java

struts2

i am using Struts2. I have a dialog box with a list of persons that is update through the "search_users" action. Next to this list i have a form that you can use to add another person by calling the "add_user" action when the form is submitted.

What i'm trying to do is that, once the add_user action is performed, the list gets updated using the "search_user" action.

I tried using the result type "redirect" in the struts.xml like this:

<action name="search_users" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLSubequipo" method="searchUsers">
            <result name="success">list.jsp</result>
        </action>

        <action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
            <result name="success" type="redirectAction">search_users</result>
        </action>

But that doesn't work. What am i doing wrong? Is there something i should add to the struts.xml file that i'm not aware of?

This is the error mesage i get:

"Caused by: There is no result type defined for type 'redirect-action' mapped with name 'success'.  Did you mean 'redirectAction'? - result - file:/.../struts.xml:59:44
    at ..."
like image 247
Daniel Calderon Mori Avatar asked Jun 08 '12 14:06

Daniel Calderon Mori


People also ask

What is action redirect?

You can use post-login Actions to redirect users before an authentication transaction is complete. This lets you implement custom authentication flows that require additional user interaction beyond the standard login form.

What is ActionSupport in Struts2?

ActionSupport class implements a no. of interfaces like Action, Validateable, LocaleProvider and Serializable etc. It is more commonly used instead of Action interface.

What is execute method in Struts2?

Struts 2 actions don't force you to implement any interface or extends class, it's only required you to implement an execute() method that returns a string to indicate which result page should return.

What is pojo in Struts2?

In struts 2, action class is POJO (Plain Old Java Object). POJO means you are not forced to implement any interface or extend any class. Generally, execute method should be specified that represents the business logic.


1 Answers

Current Configuration:

<action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
   <result name="success" type="redirectAction">search_users</result>
</action>

As per the documentation correct format is:

<action name="add_user" class="org.apache.struts.gestion_edt.controller.adm_proyectos.BLTipoEntregable" method="addUser">
    <result type="redirectAction">
        <param name="actionName">search_users</param>
        <!--<param name="namespace">/secure</param> This is optional if your action where you are redirecting is in the same namespace you can leave this, if your action is in some other name space then provide the namespace--> 
    </result>
</action>
like image 155
mprabhat Avatar answered Sep 19 '22 08:09

mprabhat