- A window state is an indicator of the amount of portal page space that will be assigned to the content generated by a portlet via the render method.
- The Portlet Specification defines three window states, NORMAL, MAXIMIZED and MINIMIZED. The WindowState class defines constants for these window states.
- The NORMAL window state indicates that a portlet may be sharing the page with other portlets. It may also indicate that the target device has limited display capabilities. Therefore, a portlet should restrict the size of its rendered output in this window state.
- The MAXIMIZED window state is an indication that a portlet may be the only portlet being rendered in the portal page, or that the portlet has more space compared to other portlets in the portal page. A portlet may generate richer content when its window state is MAXIMIZED.
- When a portlet is in MINIMIZED window state, the portlet should only render minimal output or no output at all.
By default, normal window state is displayed when portlet is called.
In this example, i have mentioned three window state.In process action method(called by edit mode) ,we can change portlet mode and window state.
Sample Code:
Portlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" id="com.jsr286tutorial.ninethexample.NinethExamplePortlet.2e941c2233">
<portlet>
<portlet-name>ninethExample</portlet-name>
<display-name xml:lang="en">ninethExample</display-name>
<display-name>ninethExample</display-name>
<portlet-class>com.jsr286tutorial.ninethexample.NinethExamplePortlet</portlet-class>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>edit</portlet-mode>
<window-state>normal</window-state>
<window-state>minimized</window-state>
<window-state>maximized</window-state>
</supports>
<supported-locale>en</supported-locale>
<resource-bundle>com.jsr286tutorial.ninethexample.nl.NinethExamplePortletResource</resource-bundle>
<portlet-info>
<title>ninethExample</title>
<short-title>ninethExample</short-title>
<keywords>ninethExample</keywords>
</portlet-info>
</portlet>
<default-namespace>http://ninethExample/</default-namespace>
</portlet-app>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" id="com.jsr286tutorial.ninethexample.NinethExamplePortlet.2e941c2233">
<portlet>
<portlet-name>ninethExample</portlet-name>
<display-name xml:lang="en">ninethExample</display-name>
<display-name>ninethExample</display-name>
<portlet-class>com.jsr286tutorial.ninethexample.NinethExamplePortlet</portlet-class>
<init-param>
<name>wps.markup</name>
<value>html</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>edit</portlet-mode>
<window-state>normal</window-state>
<window-state>minimized</window-state>
<window-state>maximized</window-state>
</supports>
<supported-locale>en</supported-locale>
<resource-bundle>com.jsr286tutorial.ninethexample.nl.NinethExamplePortletResource</resource-bundle>
<portlet-info>
<title>ninethExample</title>
<short-title>ninethExample</short-title>
<keywords>ninethExample</keywords>
</portlet-info>
</portlet>
<default-namespace>http://ninethExample/</default-namespace>
</portlet-app>
NinethExamplePortlet
package com.jsr286tutorial.ninethexample;
import java.io.*;
import javax.portlet.*;
public class NinethExamplePortlet extends GenericPortlet {
public static final String JSP_FOLDER = "/_ninethExample/jsp/"; // JSP folder name
public static final String VIEW_JSP = "NinethExamplePortletView"; // JSP file name to be rendered on the view mode
public static final String EDIT_JSP = "NinethExamplePortletEdit"; // JSP file name to be rendered on the edit mode
public void init() throws PortletException{
super.init();
}
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
rd.include(request,response);
}
public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, EDIT_JSP));
rd.include(request,response);
}
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
response.setPortletMode(PortletMode.VIEW);
response.setWindowState(WindowState.MAXIMIZED);
}
private static String getJspFilePath(RenderRequest request, String jspFile) {
String markup = request.getProperty("wps.markup");
if( markup == null )
markup = getMarkup(request.getResponseContentType());
return JSP_FOLDER + markup + "/" + jspFile + "." + getJspExtension(markup);
}
private static String getMarkup(String contentType) {
if( "text/vnd.wap.wml".equals(contentType) )
return "wml";
else
return "html";
}
private static String getJspExtension(String markupName) {
return "jsp";
}
}
import java.io.*;
import javax.portlet.*;
public class NinethExamplePortlet extends GenericPortlet {
public static final String JSP_FOLDER = "/_ninethExample/jsp/"; // JSP folder name
public static final String VIEW_JSP = "NinethExamplePortletView"; // JSP file name to be rendered on the view mode
public static final String EDIT_JSP = "NinethExamplePortletEdit"; // JSP file name to be rendered on the edit mode
public void init() throws PortletException{
super.init();
}
public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
rd.include(request,response);
}
public void doEdit(RenderRequest request, RenderResponse response) throws PortletException, IOException {
// Set the MIME type for the render response
response.setContentType(request.getResponseContentType());
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, EDIT_JSP));
rd.include(request,response);
}
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
response.setPortletMode(PortletMode.VIEW);
response.setWindowState(WindowState.MAXIMIZED);
}
private static String getJspFilePath(RenderRequest request, String jspFile) {
String markup = request.getProperty("wps.markup");
if( markup == null )
markup = getMarkup(request.getResponseContentType());
return JSP_FOLDER + markup + "/" + jspFile + "." + getJspExtension(markup);
}
private static String getMarkup(String contentType) {
if( "text/vnd.wap.wml".equals(contentType) )
return "wml";
else
return "html";
}
private static String getJspExtension(String markupName) {
return "jsp";
}
}
NinethExamplePortletView.jsp(view mode)
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.jsr286tutorial.ninethexample.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects/>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
This is a sample view mode page. You have to edit this page to customize it for your own use.<BR>
</DIV>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects/>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
This is a sample view mode page. You have to edit this page to customize it for your own use.<BR>
</DIV>
NinethExamplePortletEdit.jsp(edit mode)
<%@page session="false" contentType="text/html" pageEncoding="ISO-8859-1" import="java.util.*,javax.portlet.*,com.jsr286tutorial.ninethexample.*"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects/>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
<FORM ACTION='<portlet:actionURL/>' METHOD="POST">
<INPUT NAME="back" TYPE="submit" VALUE="Back to view mode">
</FORM>
</DIV>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects/>
<DIV style="margin: 6px">
<H3 style="margin-bottom: 3px">Welcome!</H3>
<FORM ACTION='<portlet:actionURL/>' METHOD="POST">
<INPUT NAME="back" TYPE="submit" VALUE="Back to view mode">
</FORM>
</DIV>
Click here to download the file