1 2 Previous Next 26 Replies Latest reply on Feb 6, 2008 2:58 PM by vishnu_d

    Got it y'all. Here's a working Struts bridge example (2.6.1)

    nm-156

      I was finally able to piece together the relevant pieces of documentation to make a simple Struts application work as a portlet in JBoss Portal 2.6.1. (JBoss AS 4.0.5)

      Here are the relevant configuration files. You should be able to create the rest, as it is just a simple HelloWorld type Struts app.

      1.In web.xml, change Struts ActionServlet entry from:

      org.apache.struts.action.ActionServlet

      to:

      org.apache.portals.bridges.struts.PortletServlet

      2.Download the struts portal bridge jar from:

      http://portals.apache.org/bridges/download.html

      (Note that you must extract the jar from the downloaded archive file)

      and place it in the /WEB-INF directory OR the server's /lib directory

      3.Create the following descriptor files, and place them in the /WEB-INF directory of the project:

      portlet.xml:

      
      <?xml version="1.0" encoding="UTF-8"?>
      <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
       version="1.0">
       <portlet>
       <portlet-name>TestStrutsPortlet</portlet-name>
       <display-name>TestStrutsPortlet</display-name>
       <description>This is a Struts Test Portlet</description>
       <portlet-class>org.apache.portals.bridges.struts.StrutsPortlet</portlet-class>
       <init-param>
       <name>ServletContextProvider</name>
       <!-- The following portal implementation has been configured manually -->
       <value>org.jboss.portal.bridge.JBossServletContextProvider</value>
       </init-param>
       <init-param>
       <name>ViewPage</name>
       <value>/login.do</value>
       </init-param>
       <init-param>
       <name>EditPage</name>
       <value>/login.do</value>
       </init-param>
       <expiration-cache>-1</expiration-cache>
       <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>VIEW</portlet-mode>
       </supports>
       <supports>
       <mime-type>text/html</mime-type>
       <portlet-mode>EDIT</portlet-mode>
       </supports>
       <portlet-info>
       <title>Struts Validator Portlet</title>
       <short-title>Struts</short-title>
       <keywords>Struts, validator</keywords>
       </portlet-info>
       </portlet>
      </portlet-app>
      
      


      portlet-instances.xml:

      
      <?xml version="1.0" standalone="yes"?>
      
      <!DOCTYPE deployments PUBLIC
       "-//JBoss Portal//DTD Portlet Instances 2.6//EN"
       "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
      
       <!-- This is a JBoss-specific portal deployment descriptor -->
      
      <deployments>
       <deployment>
       <instance>
       <instance-id>TestStrutsPortletInstance</instance-id>
       <portlet-ref>TestStrutsPortlet</portlet-ref>
       </instance>
       </deployment>
      </deployments>
      
      


      <any_name_you_want>-object.xml:

      
      <?xml version="1.0" encoding="UTF-8"?>
      
      <!DOCTYPE deployments PUBLIC
       "-//JBoss Portal//DTD Portal Object 2.6//EN"
       "http://www.jboss.org/portal/dtd/portal-object_2_6.dtd">
      
       <!-- This is a JBoss-specific portal deployment descriptor -->
       <!-- parent-ref element specifies portal and portal page -->
      
      <deployments>
       <deployment>
       <parent-ref>default.default</parent-ref>
       <if-exists>overwrite</if-exists>
       <window>
       <window-name>TestPortletWindow</window-name>
       <instance-ref>TestStrutsPortletInstance</instance-ref>
       <region>center</region>
       <height>1</height>
       </window>
       </deployment>
      </deployments>
      
      


      struts-portlet-config.xml:

      
      <?xml version="1.0" encoding="UTF-8"?>
      
      <config>
       <render-context>
       <attribute name="errors"/>
       <attribute name="message" keep="true"/>
       </render-context>
       <portlet-url-type default="action">
       <action path="/login.do"/>
       <action path="/testStrutsPortlet.do"/>
       </portlet-url-type>
      </config>
      
      


      4.Unzip the struts portal bridge jar into a directory and extract the struts portal specific .tld files from the tld directory. Put them in your WEB-INF directory (These files are important because they will rewrite the URLs to access the portal)

      Sample JSPs that import the TLDs:

      login.jsp:

      
      <?xml version="1.0" encoding="UTF-8" ?>
      <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
      <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
      <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
      <%@ taglib uri="/WEB-INF/struts-portlet-html.tld" prefix="html" %>
      
      <%@ page language="java" contentType="text/html; charset=UTF-8"
       pageEncoding="UTF-8"%>
      
      <portlet:defineObjects/>
      
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>Results</title>
      </head>
      <body>
      
       <html:form styleId="testForm" action="/testStrutsPortlet.do" method="POST">
       <table>
       <tr><td><label>User:</label></td>
       <td><html:text property="user" size="15"/></td>
       </tr>
       <tr><td><label>Password:</label></td>
       <td><html:password property="pwd" size="15"/></td>
       </tr>
       <tr><td><html:submit value="Search"/></td></tr>
       </table>
       </html:form>
      
      
      </body>
      </html>
      
      


      results.jsp:

      
      <?xml version="1.0" encoding="UTF-8" ?>
      <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
      <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
      <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
      <%@ taglib uri="/WEB-INF/struts-portlet-html.tld" prefix="html" %>
      
      <%@ page language="java" contentType="text/html; charset=UTF-8"
       pageEncoding="UTF-8"%>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      <bean:define id="input_form" name="test_form"/>
      
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>Response</title>
      </head>
      <body>
      
      <h3>Hello, <bean:write name="input_form" property="user"/>. I am Brainiac.</h3>
      
      </body>
      </html>
      
      


      In this example, login.jsp is set up to be the target forward of the first action called in the app (it's the first JSP shown as a portlet). results.jsp is associated with the forward that handles the response (/testStrutsPortlet.do). Note the the <init-param> tags are the reason the login page is displayed.

      This is just a bare bones example. The config files and .tlds are the keys to get it working.


        1 2 Previous Next