<portlet id="InterPortletEventPortlet" />
<portlet id="VaadinInterPortletEventPortlet" />
-->
+ <portlet id="Portlet Mode Example"/>
</category>
</display>
\ No newline at end of file
<instanceable>true</instanceable>
<ajaxable>false</ajaxable>
</portlet>
+ <portlet>
+ <portlet-name>Portlet Mode Example</portlet-name>
+ <instanceable>true</instanceable>
+ <ajaxable>false</ajaxable>
+ </portlet>
<role-mapper>
<role-name>administrator</role-name>
</supported-publishing-event>
<supported-public-render-parameter>HelloState</supported-public-render-parameter>
</portlet>
- -->
+ -->
+ <portlet>
+ <portlet-name>Portlet Mode Example</portlet-name>
+ <display-name>Portlet Mode Example</display-name>
+ <portlet-class>com.vaadin.demo.portlet.PortletModePortlet</portlet-class>
+ <init-param>
+ <name>widgetset</name>
+ <value>com.vaadin.portal.gwt.PortalDefaultWidgetSet</value>
+ </init-param>
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>view</portlet-mode>
+ <portlet-mode>edit</portlet-mode>
+ <portlet-mode>help</portlet-mode>
+ <portlet-mode>config</portlet-mode>
+ </supports>
+ <portlet-info>
+ <title>PortletModeExample</title>
+ <short-title>PortletModeExample</short-title>
+ </portlet-info>
+ </portlet>
<portlet>
<portlet-name>AddressBookPortlet</portlet-name>
</security-role-ref>
</portlet>
+ <!-- Used by the Portlet mode demo -->
+ <custom-portlet-mode>
+ <description>Custom mode</description>
+ <portlet-mode>config</portlet-mode>
+ <portal-managed>false</portal-managed>
+ </custom-portlet-mode>
+
<!--
These can be used to customize the event object types.
The types must be serializable and have JAXB binding.
import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
import javax.portlet.PortletURL;
+import javax.portlet.RenderMode;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
/*
* Always use the main window when running inside a portlet.
*/
- Window window = application.getMainWindow();
+ Window window = getPortletWindow(request, application);
if (window == null) {
throw new PortletException(ERROR_NO_WINDOW_FOUND);
}
}
}
+ /**
+ * Returns a window for a portlet mode. By default, the main window is
+ * returned. To use different portlet modes in a portlet, register windows
+ * named after the portlet modes in the application.
+ *
+ * Alternatively, a PortletListener can change the main window content.
+ *
+ * The window name requested from the application
+ *
+ * @param request
+ * @param application
+ * @return Window to show in the portlet
+ */
+ protected Window getPortletWindow(PortletRequest request,
+ Application application) {
+ PortletMode mode = request.getPortletMode();
+ if (PortletMode.VIEW.equals(mode)) {
+ return application.getMainWindow();
+ } else {
+ Window window = application.getWindow(mode.toString());
+ if (window != null) {
+ return window;
+ }
+ }
+ // no specific window found
+ return application.getMainWindow();
+ }
+
private void updateBrowserProperties(WebBrowser browser,
PortletRequest request) {
browser.updateBrowserProperties(request.getLocale(), null, request
handleRequest(request, response);
}
+ /**
+ * Handles a request for the "view" (default) portlet mode. In Vaadin, the
+ * basic portlet modes ("view", "edit" and "help") are handled identically,
+ * and their behavior can be changed by registering windows in the
+ * application with window names identical to the portlet mode names.
+ * Alternatively, a PortletListener can change the application main window
+ * contents.
+ *
+ * To implement custom portlet modes, subclass the portlet class and
+ * implement a method annotated with {@link RenderMode} for the custom mode,
+ * calling {@link #handleRequest(PortletRequest, PortletResponse)} directly
+ * from it.
+ *
+ * Note that the portlet class in the portlet configuration needs to be
+ * changed when overriding methods of this class.
+ *
+ * @param request
+ * @param response
+ * @throws PortletException
+ * @throws IOException
+ */
@Override
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
handleRequest(request, response);
}
+ /**
+ * Handle a request for the "edit" portlet mode.
+ *
+ * @see #doView(RenderRequest, RenderResponse)
+ */
+ @Override
+ protected void doEdit(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ handleRequest(request, response);
+ }
+
+ /**
+ * Handle a request for the "help" portlet mode.
+ *
+ * @see #doView(RenderRequest, RenderResponse)
+ */
+ @Override
+ protected void doHelp(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+ handleRequest(request, response);
+ }
+
@Override
public void serveResource(ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.MimeResponse;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletModeException;
import javax.portlet.PortletResponse;
import javax.portlet.PortletSession;
import javax.portlet.PortletURL;
"Shared parameters can only be set from a portlet request");
}
}
+
+ /**
+ * Sets the portlet mode. This may trigger a new render request.
+ *
+ * Portlet modes used by a portlet need to be declared in portlet.xml .
+ *
+ * @param window
+ * a window in which the render URL can be opened if necessary
+ * @param portletMode
+ * the portlet mode to switch to
+ * @throws PortletModeException
+ * if the portlet mode is not allowed for some reason
+ * (configuration, permissions etc.)
+ */
+ public void setPortletMode(Window window, PortletMode portletMode)
+ throws IllegalStateException, PortletModeException {
+ if (response instanceof MimeResponse) {
+ PortletURL url = ((MimeResponse) response).createRenderURL();
+ url.setPortletMode(portletMode);
+ window.open(new ExternalResource(url.toString()));
+ } else if (response instanceof StateAwareResponse) {
+ ((StateAwareResponse) response).setPortletMode(portletMode);
+ } else {
+ throw new IllegalStateException(
+ "Portlet mode can only be changed from a portlet request");
+ }
+ }
}
/**
* TODO document me!
- *
+ *
* @author peholmst
- *
+ *
*/
@SuppressWarnings("serial")
public class PortletCommunicationManager extends AbstractCommunicationManager {
+ themeName + "/" + resource);
}
+ /**
+ * Find the application window to use based on the portlet mode. For
+ * internal use only, not in the {@link Callback} interface.
+ *
+ * @param request
+ * @param application
+ * @return
+ */
+ public Window getPortletWindow(PortletRequest request,
+ Application application) {
+ return portlet.getPortletWindow(request, application);
+ }
+
}
public PortletCommunicationManager(Application application) {
((ActionResponse) response.getWrappedResponse())
.sendRedirect(dummyURL == null ? "http://www.google.com"
: dummyURL);
- } else
+ } else {
super.sendUploadResponse(request, response);
+ }
}
public void handleUidlRequest(ResourceRequest request,
new AbstractApplicationPortletWrapper(applicationPortlet));
}
+ @Override
+ protected Window doGetApplicationWindow(Request request, Callback callback,
+ Application application, Window assumedWindow) {
+ // find window based on portlet mode
+ if (assumedWindow == null
+ && callback instanceof AbstractApplicationPortletWrapper
+ && request.getWrappedRequest() instanceof PortletRequest) {
+ assumedWindow = ((AbstractApplicationPortletWrapper) callback)
+ .getPortletWindow((PortletRequest) request
+ .getWrappedRequest(), application);
+ }
+ return super.doGetApplicationWindow(request, callback, application,
+ assumedWindow);
+ }
}