1 16 package org.springframework.webflow.action.portlet; 17 18 import javax.portlet.ActionResponse; 19 import javax.portlet.PortletMode; 20 21 import org.springframework.util.Assert; 22 import org.springframework.util.ClassUtils; 23 import org.springframework.webflow.action.AbstractAction; 24 import org.springframework.webflow.context.portlet.PortletExternalContext; 25 import org.springframework.webflow.execution.Event; 26 import org.springframework.webflow.execution.RequestContext; 27 28 44 public class SetPortletModeAction extends AbstractAction { 45 46 50 public static final String PORTLET_MODE_ATTRIBUTE = "portletMode"; 51 52 55 private PortletMode portletMode = PortletMode.VIEW; 56 57 60 public PortletMode getPortletMode() { 61 return portletMode; 62 } 63 64 67 public void setPortletMode(PortletMode portletMode) { 68 Assert.notNull(portletMode, "The portlet mode is required and cannot be null"); 69 this.portletMode = portletMode; 70 } 71 72 80 protected Event doExecute(RequestContext context) throws Exception { 81 Assert.isInstanceOf(PortletExternalContext.class, context.getExternalContext(), "'" 82 + ClassUtils.getShortName(this.getClass()) + "' can only work with 'PortletExternalContext': "); 83 PortletExternalContext portletContext = (PortletExternalContext)context.getExternalContext(); 84 if (portletContext.getResponse() instanceof ActionResponse) { 85 PortletMode mode = 86 (PortletMode)context.getAttributes().get(PORTLET_MODE_ATTRIBUTE, PortletMode.class, getPortletMode()); 87 ((ActionResponse)portletContext.getResponse()).setPortletMode(mode); 88 return success(); 89 } 90 else { 91 throw new IllegalStateException ( 95 "SetPortletModeAction can only be invoked within a Action request -- " + 96 "make sure you are not invoking it in a RenderRequest"); 97 } 98 } 99 } | Popular Tags |