You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Dan Olsen <da...@utah.gov> on 2008/04/21 20:03:07 UTC
Passing a Collection of Objects to a JSP
In my doView function I create a collection of objects that I want to iterate through on a JSP. What is the best way to do that? I have my dispatcher which looks like it sends the response and request variables. Can I add the Collection of objects to that? If so, then how do I iterate through it in the JSP?
Re: Passing a Collection of Objects to a JSP
Posted by David Sean Taylor <da...@bluesunrise.com>.
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
Re: Passing a Collection of Objects to a JSP
Posted by Dan Olsen <da...@utah.gov>.
But how do I get the Collection of object from the doView function to the JSP page?
>>> Serkan Camurcuoglu <se...@telenity.com> 4/21/2008 1:43 PM >>>
You can use the JSTL (JSP Standard Tag Library) foreach tag for
iteration. I've found some examples at
http://www.area.trieste.it/opencms/opencms/alkacon-documentation/examples_jstl/iterators/index.html
. By the way, if you're using a web framework such as Struts or Struts2
they also have their custom JSP tags for iteration logic.
Dan Olsen wrote:
> In my doView function I create a collection of objects that I want to iterate through on a JSP. What is the best way to do that? I have my dispatcher which looks like it sends the response and request variables. Can I add the Collection of objects to that? If so, then how do I iterate through it in the JSP?
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org
Re: Passing a Collection of Objects to a JSP
Posted by Serkan Camurcuoglu <se...@telenity.com>.
You can use the JSTL (JSP Standard Tag Library) foreach tag for
iteration. I've found some examples at
http://www.area.trieste.it/opencms/opencms/alkacon-documentation/examples_jstl/iterators/index.html
. By the way, if you're using a web framework such as Struts or Struts2
they also have their custom JSP tags for iteration logic.
Dan Olsen wrote:
> In my doView function I create a collection of objects that I want to iterate through on a JSP. What is the best way to do that? I have my dispatcher which looks like it sends the response and request variables. Can I add the Collection of objects to that? If so, then how do I iterate through it in the JSP?
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org