Stripes: Je peux préremplir un formulaire, mais après la soumettre FormBean est nulle

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

  •  13-09-2019
  •  | 
  •  

Question

Je peux pré-remplir mon formulaire JSP Stripes avec un objet, client dans mon cas, mais lorsque je soumets cette forme, mon objet est de retour comme nulle.

J'ai créé un second objet « temp » qui est une copie parallèle de client et cela conserve ses valeurs, donc je ne vois pas un problème qui passe un objet dans la demande

Ma forme est la suivante:

<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>

Mon action ressemble

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");
    }
...

Si je mets un point d'arrêt à clientService.persistClient(client); je peux voir que ClientA a toutes les valeurs d'origine de l'objet, mais client est Nulled.

Ai-je manqué quelque chose qui lie le grain de forme à l'objet client dans mon action?

Merci

Était-ce utile?

La solution

Ajoutez cette ligne dans votre JSP:

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

Autres conseils

Je suis arrivé ce scénario de travail en ajoutant une méthode @Before pour réhydrater l'objet imbriqué. Après cela, sauvegarde fonctionne correctement

@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();
    //...
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top