Rayas: Me pueden rellenar previamente un formulario, pero después de someter la FormBean es nula

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

  •  13-09-2019
  •  | 
  •  

Pregunta

Puedo rellenar previamente mi forma de rayas JSP con un objeto, client en mi caso, pero cuando me entregar esta forma, mi objetivo está volviendo como nulo.

he creado un segundo objeto "temp" que es un duplicado en paralelo de client y esto retiene sus valores, así que no puedo ver un problema pasar un objeto en la solicitud

Mi forma es la siguiente:

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

Mi acción parece

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 fijo un punto de interrupción en clientService.persistClient(client); puedo ver que ClientA tiene todos los valores originales del objeto, sin embargo client está anulado.

¿Me he perdido algo que une la forma de grano al objeto client en mi acción?

Gracias

¿Fue útil?

Solución

Añadir esta línea en su JSP:

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

Otros consejos

Tengo este escenario de trabajo mediante la adición de un método @Before para rehidratar el objeto anidado. Después de esto, salvo que funciona correctamente

@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();
    //...
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top