ストライプ:私は、フォームを事前に取り込むことができますが、提出後にフォームBeanがnullの場合

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

  •  13-09-2019
  •  | 
  •  

質問

私は、私の場合は、オブジェクト、clientと私のストライプ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がゼロになり見ることができます。

私は自分の行動でclientオブジェクトにフォームBeanをバインドする何かを逃したことがありますか?

おかげ

役に立ちましたか?

解決

あなたの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