portals-jetspeed-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Sean Taylor <da...@bluesunrise.com>
Subject Re: Passing a Collection of Objects to a JSP
Date Tue, 22 Apr 2008 03:47:27 GMT

On Apr 21, 2008, at 1:11 PM, Dan Olsen wrote:

> But how do I get the Collection of object from the doView function  
> to the JSP page?
>

Here is an example of using JSP and portlet tags, also showing both  
app and portlet session scoping as well:

------
the JSP view:

<%@ page session="true" contentType="text/html;charset=utf-8"%>
<%@ taglib uri='/WEB-INF/portlet.tld' prefix='portlet'%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix='c' %>
<%@include file="/WEB-INF/view/include/portletDefineObjects.jsp" %>

<jsp:useBean id="appScoped" scope="session" class="java.lang.String" />
<jsp:useBean id="portltScoped" scope="request"  
class="java.lang.String" />
<b>test</b>


<form method="POST" action="<portlet:actionURL/>">
     <label for='portletScoped'>Portlet Scope Value:</label>
	<input type="text" name="portletScoped" value='<c:out value="$ 
{portletScoped}"/>' size="20"/>
	<input type="submit" value="Submit"/>
</form>

<form method="POST" action="<portlet:actionURL/>">
     <label for='appScopedCount'>Application Scope Value:</label>
	<input type="text" name="appScoped" value='<c:out value="$ 
{appScoped}"/>' size="20"/>	
	<input type="submit" value="Submit"/>
</form>

---
the java doView:

	public void doView(RenderRequest request, RenderResponse response)  
throws PortletException, IOException {
		String portletScoped = (String)
			request.getPortletSession().getAttribute("portletScoped",  
PortletSession.PORTLET_SCOPE);
		if (portletScoped == null)
			portletScoped = "";
         request.setAttribute("portletScoped", portletScoped);		
		super.doView(request, response);
	}

--
the action:

	public void processAction(ActionRequest request, ActionResponse  
response) throws PortletException, IOException
	{
		PortletSession session = request.getPortletSession(true);
		String appScoped = request.getParameter("appScoped");
		if (!StringUtils.isEmpty(appScoped))
		{
			session.setAttribute("appScoped", appScoped,  
PortletSession.APPLICATION_SCOPE);
		}
		String portletScoped = request.getParameter("portletScoped");
		if (!StringUtils.isEmpty(portletScoped))
		{
			session.setAttribute("portletScoped", portletScoped,  
PortletSession.PORTLET_SCOPE);
		}		
	}



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Mime
View raw message