【问题标题】:Stripes: I can pre-populate a form, but after submit the formBean is null条纹:我可以预填充表单,但提交后 formBean 为空
【发布时间】:2009-12-06 18:05:37
【问题描述】:

我可以用一个对象预填充我的 Stripes JSP 表单,在我的例子中是 client,但是当我提交这个表单时,我的对象返回为 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 对象的内容?

谢谢

【问题讨论】:

    标签: stripes


    【解决方案1】:

    在你的 JSP 中添加这一行:

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

    【讨论】:

      【解决方案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();
          //...
      }
      

      【讨论】:

        猜你喜欢
        • 2017-07-16
        • 1970-01-01
        • 2018-04-11
        • 2012-11-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-22
        • 1970-01-01
        相关资源
        最近更新 更多