Ivan Shih created WW-5046:
-----------------------------
Summary: Validation framework won't work when running a method
named input() in an Action class
Key: WW-5046
URL: https://issues.apache.org/jira/browse/WW-5046
Project: Struts 2
Issue Type: Bug
Components: Core Actions
Affects Versions: 2.3.37
Environment: Windows 10
Struts 2.3.37
Eclipse Oxygen
Tomcat 9.0.24
Reporter: Ivan Shih
When running a method named input() in an Action class, the build-in validation
framework won't work, i.e., the validation messages doesn't get displayed, no
validation function is performed:
BookAction Class with a method named input() :
{code:java}
public class BookAction extends ActionSupport implements ModelDriven<Book> {
private Book book = new Book();
@Override public Book getModel() {
return book;
}
public String input() {
return SUCCESS;
}
}
{code}
Book Class:
{code:java}
public class Book {
private String isbn;
// get and set method
...
}
{code}
BookAction-validation.xml:
{code:java}
<validators>
<validator type="requiredstring">
<param name="fieldName">isbn</param>
<message>ISBN is empty!!!</message>
</validator>
</validators>
{code}
Results:
The build-in validation framework won't work, i.e., the validation messages
doesn't get displayed, no validation function is performed.
How to Fix:
Changing the method name to inputs() or else in BookAction Class :
{code:java}
public class BookAction extends ActionSupport implements ModelDriven<Book> {
private Book book = new Book();
@Override public Book getModel() {
return book;
}
// Changing the method name to inputs() or else fix the issue
public String inputs() {
return SUCCESS;
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)