在我的情况下,我可以使用对象client
预先填充我的Stripes JSP表单,但是当我提交此表单时,我的对象返回为null。
我创建了第二个“临时”对象,它是client
的并行副本,并且保留了它的值,所以我看不到在请求中传递对象的问题
我的表格如下:
<s:form beanclass="com.jameselsey.salestracker.action.ViewClientAction">
<s:hidden name="clientA" value="${actionBean.clientA}"/>
<s:hidden name="clientId" value="${actionBean.clientId}"/>
<table>
<tr>
<td>Name : </td>
<td><s:text name="client.name"/></td>
</tr>
<tr>
<td>Sector : </td>
<td><s:text name="client.sector"/></td>
</tr>
<!-- omitted some attirbutes, not needed here -->
</table>
</s:form>
我的行动看起来像
public class ViewClientAction extends BaseAction
{
@SpringBean
ClientService clientService;// = new ClientService();
private Integer clientId;
private Client client;
private Client clientA;
public void setClient(Client client)
{
this.client = client;
}
public Integer getClientId()
{
return clientId;
}
public void setClientId(Integer clientId)
{
this.clientId = clientId;
}
public Client getClientA()
{
return clientA;
}
public void setClientA(Client clientA)
{
this.clientA = clientA;
}
public Client getClient()
{
return client;
}
@DefaultHandler
public Resolution quickView()
{
clientA = clientService.getClientById(clientId);
client = clientService.getClientById(clientId);
return new ForwardResolution("/jsp/viewClientQuickView.jsp");
}
public Resolution save()
{
clientService.persistClient(client);
return new ForwardResolution("/jsp/reports.jsp");
}
public Resolution viewClientInfo()
{
client = clientService.getClientById(clientId);
return new ForwardResolution("/jsp/viewClientClientInfo.jsp");
}
...
如果我在clientService.persistClient(client);
处设置断点,我可以看到ClientA
包含对象的所有原始值,但client
已为空。
我是否遗漏了将表单bean绑定到我的操作中的client
对象的内容?
由于
答案 0 :(得分:4)
在JSP中添加以下行:
<s:hidden name="client" value="${actionBean.client}"/>
答案 1 :(得分:2)
我通过添加@Before方法来重新水合嵌套对象,从而使这个场景起作用。在此之后,保存正常
@Before(stages = LifecycleStage.BindingAndValidation)
public void rehydrate() {
if (context.getRequest().getParameter("save")!=null){
this.domainObject = getHibernateSession().load(DomainObject.class, context.getRequest().getParameter("id"));
}
}
public void save(){
Session session=getHibernateSession();
session.update(domainObject);
session.commit();
//...
}