November 19, 2008

How to set a cookie in spring WebFlow action

So in spring webflow 1.x there is lots of people asking how to set a cookie or read cookies in a WebFlow Action.

We have created the following utility that does that... check out

 public static ServletExternalContext getServletExternalContext(RequestContext context) {

        ExternalContext externalCntxt = context.getExternalContext();
        if (externalCntxt instanceof ServletExternalContext) {
            ServletExternalContext servletExtContext = (ServletExternalContext) externalCntxt;
            return servletExtContext;
        return null;

Note that we the instanceof check... we do that since that in unit test for the flows that extends AbstractXmlFlowExecutionTests, the ExternalContext is not an instance of ServletExternalContext

1 comment:

  1. It is included in my habit that I often visit blogs in my free time, so after landing on your blog. I have thoroughly impressed with it and decided to take out some precious time to visit it again and again. Thanks. how to use panda cookie cutter