views:

319

answers:

1

Hi,

I have an action bean in my stripes application. The default handler/method will display a list of data, a list of all my MarketResearch objects

On my JSP, I can click on one to view its details, this takes me to a different JSP with a pre-populated form based on the particular MarketResearch object that you selected.

I have another method on my action bean which is mapped to the save submit button, this takes in what is on the amended form, and persists it. After this has taken place, I want it to redirect back to the form, rather than to the listing (default handler) action, is this possible?

My action is as follows :

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;
    }


}

Is it possible? Or am I approaching the situation from a bad angle and should re-factor?

Thanks

+2  A: 

Yes. You could return a RedirectResolution to the form jsp. If you're having difficulty with the parameters, if you have them in the save() method, you could do like so:

return new RedirectResolution("/theJsp.jsp")
    .addParameter("one", one)
    .addParameter("two", two)
    .addParameter("three", three)
    .flash(this);

If you don't have the params that were passed to the form, you'll have to keep them going somehow. You could pass the MarketResearch object through the form so you'd have it there.

<stripes:hidden name="marketResearch"  value="${ActionBean.marketResearch}"/> 

And add the requisite instance variable/getter/setter on your MarketResearchActionBean.

lucas