 |
Software > WebSphere > WebSphere Portal Family >
|
 |
 |
 |
Creating a link from a servlet to a page in a virtual Portal
|
| | | Problem(Abstract) | | Sometimes when creating a portal application, you need to create links from a servlet to a page within a virtual Portal. You realize that you cannot use the standard APIs because the unique names are scoped to a specific virtual portal. | | | | | | Resolving the problem | | To create a link from a servlet to a page within a virtual portal, you can make use of extension of the already existing URL Generation Helper classes provided in technote 1265900. Use the following steps:
1. First, create a ServerContext that returns the virtual portal context root, as shown:
MyServerContext serverContext = new MyVPServerContext(request.getServerName(), request.getServerPort()+"", "testvp"); The methods will appear as follows: public String getHomeProtected() { // example! return "/myportal/"+vpRoot; } and public String getHomePublic() { // example! return "/portal/"+vpRoot; }
2. Now you can pass the server context into the OfflineURLGenerator to create a URL for you.
3. Next, call the generateUrlString with the page object ID (you cannot use the unique name). To obtain the oid string do a full xmlaccess from the virtual portal. Example
In this test case, we have a page that contains the following: <content-node action="update" active="true" allportletsallowed="true" content-parentref="6_3A7U7FH20OEPD025K1BMCJ00I6" create-type="explicit" domain="rel" objectid="6_3A7U7FH20OGQD025EGC31J10G7" ordinal="200" type="page" uniquename="this.test.page">
Take the object ID, and use the identification service to change that into an ObjectID object: javax.naming.Context ctx = new javax.naming.InitialContext(); javax.naming.Name ctxName = new javax.naming.CompositeName("portal:service/Identification"); Identification identification = (Identification) ctx.lookup(ctxName); ObjectID pageoid = identification.deserialize("6_3A7U7FH20OGQD025EGC31J10G7");
Then use that information in this call: String url = OffLineURLGenerator.generateUrlString(pageoid, null, null, serverContext, true);
The code then generates a URL to the page you need in the virtual portal. The resulting code looks like the following:
MyServerContext serverContext = new MyVPServerContext(request.getServerName(), request.getServerPort()+"", "testvp"); javax.naming.Context ctx = new javax.naming.InitialContext(); javax.naming.Name ctxName = new javax.naming.CompositeName("portal:service/Identification"); Identification identification = (Identification) ctx.lookup(ctxName); ObjectID pageoid = identification.deserialize("6_3A7U7FH20OGQD025EGC31J10G7"); String url = OffLineURLGenerator.generateUrlString(pageoid, null, null, serverContext, true); writer.println("<a href=\""+url+"\">This is a link to the portlet with no params</a>"); writer.println("</body></html>"); writer.close();
Attached are the helper classes and a sample servlet.  | | | | | | | | |
 |
| IBM, the IBM logo and ibm.com are trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the Web at "Copyright and trademark information" at www.ibm.com/legal/copytrade.shtml. |
 |
 |
 |
| Please take a moment to complete this form to help us better serve you. |
 |
 |
 |
|
|
|
 |
 |
| Product categories: |
 |
| | Software |  |
| | Organizational Productivity, Portals & Collaboration |  |
| | Portals |  |
| | WebSphere Portal |  |
| | Application Development |  |
 |
| Operating system(s): |
| |
AIX, HP-UX, Linux, Solaris, Windows, i5/OS, z/OS
|
 |
| Software version: |
| |
6.0
|
 |
| Software edition: |
| |
Enable, Express, Extend, Server
|
 |
| Reference #: |
| |
1271209
|
 |
| IBM Group: |
| | Software Group |
 |
| Modified date: |
| | 2007-09-14 |
 |
|