条纹:我可以预先填充表单,但之后才提交的formBean为null

StackOverflow https://stackoverflow.com/questions/1856082

  •  13-09-2019
  •  | 
  •  

我可以预先填充我的条纹JSP形式与一个对象,client在我的情况,但是当我提交这种形式,我的对象返回空。

我已经创建了一个第二“TEMP”对象,它是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零化。

有我错过了一些东西结合的形式豆到client对象在我的行为?

由于

有帮助吗?

解决方案

在JSP中添加这一行:

    <s:hidden name="client" value="${actionBean.client}"/>

其他提示

我这种情况下通过添加@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();
    //...
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top