gpt4 book ai didi

redirect - 条纹 : RedirectResolution; How can I redirect to specific action event?

转载 作者:行者123 更新时间:2023-12-02 00:41:06 26 4
gpt4 key购买 nike

我的 stripes 应用程序中有一个 Action bean。默认处理程序/方法将显示数据列表,即我所有的 MarketResearch 对象的列表

在我的 JSP 上,我可以单击一个以查看其详细信息,这会将我带到另一个 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;
}


}

这可能吗?还是我从一个糟糕的角度来处理这种情况,应该重构?

谢谢

最佳答案

是的。您可以将 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。

关于redirect - 条纹 : RedirectResolution; How can I redirect to specific action event?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2540214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com