将 bean 从操作映射到 struts2 中的表单
Mapping bean from action to a form in struts2
我使用 ModelDriven
将参数从表单 (value=username, fullname,...
) 填充到 Action 中的一个 bean(一个名为 user 的 bean)。
我怎样才能从动作到表格做同样的事情(视图仍然 value=username, fullname,...
而不是 user.username, user.fullname, ...
)
search.jsp
获取 txtSearch
并提交以查看操作。
ViewAction
使用 txtSearch
从数据库获取数据并使用 UserDTO(ViewAction 的 属性)保存
/*
我不知道如何将 属性 映射到此 view.jsp
*/
view.jsp
<s:form action="update" method="post">
<s:textfield label="Book Id" name="username" value="%{username}">
</s:textfield>
<s:textfield label="Book Title" name="fullname" value="%{fullname}">
</s:textfield>
<s:submit label="Update"></s:submit>
</s:form>
加上上面的update动作,结果又回到了view.jsp
等了几天,找到了2个方法:
1. set refreshModelBeforeResult param of ModelDriven interceptor to true
2. ActionContext.getContext().getActionInvocation().getStack().push(user);
我使用 ModelDriven
将参数从表单 (value=username, fullname,...
) 填充到 Action 中的一个 bean(一个名为 user 的 bean)。
我怎样才能从动作到表格做同样的事情(视图仍然 value=username, fullname,...
而不是 user.username, user.fullname, ...
)
search.jsp
获取txtSearch
并提交以查看操作。ViewAction
使用txtSearch
从数据库获取数据并使用 UserDTO(ViewAction 的 属性)保存/* 我不知道如何将 属性 映射到此 view.jsp */
view.jsp
<s:form action="update" method="post"> <s:textfield label="Book Id" name="username" value="%{username}"> </s:textfield> <s:textfield label="Book Title" name="fullname" value="%{fullname}"> </s:textfield> <s:submit label="Update"></s:submit> </s:form>
加上上面的update动作,结果又回到了
view.jsp
等了几天,找到了2个方法:
1. set refreshModelBeforeResult param of ModelDriven interceptor to true
2. ActionContext.getContext().getActionInvocation().getStack().push(user);