Skip to main content

URL to use in Accordian?

4 replies [Last post]
viggonavarsete
Offline
Joined: 2007-06-17
Points: 0

I have a JSF portlet where I want to use an Accordion. Since a portlet lives inside a portal, all URL's are relative to the portlet instance. To get a reference to a resource in the war file, I can do like this:
renderResponse.encodeURL( renderRequest.getContextPath() + "/resources/images/text.gif")
in my JSP file, and it will give me the following URL:
/portlet-search-java/resources/images/text.gif
The problem is to refer to a JSP to use in i.e an accordion. I've tried the following, with no luck:

I guess the URL must be an absolute URL? Any input on how to achive this? I want the content of each panel in the accordion to be rendered from two different jsp's.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi,

You will need to go through the faces servlet which invokes a phase listener to get resources out of a war file.

This means you'll need to include /faces/ or similar URI to where you have your faces servlet mapped to.

More than likely:

faces/resources/images/text.gif

The accordion widgets use the built in XMLHttpRequet objects as is so if you start a URL with a "/" this will mean the server root so it is best to use absolute URLs whenever possible and relative URLs like the one above when that is not possible.

You will also need to make sure that the resources you are trying to access are packaged correctly in a jar file in the classpath.

for faces/resources/images/text.gif to be accessible for example you will need to place text.gif
in a jar file under the directory /META-INF/resources/images/text.gif

I would suggest you look at how we put together the Dojo JSF unit test application which you may find at:

https://ajax.dev.java.net/download.html

One other thing you can do is look at the page source how the URLs are being generated for the jMaki resources like the jmaki.js which are loaded from the classpath in JSF.

viggonavarsete
Offline
Joined: 2007-06-17
Points: 0

Hi again!

The example with the resource text.gif was just an example of how I already fetch resources from a war-file.
My actual problem is to create the url in the accordion widget. Let me give you two examples, one working, and not that's not working.

part of my web.xml:

XmlHttpProxy
jmaki.xhp.XmlHttpProxyServlet


Faces Servlet
javax.faces.webapp.FacesServlet
1


XmlHttpProxy
/xhp


Faces Servlet
/faces/*

My war-file tree structure:
jsp
   summary.jsp
   textdetails.jsp
META-INF
   MANIFEST.MF
resources
   css
   dojo
   images
   jmaki
   spry
   xsl
   yahoo
   jui
   (and all other jmaki resources..)
WEB-INF
   classes
      (my JSF backing bean)
   jsp
      Search_view.jsp (my initial jsp used in my portlet, and where the jmaki widget I'm trying to use is referred to, as shown below)
   lib
      (all dependent libraries)
   faces-config.xml
   portlet.xml
   web.xml
glue.js

Then my Search_view.jsp:

(on top of the jsp)
<%-- jMaki taglib --%>
<%@ taglib prefix="a" uri="http://jmaki/v1.0/jsp" %>

<%-- JSF taglibs --%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<%-- portlet taglibs --%>
<%@ page import="javax.portlet.*"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>

<%-- A portlet custom tag exposing three portlet API objects:
- RenderRequest object, where I can get the context path to the actual portlet by calling renderRequest.getContextPath()
- RenderResponse object
- PortletConfig object
--%>

<%PortletPreferences prefs = renderRequest.getPreferences();%>

Working example which will display the content of the two jsp files inside the accordion:

Non-working example where I have replaced the hardcoded context path, /portlet-search-java :

This isn't working, and will display
Unable to load URL <%=renderRequest.getContextPath()%>/jsp/textdetails.jsp.
and
Unable to load URL <%=renderRequest.getContextPath()%>/jsp/summary.jsp.

So, the problem is that renderRequest.getContextPath() isn't replaced by /portlet-search-java when the widget is rendered.

viggonavarsete
Offline
Joined: 2007-06-17
Points: 0

I'm also having the same problem trying to use the yahoo.tabbedview widget. When referring to an existing jsp in my war file, it can't find it unless I hardcode the portlet context path into the URL, like this:
value="{tabs:[
{label : 'My Tab', content : 'Some Content'},
{label : 'My Tab 2', include : '/portlet-search-java//jsp/test.jsp' },
{label : 'My Tab 3', content : 'More Content', selected: true}
]
}" />

I've looked at the tabbelview-jsf.jsp example from the downloaded jmaki-dojo-jsf war file, where you do it like this:
value="{tabs:[
{label:'Tab 1', url: 'tab1-jsf.faces'},
{label:'Tab 2', url: 'tab2-jsf.faces'},
{label:'Tab 3', url: 'tab3-jsf.faces'},
{label:'Static Tab', content: 'Tab 2 Content'} ]}" />

and in web.xml you have the servlet-mappings


Faces Servlet
/faces/*


Faces Servlet
*.faces

but still I'm not able to retrieve the jsp's.

gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi,

I'd suggest using the latest version of jMaki and use include 'include' instread of 'url' if you are using the latest.

Is normally I would think your FacesServlet mapping not set right but it seems alright..

Are the JSP / JSF pages hosted in the same context? If not you are going to have propblems with the same origin policy.

You should be able to use fully qualified URLs to the resources outside of the domain if you set a property 'iframe' to true which will use iframes instread and allow you to include external content.

For more on the same origin policy see:

http://www.mozilla.org/projects/security/components/same-origin.html