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 Michael Binette <je...@adinquiry.com> on 2007/01/25 14:57:51 UTC

JSP and Portal Scoped beans

I have a portlet that is derived from GenericPortlet.  In the 
processAction class I have the following code:

plant = new Plant();
plant.setPlantName("My Plant");
request.getPortletSession ().setAttribute("plant", plant, 
PortletSession.PORTLET_SCOPE);


I also have a doView that simply returns the proper JSP file.  I also 
put a log message in there to make sure that the attribute "plant" 
existed and it does.

In the JSP I have the following:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ page import="javax.portlet.* "%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core 
<http://java.sun.com/jsp/jstl/core>" prefix="c"%>
<%@ taglib uri="http://java.sun.com/portlet 
<http://java.sun.com/portlet>" prefix="portlet"%>

<portlet:defineObjects />

<c:out value="plantName: ${plant.plantName}"/>

<form method="post" action="<portlet:actionURL/>" portletMode="view">
    Plant Name: <input type="text" name="plantName" 
value="${plant.plantName}" />
    <input type="submit" name="savePlant" value="Save"/>
    <input type="submit" name="cancelEditPlant" value="Cancel"/>
</form>

The ${plant.plantName} does not work.  But if I change my processAction 
method to put plant in APPLICATION_SCOPE, it works.  Am I missing 
something here?

--
Thanks,
Michael Binette


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


Re: JSP and Portal Scoped beans

Posted by Aaron Evans <aa...@gmail.com>.
I suspect that

<c:out value="plantName: ${plant.plantName}"/>

is looking for the session attribute via the HTTPServletRequest object
rather than the Portlet's RenderRequest object.

Perhaps there is an equivalent portlet tag.

Personally (and call me old-school) I got sick of having to use tonnes
of nested, complicated tags to do the simplest of things a long time
ago so I just use scriplets. ;-)

Use this and you'll be all set (although you'll have to do a page
import of the Plant class):

<%= ((Plant) renderRequest.getPortletSession().getAttribute("plant")).getPlantName()
%>

-aaron

On 1/25/07, Michael Binette <je...@adinquiry.com> wrote:
> I have a portlet that is derived from GenericPortlet.  In the
> processAction class I have the following code:
>
> plant = new Plant();
> plant.setPlantName("My Plant");
> request.getPortletSession ().setAttribute("plant", plant,
> PortletSession.PORTLET_SCOPE);
>
>
> I also have a doView that simply returns the proper JSP file.  I also
> put a log message in there to make sure that the attribute "plant"
> existed and it does.
>
> In the JSP I have the following:
>
> <%@page contentType="text/html"%>
> <%@page pageEncoding="UTF-8"%>
> <%@ page import="javax.portlet.* "%>
> <%@ taglib uri="http://java.sun.com/jsp/jstl/core
> <http://java.sun.com/jsp/jstl/core>" prefix="c"%>
> <%@ taglib uri="http://java.sun.com/portlet
> <http://java.sun.com/portlet>" prefix="portlet"%>
>
> <portlet:defineObjects />
>
> <c:out value="plantName: ${plant.plantName}"/>
>
> <form method="post" action="<portlet:actionURL/>" portletMode="view">
>     Plant Name: <input type="text" name="plantName"
> value="${plant.plantName}" />
>     <input type="submit" name="savePlant" value="Save"/>
>     <input type="submit" name="cancelEditPlant" value="Cancel"/>
> </form>
>
> The ${plant.plantName} does not work.  But if I change my processAction
> method to put plant in APPLICATION_SCOPE, it works.  Am I missing
> something here?
>
> --
> Thanks,
> Michael Binette
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>
>

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