%@ page session="true" %>
<%@ taglib uri='/WEB-INF/tld/portlet.tld' prefix='portlet'%>
<%@ page import="javax.portlet.*"%>
<%@ page import="java.util.*"%>
Testing renderRequest...
getAttribute(), setAttribute() and removeAttribute()...
<%
boolean allOk = true;
String attribute = (String)renderRequest.getAttribute("testName");
if (attribute==null)
{ out.print("#1 passed..."); }
else { out.print("#1 failed..."); allOk = false; }
renderRequest.setAttribute("testName", "testValue");
attribute = (String)renderRequest.getAttribute("testName");
if (attribute.equals("testValue"))
{ out.print("#2 passed..."); }
else { out.print("#2 failed..."); allOk = false; }
renderRequest.removeAttribute("testName");
attribute = (String)renderRequest.getAttribute("testName");
if (attribute==null)
{ out.print("#3 passed..."); }
else { out.print("#3 failed..."); allOk = false; }
if (allOk) { out.print("all passed."); }
else { out.print("failed."); }
%>
getAttributeNames()...
<%
allOk = true;
renderRequest.setAttribute("testName", "testValue");
renderRequest.setAttribute("testName2", "testValue2");
try
{
int nr = 1;
Enumeration attributes = renderRequest.getAttributeNames();
while (attributes.hasMoreElements())
{
String name = (String)attributes.nextElement();
attribute = (String)renderRequest.getAttribute(name);
if (attribute!=null)
{ out.print("#"+nr+" passed..."); }
else { out.print("#"+nr+" failed..."); allOk = false; }
nr++;
}
}
catch (Exception e)
{
e.printStackTrace(System.err);
out.print(""+e.toString()+"...");
allOk = false;
}
if (allOk) { out.print("all passed."); }
else { out.print("failed."); }
%>
Testing PortletContext...TBD
Testing PortletSession...
getAttribute(PORTLET_SCOPE), setAttribute(PORTLET_SCOPE) and removeAttribute(PORTLET_SCOPE)...
<%
PortletSession portletSession = renderRequest.getPortletSession();
allOk = true;
attribute = (String)portletSession.getAttribute("testName", PortletSession.PORTLET_SCOPE);
if (attribute==null)
{ out.print("#1 passed..."); }
else { out.print("#1 failed..."); allOk = false; }
portletSession.setAttribute("testName", "testValue", PortletSession.PORTLET_SCOPE);
attribute = (String)portletSession.getAttribute("testName", PortletSession.PORTLET_SCOPE);
if (attribute.equals("testValue"))
{ out.print("#2 passed..."); }
else { out.print("#2 failed..."); allOk = false; }
portletSession.removeAttribute("testName", PortletSession.PORTLET_SCOPE);
attribute = (String)portletSession.getAttribute("testName", PortletSession.PORTLET_SCOPE);
if (attribute==null)
{ out.print("#3 passed..."); }
else { out.print("#3 failed..."); allOk = false; }
if (allOk) { out.print("all passed."); }
else { out.print("failed."); }
%>
getAttributeNames()...
<%
allOk = true;
portletSession.setAttribute("testName1", "testValue1", PortletSession.PORTLET_SCOPE);
portletSession.setAttribute("testName2", "testValue2", PortletSession.PORTLET_SCOPE);
try
{
int nr = 1;
Enumeration attributes = portletSession.getAttributeNames(PortletSession.PORTLET_SCOPE);
while (attributes.hasMoreElements())
{
String name = (String)attributes.nextElement();
attribute = (String)portletSession.getAttribute(name, PortletSession.PORTLET_SCOPE);
if (attribute!=null)
{ out.print("#"+nr+" passed..."); }
else { out.print("#"+nr+" failed..."); allOk = false; }
nr++;
}
}
catch (Exception e)
{
e.printStackTrace(System.err);
out.print(""+e.toString()+"...");
allOk = false;
}
if (allOk) { out.print("all passed."); }
else { out.print("failed."); }
%>
getAttribute(APPLICATION_SCOPE)...<%=portletSession.getAttribute("globalTestName", PortletSession.APPLICATION_SCOPE)%>
setAttribute('globalTestValue', APPLICATION_SCOPE)...done<%portletSession.setAttribute("globalTestName", "globalTestValue", PortletSession.APPLICATION_SCOPE);%>
please check in your second portlet whether you get the value 'globalTestValue'. Otherwise an error occured.
<%
PortletURL url = renderResponse.createRenderURL();
url.setParameter("jspName","test2.jsp");
%>