줄무늬 : 양식을 사전에 인구 할 수 있지만 제출 후 Formbean은 NULL입니다.
-
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 메소드를 추가 하여이 시나리오가 작동했습니다. 그런 다음 작업을 제대로 저장하십시오
@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();
//...
}
제휴하지 않습니다 StackOverflow