Lohit
Lohit

Reputation: 891

Strut2 - Get Property value in next Action

I am using <s:form action="someAction">

my struts.xml contains

<action name="someAction" 
        class="com.test.testaction.getValue" 
        method="getValuedemo">
    <result name="success" type="redirectAction">demo</result>   
</action> 

while my Action contains

public class getValue extends ActionSupport{
    private String userName;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getValuedemo() {
        userName = "tmpUser";
    }
}

My question is how to get userName property in demo.action????? Please help

Upvotes: 2

Views: 3918

Answers (3)

Anupam
Anupam

Reputation: 8016

You can pass userName as a parameter

<action name="someAction" class="com.test.testaction.getValue" method="getValuedemo">
    <result name="success" type="redirectAction">
        <param name="actionName">demo</param>
        <param name="userName">${userName}</param>
    </result>
</action> 

Also add userName getter/setter in the demo action

Upvotes: 6

Quaternion
Quaternion

Reputation: 10458

First use the chain result type...

<result name="success" type="chain">demo.action</result>

Then read about interceptors so you can avoid using chain, redirect, redirectAction.

Upvotes: 0

Steven Benitez
Steven Benitez

Reputation: 11055

Values associated with a specific action are per-request. If you set values in an action and then redirect, those values will be lost. If getValue is just redirecting to demo, what is the purpose of the getValue action? Why not just have the userName getter and setter on DemoAction?

Please revise your question to provide more details on what you are trying to do.

Additionally, your action name does not adhere to Java naming conventions for a class, which should start with a capital letter. Additionally, you might want to come up with a better name for the action than GetValue.

Upvotes: 1

Related Questions