在struts2中实现了编辑功能。当我点击提交按钮后,我在JSP中显示的bean值在操作类中正确获取。为什么没有得到一些bean对象的值?
但是我在JSP中没有提到的其他bean的值是返回null。
如果我在JSP中显示bean的所有值,那么我可以在Action中获取所有值。
这是解决此问题的方法。否则,还有其他方法。
的Action类的代码
UserForm userForm = new UserForm();
public String edit(){
String result = ActionSupport.ERROR;
HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpSession session = request.getSession(false);
if (null != session
&& null != (UserAccount) session.getAttribute(USER)) {
String editUser = (String) request
.getParameter(RequestAttributes.EDIT_USER);
UserAccount userAccount = userForm.getUserAccount();
if (null != editUser) {
//invoked when edit user page is submitted
userUtils.updateUserAccount(userAccount);
} else {
// invoked when edit user page gets loaded
String userAccSID = (String) request
.getParameter(USER_ACC_SID);
String roleSID = (String) request.getParameter(ROLE_SID);
if (null != userAccSID && null != roleSID) {
Long userAccSIDVal = Long.valueOf(userAccSID);
Long roleSIDVal = Long.valueOf(roleSID);
userAccount = userUtils
.loadUserAccount(userAccSIDVal);
userForm.setUserAccount(userAccount);
}
}
}
return result;
}
public UserForm getUserForm() {
return userForm;
}
public void setUserForm(UserForm userForm) {
this.userForm = userForm;
}
而对于JSP页面的代码是
<s:form action="edit?editUser=edit">
<table align="center">
<s:hidden name="userForm.userAccount.createdBy"/>
<tr align="center">
<th>Edit User</th>
</tr>
<tr>
<td><s:textfield name="userForm.userAccount.firstName" label="First Name"/></td>
</tr>
<tr>
<td><s:textfield name="userForm.userAccount.lastName" label="Last Name"/></td>
</tr>
<tr>
<td><s:submit value="Save" /><s:reset value="Cancel" /></td>
</tr>
</table>
现在,如果我把createdBy为隐藏,然后我可以得到的价值在行动中创建。 它的价值已经由行动类设置。 那么,为什么我应该在jsp页面中设置呢?
任何帮助将不胜感激。谢谢
没有特定的代码/错误消息/堆栈跟踪/值,几乎不可能建议你。 – beny23