المشارب: يمكنني مرفق نموذج مسبق، ولكن بعد إرسال النقر هو فارغة

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

  •  13-09-2019
  •  | 
  •  

سؤال

يمكنني مسبق ملء المشارب بلدي نموذج JSP مع كائن، client في حالتي، ولكن عندما أقدم هذا النموذج، يعود كائني ك NULL.

لقد قمت بإنشاء كائن "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(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