デモ アプリケーションの開発。
エラー:プッシュ タグの下のプロパティを解決できません。名前と年齢
形:
<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>
アクション & モデル:
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;
}
}
編集済み
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;
}
}
まだプロパティは解決されていません。オプションを参照してください。model.name はプロパティを解決します。
**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>