4 Replies Latest reply on Oct 7, 2009 5:54 PM by Tom Hampton

    links from portlet content to another portal page

    Tom Hampton Newbie

      I need to create inline hyper-links in the content (JSP fragment) of a portlet to another portal page. What is the best way to do this. I would like to do this from the JSP not from the portlet's Java code. I am not building a menu but simply hyper-linking some of the content that appears in the portlet.

      Basically, what I need to know is how to generate the href for the anchor tag below

      I need a hyper-link to <a href="">another page</a> in the portal.
      


      I don't care if the solution is JBoss specific.


        • 1. Re: links from portlet content to another portal page
          gunther verhemeldonck Newbie

          The reference guide has a topic about this: "13.9.3. Link to other pages."

          // Get the ParentNode. Since we are inside a Window, the Parent is the Page
          PortalNode thisNode = req.getPortalNode().getParent();
          // Get the Node in the Portal hierarchy tree known as "../default"
          PortalNode linkToNode = thisNode.resolve("../default");
          // Create a RenderURL to the "../default" Page Node
          PortalNodeURL pageURL = resp.createRenderURL(linkToNode);
          // Output the Node's name and URL for users
          Samples
          149
          html.append("Page: " + linkToNode.getName() + " -> ");
          html.append("<a href=\"" + pageURL.toString() + "\">" + linkToNode.getName() + "</a>");


          • 2. Re: links from portlet content to another portal page
            Tom Hampton Newbie

            I tried the code from the reference guide but I can't get it working correctly. The following is a test portlet jsp fragment that I'm working with.

            The portal page structure is like this

            pageA
             pageB
             pageC
            


            The jsp fragment below is for a portlet that is on page B and is trying to resolve the pageURL to pageC which is a sub-page of pageB

            <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
            <%@ page isELIgnored="false" %>
            <%@ page import="org.jboss.portlet.JBossRenderRequest" %>
            <%@ page import="org.jboss.portlet.JBossRenderResponse" %>
            <%@ page import="org.jboss.portal.api.node.PortalNode" %>
            <%@ page import="org.jboss.portal.api.node.PortalNodeURL" %>
            
            <portlet:defineObjects/>
            
            <%
             JBossRenderRequest req = new JBossRenderRequest(renderRequest);
             JBossRenderResponse resp = new JBossRenderResponse(renderResponse);
            
             PortalNode thisNode = null;
             PortalNode linkToNode = null;
             PortalNodeURL pageURL = null;
            
             thisNode = req.getPortalNode().getParent();
             if (thisNode != null) linkToNode = thisNode.resolve("pageC");
             if (linkToNode != null) pageURL = resp.createRenderURL(linkToNode);
            %>
            
            
            <p>
            thisNode =
            <% if (thisNode != null) { %>
             <%= thisNode.getName() %>
            <% } else { %>
             null
            <% } %>
            </p>
            
            
            
            <p>
            linkToNode =
            <% if (linkToNode != null) { %>
             <%= linkToNode.getName() %>
            <% } else { %>
             null
            <% } %>
            </p>
            
            
            <p>
            pageURL =
            <% if (pageURL != null) { %>
             <%= pageURL.toString() %>
            <% } else { %>
             null
            <% } %>
            </p>
            


            This example also produces a bizarre and very long error on the call to thisNode.resolve(). I am not sure that I'm getting the references to JBossRenderRequest & JBossRenderResponse correctly, but the example in the reference guide does not say what the correct way is to get these objects.

            12:46:07,397 ERROR [PortalPermissionCollection] Permission check against the repository failed
            org.hibernate.HibernateException: Unable to locate current JTA transaction
            .........
            


            I'm not sure what to the correct way to do this is but I'm pretty sure I did it wrong :)

            • 3. Re: links from portlet content to another portal page
              Andy Pemberton Newbie

              The message you're getting may be resolved by configuring your jboss-portlet.xml with a transaction attribute, otherwise your two portlets won't be able to generate URLs to eachother:


              <portlet-name>YourPortlet</portlet-name>

              <trans-attribute>Required</trans-attribute>



              The the appropriate reference guide for info on the jboss-portlet.xml descriptor: http://docs.jboss.org/jbportal/v2.6.4/referenceGuide/html/jbossPortletDTD.html

              • 4. Re: links from portlet content to another portal page
                Tom Hampton Newbie

                Thanks apemberton,

                That was the trick.


                This is a pretty onerous way to create a simple link to a page. Is there a simpler way ?


                Thanks.