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

在我的JSP上,我可以单击一个以查看其详细信息,这将带我到另一个基于您选择的特定MarketResearch对象的,具有预填充格式的JSP。

我在操作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。

09-26 08:40