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

No comments:

Post a Comment