The Struts servlet mapping parameter is set to:
org.apache.struts.action.RequestActionMapping
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Orbeon Forms User Guide
|
Struts Support1. IntroductionStruts is a popular Web Application framework, based on the MVC pattern. In recent years, Struts has quickly gained popularity due to its ease of use and conformance to the Model 2 pattern. This chapter demonstrates how to use Orbeon Forms in conjunction with a Struts-based Web Application in a pattern called Model 2X. It assumes that the reader is familiar with Struts. Please refer to this page for more information about the use of XSLT in place of JSP. 2. Control FlowThe following figure presents the flow of the request, from the client to the Struts servlet and Orbeon Forms pipeline:
3. Implementation
A Struts-Orbeon Forms Web Application contains two servlets: the Struts
controller server and the Orbeon Forms processor servlet. The former is the
default servlet, serving all URI, while the latter is bound to <web-app><context-param><param-name>oxf.resources.factory</param-name><param-value>org.orbeon.oxf.resources.PriorityResourceManagerFactory</param-value></context-param><context-param><param-name>oxf.resources.webapp.rootdir</param-name><param-value>/WEB-INF/resources</param-value></context-param><context-param><param-name>oxf.resources.priority.1</param-name><param-value>org.orbeon.oxf.resources.WebAppResourceManagerFactory</param-value></context-param><context-param><param-name>oxf.resources.priority.2</param-name><param-value>org.orbeon.oxf.resources.ClassLoaderResourceManagerFactory</param-value></context-param><context-param><param-name>oxf.properties</param-name><param-value>oxf:/config/properties.xml</param-value></context-param><servlet><servlet-name>struts</servlet-name><servlet-class>org.apache.struts.action.ActionServlet</servlet-class><init-param><param-name>config</param-name><param-value>/WEB-INF/struts-config.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet><servlet-name>oxf</servlet-name><servlet-class>org.orbeon.oxf.servlet.OPSServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>struts</servlet-name><url-pattern>/</url-pattern></servlet-mapping><servlet-mapping><servlet-name>oxf</servlet-name><url-pattern>*.xpl</url-pattern></servlet-mapping><servlet-mapping><servlet-name>oxf</servlet-name><url-pattern>*.css</url-pattern></servlet-mapping><servlet-mapping><servlet-name>oxf</servlet-name><url-pattern>*.js</url-pattern></servlet-mapping><servlet-mapping><servlet-name>oxf</servlet-name><url-pattern>*.gif</url-pattern></servlet-mapping><servlet-mapping><servlet-name>oxf</servlet-name><url-pattern>*.png</url-pattern></servlet-mapping></web-app>
Warning
The Struts servlet org.apache.struts.action.RequestActionMapping
The Struts controller servlet interprets the request and creates form beans
containing the request parameters. It then instantiates and calls the appropriate
action class. The result bean is then set in the request, and the request is
forwarded to the Orbeon Forms processor servlet. Struts chooses the forwarding
pages in the same way as the traditional JSP forward: through <action path="/hello" type="org.orbeon.oxf.struts.examples.hello.HelloAction" name="hello"><forward name="success" path="/hello.xpl"/></action>
Orbeon Forms utilizes a Bean generator to serialize beans from the request or session into XML. This process makes use of the Castor XML Marshaller.
The Orbeon Forms processor servlet is configured to use a simple pipeline that
looks at the request's path and executes the corresponding pipeline, feeding it with
the bean form generator. The pipeline's output is then processed through a second
pipeline, the epilogue. This allows to apply common stylesheets ot all pages, such
as style, internationalization, etc. The main pipeline is also responsible to serve
static resources, such as images or css style sheets. Theses resources are served
via the Resource Server processor. You will find below the complete source of the
Struts main pipeline. The same file, <p:config xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:f="http://orbeon.org/oxf/xml/formatting"><p:param name="data" type="output"/><p:processor name="oxf:request"><p:input name="config"><config><include>/request/request-path</include></config></p:input><p:output name="data" id="path"/></p:processor><p:processor name="oxf:xslt"><p:input name="config"><xsl:stylesheet version="1.0"><xsl:template match="/"><config>oxf:<xsl:value-of select="substring-after(/request/request-path, '/WEB-INF')"/></config></xsl:template></xsl:stylesheet></p:input><p:input name="data" href="#path"/><p:output name="data" id="url"/></p:processor><p:processor name="oxf:url-generator"><p:input name="config" href="#url"/><p:output name="data" id="user-pipeline"/></p:processor><p:processor name="oxf:xslt"><p:input name="data" href="aggregate('root', #user-pipeline, #url)"/><p:input name="config"><xsl:stylesheet version="1.0"><xsl:template match="/"><p:config><p:param name="data" type="output"/><xsl:for-each select="/root/p:config/p:param[@type='input' and @name != 'errors']"><p:processor name="oxf:bean-generator"><p:input name="mapping"><mapping/></p:input><p:input name="config"><config><attribute><xsl:value-of select="@name"/></attribute><source>request</source></config></p:input><p:output name="data" id="bean-{@name}"/></p:processor></xsl:for-each><xsl:if test="/root/p:config/p:param[@type='input' and @name = 'errors']"><p:processor name="oxf:struts-errors-generator"><p:output name="data" id="errors"/></p:processor></xsl:if><p:processor name="oxf:url-generator"><p:input name="config"><config><xsl:value-of select="/root/config"/></config></p:input><p:output name="data" id="user-pipeline"/></p:processor><p:processor name="oxf:pipeline"><p:input name="config" href="#user-pipeline"/><xsl:for-each select="/root/p:config/p:param[@type='input' and @name != 'errors']"><p:input name="{@name}" href="#bean-{@name}"/></xsl:for-each><xsl:if test="/root/p:config/p:param[@type='input' and @name = 'errors']"><p:input name="errors" href="#errors"/></xsl:if><p:output name="data" ref="data"/></p:processor></p:config></xsl:template></xsl:stylesheet></p:input><p:output name="data" id="pipeline"/></p:processor><p:processor name="oxf:pipeline"><p:input name="config" href="#pipeline"/><p:output name="data" ref="data"/></p:processor></p:config>
4. Writing a Struts View Pipeline
The
5. Accessing the Struts Application Resources
Orbeon Forms provides a mechanism to access Struts resources from an XSLT
stylesheet. You define a resource bundle in <message-resources parameter="org.orbeon.oxf.struts.examples.ApplicationResources" null="false" key="messages"/>
You access the resource bundle with the
XSLT processors use a slightly different mechanism to access the Struts message
library. Orbeon Forms provides wrappers for Xalan, Saxon 6 and 7. XSLTC
calls the Java method directly. Declare the
The following example calls the Struts support library for Xalan. It displays the
content of the <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:struts="http://www.orbeon.com/oxf/struts"><xsl:import href="oxf:/oxf/struts/struts-support-xalan.xsl"/><xsl:template match="/root/beans/guess"><xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:f="http://orbeon.org/oxf/xml/formatting"><xhtml:head><xhtml:title><xsl:value-of select="struts:message('page.title')"/></xhtml:title></xhtml:head></xhtml:html></xsl:template></xsl:stylesheet>
6. Using the Struts Validator
The Struts
validator allows you to write Javascript code to validate user input on the
browser. Struts uses the Similarly, Orbeon Forms exposes this functionality through an XSLT function. Only the first parameter is mandatory.
XSLT processors use a slightly different mechanism to access the Struts javascript library. Orbeon Forms
provides wrappers for Xalan, Saxon 6 and 8. XSLTC calls the Java method directly. Declare the
The following example shows how to call the <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:struts="http://www.orbeon.com/oxf/struts"><xsl:import href="oxf:/oxf/struts/struts-support-xalan.xsl"/><xsl:template match="/"><xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:f="http://orbeon.org/oxf/xml/formatting"><xhtml:head><xhtml:script type="text/javascript"><xsl:value-of select="struts:javascript('jsTypeForm')"/></xhtml:script></xhtml:head><xhtml:body>...</xhtml:body></xhtml:html></xsl:template></xsl:stylesheet>
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||