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 James Dixon <ja...@canberra.edu.au> on 2005/06/03 08:17:35 UTC

Redirecting to other JSP pages within a portal in JetSpeed2

Hi there

 

I've been tearing my hair out all day trying to solve what seems to be a
fairly simple issue.  I want to put a very simple JSP application into a
portlet.  This application will have links to other JSP pages within the
Portlet.  My first attempt was to put a plain old <a href="target.jsp">To
the Target</a>, but this doesn't work because of the RequestDispatcher does
its thing.

 

So, after working through the 'Building Portals with the Java Portal API'
book, I thought I had a solution at Chapter 13- 'Exposing an Existing
Application as a Portlet'.  Implementing this was useful, and I reckon it
might work - except for an error I am getting.  One of the things this
example does is get a RenderResponse from the page context, and then creates
the Portlet URL from there.  The code from the book is given below.


 

RenderResponse rrs = (RenderResponse) pageContext.getResponse();

PortletURL url = rrs.createRenderURL();

 

However, in the portlet, I get a java.lang.ClassCastException. :-( 

 

I think this is because the pageContext.getResponse() returns a
ServletResponse?  Anyway, the funny thing is, the cast is allowed by eclipse
and maven (ie the project compiles) - is there anyway to ensure that the
Servlet.jar being used in Jetspeed is the same one as is being compiled
before deployment into Jetspeed?

 

Alternatively, if there is an easier way to go from JSP page to JSP page in
Jetspeed2, could someone fill me in - this is driving me nuts!!

 

Thanks

 

James

 

 


Re: Redirecting to other JSP pages within a portal in JetSpeed2

Posted by Jouni Rajala <jo...@systeemiratkaisu.fi>.
I am not 100% I understand what you have trying to do. If I have understood
correctly you have a portlet that shows set of pages as hrefs and when user
clicks url, you want portlet to show contents of that link.

You don't directly link page to that URL. Always move control to portlet
that does actual redirecting to jsp in the link. So in action your links 
always
point to portlet and you pass as parameter what page you want to show.
Then in end of doView method you dispatch to jsp that was requested
in parameter.

I use bit similar scheme in one online shop where i need different
styles of view into product and category lists. Administrator sets in
edit mode what jsp is used in view mode to show category or product
list for user. Easier to implement vertical, horizontal and grid style
layouts with or without images by using different jsp of each layout than
implement all different view modes into same jsp. But because data
is same, there is no need to use different Portlet.

--
Jouni Rajala

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


Re: Redirecting to other JSP pages within a portal in JetSpeed2

Posted by Raphaël Luta <ra...@apache.org>.
James Dixon wrote:
> Hi there
> 
>  
> 
> I've been tearing my hair out all day trying to solve what seems to be a
> fairly simple issue.  I want to put a very simple JSP application into a
> portlet.  This application will have links to other JSP pages within the
> Portlet.  My first attempt was to put a plain old <a href="target.jsp">To
> the Target</a>, but this doesn't work because of the RequestDispatcher does
> its thing.
> 
>  
> 
> So, after working through the 'Building Portals with the Java Portal API'
> book, I thought I had a solution at Chapter 13- 'Exposing an Existing
> Application as a Portlet'.  Implementing this was useful, and I reckon it
> might work - except for an error I am getting.  One of the things this
> example does is get a RenderResponse from the page context, and then creates
> the Portlet URL from there.  The code from the book is given below.
> 
> 
>  
> 
> RenderResponse rrs = (RenderResponse) pageContext.getResponse();
> 
> PortletURL url = rrs.createRenderURL();
> 
>  
> 
> However, in the portlet, I get a java.lang.ClassCastException. :-( 
> 
>  

If you want to access the portlet API objects in a JSP, you'll need to
"load" the appopriate objects by using the Pluto portlet taglib:

Basic skeleton portlet jsp:
<%@ taglib uri='/WEB-INF/portlet.tld' prefix='portlet'%>
<portlet:defineObjects/>

You can then use the actionURL and renderURL tags to generate
URLS pointing back to the portal.

Note however, that the Portlet API *does not* allow to link directly
to some portlet pages using URLs since your portlet cannot really know
how the portal handles its URL.

If you simply want to show different "views" (ie different JSPs) in your
portlet, you'll need to have some "controller" logic in your portlet.

The most basic is to take a request parameter (for example "target" whose
value is your jsp page name) and in your main portlet code (or default
JSP page) read the request parameter and forward or include the target
JSP.

basic example:
<%@ taglib uri='/WEB-INF/portlet.tld' prefix='portlet'%>
<portlet:defineObjects/>

<jsp:forward page="<%= renderRequest.getParameter("page") %>" />

I strongly urge you to look at using existing frameworks and bridges
like Struts or JSF/Myfaces, that mostly handle this controlling logic
for you either when used in stand-alone servlets or portlets.

You'll find some example codes in jetspeed-2/applications/.

-- 
Raphaël Luta - raphael@apache.org
Apache Portals - Enterprise Portal in Java
http://portals.apache.org/

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