Tech Armada
Tech Armada

Reputation: 11

In struts 2 how to call method of same action with passing parameter along with method call

I wanted to make a call to a method of same action and pass parameter to it. Can anybody tell me how can i make a call to it.

Usually in action class if same class method is called in another method of same class then just we write :

return methodName();

but in case i want to make a call with passing parameter along with the call;

Upvotes: 1

Views: 3498

Answers (2)

doctrey
doctrey

Reputation: 1227

There are two ways I can think of to do this.

If you want to call the method on the same action:

<s:property value="methodName(parameter)"/> 

If the method is in another action and you have specified the method in that action in your action mappings:

<s:action name="actionName_mehtodName" executeResult="false">
    <s:param name="paramName" value="paramValue"/>
<s:action/>

In latter case you if you set executeResult to false you can use the action to set properties on ValueStack for later use. But if set to true whatever the result of that action is, it will be executed.

Upvotes: 2

nmc
nmc

Reputation: 8686

Can you save it to a class variable of your action class so that all methods can access it?

public class MyAction extends ActionSupport {

   private Object parameter; //The parameter to be passed between methods

   public String firstAction() {
       ...
       parameter = something; //Set the parameter for second action to access
       return secondAction();
   }
   ...
}

Upvotes: 1

Related Questions