我的条带应用程序中有一个动作bean。默认处理程序/方法将显示数据列表,即所有MarketResearch
个对象的列表
在我的JSP上,我可以单击一个查看其详细信息,这会将我带到一个不同的JSP,其中包含基于您选择的特定MarketResearch
对象的预先填充的表单。
我的动作bean上有另一个方法,它被映射到save
提交按钮,它接受修改后的表单上的内容,并保留它。在发生这种情况之后,我希望它重定向回到表单,而不是列表(默认处理程序)操作,这可能吗?
我的行动如下:
public class MarketResearchAction extends BaseAction
{
@SpringBean
ClientService clientService;
private static final String VIEW = "/jsp/marketResearch.jsp";
private Client client;
private Client clientBeforeChanges;
public Client getClient()
{
return client;
}
public void setClient(Client client)
{
this.client = client;
}
@DefaultHandler
public Resolution viewAll()
{
return new ForwardResolution(VIEW);
}
public Resolution viewClientMarketResearch()
{
if (client.getSector().equals("Education"))
{
return new ForwardResolution("/jsp/marketResearchEducation.jsp");
} else if (client.getSector().equals("Local Government"))
{
return new ForwardResolution("/jsp/marketResearchLocalGovernment.jsp");
} else if (client.getSector().equals("Housing Association"))
{
return new ForwardResolution("/jsp/marketResearchHousing.jsp");
}
return new ForwardResolution("/jsp/viewClientMarketResearch.jsp");
}
public Resolution save()
{
clientBeforeChanges = clientService.getClientById(client.getId());
clientService.persistClient(client);
getContext().getMessages().add(new SimpleMessage("{0} updated", client.getName()));
return new RedirectResolution("/MarketResearch.action").flash(this);
}
public Client getClientBeforeChanges()
{
return clientBeforeChanges;
}
public void setClientBeforeChanges(Client clientBeforeChanges)
{
this.clientBeforeChanges = clientBeforeChanges;
}
public ClientService getClientService()
{
return clientService;
}
public void setClientService(ClientService clientService)
{
this.clientService = clientService;
}
}
有可能吗?或者我是从一个坏角度接近这种情况并且应该重新考虑?
由于
答案 0 :(得分:3)
是。您可以将RedirectResolution
返回到jsp表单。如果您对参数有困难,如果您使用save()
方法,则可以这样做:
return new RedirectResolution("/theJsp.jsp")
.addParameter("one", one)
.addParameter("two", two)
.addParameter("three", three)
.flash(this);
如果您没有传递给表单的参数,您将不得不以某种方式保持它们。您可以通过表单传递MarketResearch对象,以便在那里进行。
<stripes:hidden name="marketResearch" value="${ActionBean.marketResearch}"/>
在MarketResearchActionBean
上添加必需的实例变量/ getter / setter。