Developing a demo application.
Error: Can not resolve properties under push tag. name and age
FORM:
<s:form action="addStudentAction" method="POST">
<s:push value="student">
<s:textfield name="name" label="Name : " value="" />
<s:textfield name="age" label="Age : " value=""/>
</s:push>
<s:submit/>
</s:form>
Action & model:
public class StudentAction extends ActionSupport implements ModelDriven {
Student student = new Student();
@Autowired
StudentService studentService;
public Object getModel() {
return student;
}
public String execute(){
return SUCCESS;
}
public String addStudent() throws Exception {
student.setCreatedDate(new Date());
studentService.add(student);
return SUCCESS;
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
}
package com.myapp.model;
import java.util.Date;
public class Student {
private Long id;
private String name;
private Integer age;
private Date createdDate;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
}
EDITED
public class StudentAction extends ActionSupport implements ModelDriven<Student> {
Student student = new Student();
List<Student> studentList = new ArrayList<Student>();
@Autowired
StudentService studentService;
public Student getModel() {
return student;
}
public String execute(){
return SUCCESS;
}
public String addStudent() throws Exception {
student.setCreatedDate(new Date());
studentService.add(student);
return SUCCESS;
}
}
Still properties are not resolved. See the options. model.name will resolve the property.

**struts.xml**
<struts>
<constant name="struts.devMode" value="true"/>
<package name="default" namespace="/" extends="struts-default">
<action name="addStudentAction" class="com.myapp.action.StudentAction" method="addStudent">
<result name="success" type="redirectAction">listStudentAction</result>
</action>
<action name="listStudentAction" class="com.myapp.action.StudentAction" method="listAllStudents">
<result name="success">/pages/student.jsp</result>
</action>
</package>
</struts>
Push is used when accessing variables during rendering. In your case you are setting the value in the textfield to empty, and since that is all you are doing inside the push it is clear that the push tag is not doing anything useful.
What I think you might be intending is to “push” student in the view, what would be the equivalent of appending “student.” to all the variables. This is not what the push tag does, although I must admit such a tag would be useful and possibly save a lot of typing. We can see that the target of the action implements model driven (and the model is a Student), this effectively pushes the student to the top of the stack already, so simply remove the push tag and you should be good.
The following is advice:
Your action has a get/set Student… it should not if it implements ModelDriven.
Your class StudentAction, should probably be called AddStudentAction.
The addStudent method should be removed and the functionality moved into execute() ie:
You should implement a validate method
public void validate()(unless you’re doing that in xml or annotations).Finally, this is personal preference but when you implement ModelDriven it helps to supply the type ie:
implements ModelDriven<Student>(Then the IDE hopefully knows to create the correct getter/setter).