In the following piece of code about Struts action class,
@Namespace("/admin_side")
@ResultPath("/WEB-INF/content") // Default.
public final class TestAction extends ActionSupport implements Serializable
{
private static final long serialVersionUID = 1L;
private static final String SUCCESS = "success";
private String name;
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
@Action(value="test",results={@Result(name="success",location="Test.jsp")})
public String execute() throws Exception
{
System.out.println("name = "+name);
System.out.println("email = "+email);
return SUCCESS;
}
// Some annotations to map this method to <s:submit>
public String postAction()
{
System.out.println("postAction() invoked.");
System.out.println("name = "+name);
System.out.println("email = "+email);
return SUCCESS;
}
}
I want to invoke the postAction()
method on the given submit button like so,
<s:form action="test">
<s:textfield id="name" name="name" label="Enter your name"/>
<s:textfield id="email" name="email" label="Enter your email"/>
<s:submit value="Submit" method="postAction"/>
</s:form>
I have seen some questions like this one but all of them use XML configurations in struts.xml
.
How to make it possible using convention plugin?
You need to use
namespace
attribute because your action is mapped with@Namespace
.If this doesn't work in the latest version according to WW-4023 then you can invoke a method directly
or configure
params
interceptor parameterexcludeParams
to removemethod
parameter from excluded parameters.Note, either you use DMI and the methods above or don't use it, in this case you should map an action to the method and don't use attributes
method
orsubmit
tag'smethod
andaction
as the issue above restrict using special parameters. If you have multiple submit buttons if you follow that restriction you have to dynamically changeform
tag's action attribute using JavaScriptonclick
event.