struts2 textfield的标记(struts2 tag for textfield)
开发演示应用程序。
错误:无法解析push标签下的属性。 姓名和年龄
形成:
<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; } }
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; } }
仍然没有解决属性。 查看选项。 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>
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>
原文:https://stackoverflow.com/questions/12667275
更新时间:2023-06-24 19:06