Struts的回显
来源:互联网 发布:京东盈利模式 知乎 编辑:程序博客网 时间:2024/05/22 13:13
思路:
从一个Action redirect跳转到一个回显页面,其中Action里的AcrionForm和Edit页面中的ActionFom是同一个Fom类,而且从Action跳转到edit.jsp设置为服务器跳转,这样form的数据不会丢失。所以只要在进入回显页面的Action中查询出回显数据后,放到ActionForm中,就能在Edit页面中进行数据回显了。
struts-config.xml:
<struts-config><form-beans><form-bean name="personForm" type="com.xxc.form.PersonForm"></form-bean></form-beans><action-mappings><action path="/editPersonUi" type="com.xxc.actionUI.EditUiAction" name="personForm"><forward name="editUi" path="/CRUD/edit.jsp" redirect="false"></forward><!--redirect="false"表示进行服务器跳转 --></action><action path="/editPerson" type="com.xxc.action.PersonAction" name="personForm" parameter="method"></action></action-mappings></struts-config>
EditAction:
public class EditUiAction extends Action {public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {PersonDao personDao = new PersonDaoImpl();Person p = personDao.findPersonById(request.getParameter("id"));PersonForm personForm = (PersonForm)form;//将form强转,然后赋值personForm.setId(p.getId());personForm.setUserName(p.getUserName());personForm.setBirthday(p.getBirthday());personForm.setDescribe(p.getDescribe());personForm.setEduName(p.getEduName());personForm.setSex(p.getSex());personForm.setLove(p.getLove().split(","));//如果有checkbox和select组件,那么首先需要将checkbox和select的所有内容传递过去,然后struts回进行自动回显,因为选择的值在上面的form里已经封装了String[] allLove = AllLove.allLoce;request.setAttribute("allLove", allLove);EduDao eduDao = new EduDaoImpl();List<Edu> eduList = eduDao.getAllEdu();request.setAttribute("eduList", eduList);return mapping.findForward("editUi");}}
Edit.jsp:
<body> <html:form action="editPerson.do?method=edit" method="post"> <html:hidden property="id"/> <table> <tr> <td>用户名:</td> <td> <html:text property="userName"></html:text> </td> </tr> <tr> <td>性别:</td> <td> <html:radio property="sex" value="1"></html:radio>男 <html:radio property="sex" value="0"></html:radio>女 </td> </tr> <tr> <td>生日:</td> <td> <html:text property="birthday"></html:text> </td> </tr> <tr> <td>描述:</td> <td> <html:textarea property="describe" rows="10" cols="40"></html:textarea> </td> </tr> <tr> <td>爱好</td> <td> <c:if test="${! empty allLove}"> <c:forEach items="${allLove}" var="love"> <html:multibox property="love"> ${love} </html:multibox> ${love} </c:forEach> </c:if> </td> </tr> <tr> <td>级别</td> <td><html:select property="eduName"><html:options collection="eduList" property="eduId" labelProperty="eduName"/></html:select> </td> </tr> <tr> <td> <html:submit value="提交"/><html:reset value="重置"/> </td> <tr> </table> </html:form> </body>
- Struts的回显
- Struts数据回显
- 【Struts】数据回显
- struts的struts-config
- 关于struts修改实体信息回显的方法
- struts的struts.properties详解
- struts笔记-struts的理解
- 【struts】struts namespace的配置
- struts案例的struts.xml
- 性别回显 struts中radio标签
- 不错的struts插件:Struts Spring Plugin
- 不错的struts插件:Struts Spring Plugin
- struts源代码阅读(struts 的执行)
- STRUTS的struts--config.xml详解
- 关于struts+hibernate的替代:struts+newxy
- Struts的后代:Shale不是Struts
- struts的执行(struts-1.1版)
- Struts 2和Struts 1的比较
- Android内核的编译与裁剪
- openstack的identity组件keystone
- windows环境下Python IDLE
- 查询转换--子查询解嵌套
- WPF中的实现类似Excel的动态条件格式
- Struts的回显
- gc日志分析工具
- iframe页面里的js调用父级页面js函数的解决方法
- CMake 使用方法
- UVa10948 - The primary problem
- uploadify(或swfupload)刷新页面时IE下不断报JS Error的bug的处理
- 在Win7上用Tomcat发布网站--工作收获
- 设置Oracle的默认的时间显示格式
- SQLServer存储过程学习