Как исключить действие отправки из списка параметров в struts2?
Я пытаюсь исключить действие отправки из списка параметров. Ниже приведен класс действий.
@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@InterceptorRefs({
@InterceptorRef(value="validation", params={"excludeMethods", "test"}),
@InterceptorRef(value="params", params={"excludeParams", "action:postAction"})})
public final class TestAction extends ActionSupport implements Serializable, ValidationAware
{
private static final long serialVersionUID = 1L;
private static final String SUCCESS = "success";
private String name;
@Action(value = "test", results = {
@Result(name="success", location="Test.jsp"),
@Result(name = "input", location = "Test.jsp")})
public String test() throws Exception
{
System.out.println("name = "+name);
return SUCCESS;
}
@Action(value = "postAction", results = {
@Result(name="success", location="Test.jsp"),
@Result(name = "input", location = "Test.jsp")})
public String postAction()
{
System.out.println("Post invoked");
System.out.println("name = "+name);
return SUCCESS;
}
@RequiredStringValidator(type= ValidatorType.FIELD, message = "The name is required.")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public void validate()
{
if(!hasErrors()&&name.length()<2)
{
addFieldError("name", "The name must compose of 2 letters.");
}
}
}
Test.jsp
страница:
<s:form namespace="/admin_side" action="test" validate="true">
<s:textfield id="name" name="name" label="Name"/>
<s:submit id="btnSubmit" name="btnSubmit" value="Submit" action="postAction"/>
</s:form>
Сгенерированный HTML-код для<s:submit>
будет выглядеть следующим образом.
<input type="submit" id="btnSubmit" name="action:postAction" value="Submit"/>
@InterceptorRef
выше класса
@InterceptorRef(value="params", params={"excludeParams", "action:postAction"})
не похоже на работу. МетодpostAction()
никогда не вызывается, вызывая следующее предупреждение.
24 декабря 2013 г. 22:49:16 com.opensymphony.xwork2.interceptor.ParametersInterceptor warn ПРЕДУПРЕЖДЕНИЕ: Параметр [action: postAction] находится в списке шаблонов excludeParams!
вstruts.properties
файл, у меня есть следующие свойства до сих пор.
struts.enable.DynamicMethodInvocation=false
struts.devMode=false
struts.ui.theme=simple
struts.convention.package.locators=actions
struts.convention.action.suffix=Controller
struts.convention.action.mapAllMatches=true
struts.convention.result.path=/WEB-INF/content //No need. It is the default.
struts.mapper.action.prefix.enabled=true
Я использую Struts 2.3.16.
Почему он не исключает параметр кнопки отправки? Как вызватьpostAction()
метод, когда<s:submit>
нажал?