Stripes: Eu posso pré-preencher um formulário, mas depois de submeter o FormBean é nulo
-
13-09-2019 - |
Pergunta
Eu posso preencher previamente a minha forma Stripes JSP com um objeto, client
no meu caso, mas quando eu enviar este formulário, o meu objeto está retornando como null.
Eu criei um segundo objeto "temp", que é uma duplicata paralelo de client
e isso mantém os seus valores, então não posso ver um problema passando um objeto no pedido
Minha forma é a seguinte:
<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>
Os meus olhares de ação como
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");
}
...
Se eu definir um ponto de interrupção na clientService.persistClient(client);
eu posso ver que ClientA
tem todos os valores originais do objeto, ainda client
é anulado.
eu perdi alguma coisa que se liga a forma de feijão para o objeto client
em minha ação?
Graças
Solução
Adicione esta linha em seu JSP:
<s:hidden name="client" value="${actionBean.client}"/>
Outras dicas
Eu tenho esse cenário funcionar, adicionando um método @Before para re-hidratar o objeto aninhado. Depois disso, save funciona corretamente
@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();
//...
}