JSP + XForms

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

JSP + XForms

Alessandro  Vernet
Administrator
Can I use XForms without going through the page flow controller? Can I
generate XForms with my own JSP or servlet? The question comes up from
time to time and in fact the answer is: yes, you can. But in the past
this was not documented and there were no examples in
PresentationServer showing how to do it. If this is what you wanted,
you were on your own.

We now have two new examples showing how to generate XForms with JSP
and how to implement a "service" that can be called by XForms with a
JSP. You can find both of those examples in the latest "unstable
build", as usual available from:

http://forge.objectweb.org/nightlybuilds/ops/ops/

You can see two examples online, but the interesting things are in the
source, and for this you'll need to get a build. Nevertheless the two
examples are up on:

http://www.orbeon.com/ops/xforms-jsp/guess-the-number/
http://www.orbeon.com/ops/xforms-jsp/flickr-search/

Deployment

In the PresentationServer web archive (WAR file), all the JSPs are in
a directory called xforms-jsp. Under this directory, there is one
distinct subdirectory per example, for instance:
xforms-jsp/guess-the-number or xforms-jsp/flickr-search. Instead of
generating plain HTML, JSP files will generate XHTML + XForms, which
is then transformed by PresentationServer in HTML that the browser can
understand. This is done with the help of a filter declared in the
web.xml. In the PresentationServer web.xml, it is declared as follow:

<filter>
    <filter-name>ops-main-filter</filter-name>
    <filter-class>org.orbeon.oxf.servlet.OXFServletFilter</filter-class>
    <init-param>
        <param-name>oxf.main-processor.name</param-name>
        <param-value>{http://www.orbeon.com/oxf/processors}pipeline</param-value>
    </init-param>
    <init-param>
        <param-name>oxf.main-processor.input.config</param-name>
        <param-value>oxf:/config/filter.xpl</param-value>
    </init-param>
    <init-param>
        <param-name>oxf.error-processor.name</param-name>
        <param-value>{http://www.orbeon.com/oxf/processors}pipeline</param-value>
    </init-param>
    <init-param>
        <param-name>oxf.error-processor.input.config</param-name>
        <param-value>oxf:/ops/xforms/xforms-server-error.xpl</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>ops-main-filter</filter-name>
    <url-pattern>/xforms-jsp/*</url-pattern>
</filter-mapping>

The most important part is the url-pattern defined under
<filter-mapping>. It reads: /xforms-jsp/*. This means that all the
data generated by URL that starts with /xforms-jsp/ will be
post-processed by PresentationServer. We tell PresentationServer what
post-processing needs to happen in the web.xml: here we run the
pipeline oxf:/config/filter.xpl, which applies the epilogue on the
data generated by JSP. The epilogue will transform XHTML + XForms into
HTML and in some cases apply a theme.

Generating XHTML and XForms in JSP

The JSP generates XHTML + XForms, like a view linked from the page
flow would. To be recognized as XHTML, you need to set the appropriate
content type in your JSP by calling
response.setContentType("application/xhtml+xml"). So your JSP will
typically look like:

<% response.setContentType("application/xhtml+xml"); %>
<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:ev="http://www.w3.org/2001/xml-events">

    <xhtml:head>
        <xhtml:title>Guess The Number</xhtml:title>
        <xforms:model>
            <xforms:instance>
                ...
            </xforms:instance>
        </xforms:model>
    </xhtml:head>
    <xhtml:body>
        <xhtml:h1>My Page</xhtml:h1>
        <xforms:input ref="..."/>
        ...
    </xhtml:body>
</xhtml:html>

Implementing XForms Services with JSP

The backend of your forms is implemented in what we loosely call
"services", that is URLs that can be used with an <xforms:submission>.
Most of the time, XML is being posted to the service and XML is
returned by the service. Since services take XML as input and generate
XML, XPL is an ideal tool to implement services. However, you can also
use JSP. If you do, one of the first thing you will want to do in your
JSP file is to set the appropriate content type for the reponse:
response.setContentType("application/xml"). Using the dom4j API, you
can create an object that represents the posted document with:
Document queryDocument = xmlReader.read(request.getInputStream()). You
will then use this object to gather data about the query sent to your
service.

In XForms you reference the service implemented with JSP in the action
attribute of <xforms:submission>, as usual. For instance:

<xforms:submission id="do-query" method="post" replace="instance"
        ref="instance('query')"
        instance="photos"
action="/xforms-jsp/flickr-search/service-search.jsp"/>

Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: JSP + XForms

Adrian Baker-2
Should the error pipeline work with this approach of using a filter?

We can get a form working fine using this approach, however when there is an exception we just see the raw XML dump of the exception rather than the pretty OPS exception page.

Adrian


Alessandro Vernet wrote:
Can I use XForms without going through the page flow controller? Can I
generate XForms with my own JSP or servlet? The question comes up from
time to time and in fact the answer is: yes, you can. But in the past
this was not documented and there were no examples in
PresentationServer showing how to do it. If this is what you wanted,
you were on your own.

We now have two new examples showing how to generate XForms with JSP
and how to implement a "service" that can be called by XForms with a
JSP. You can find both of those examples in the latest "unstable
build", as usual available from:

http://forge.objectweb.org/nightlybuilds/ops/ops/

You can see two examples online, but the interesting things are in the
source, and for this you'll need to get a build. Nevertheless the two
examples are up on:

http://www.orbeon.com/ops/xforms-jsp/guess-the-number/
http://www.orbeon.com/ops/xforms-jsp/flickr-search/

Deployment

In the PresentationServer web archive (WAR file), all the JSPs are in
a directory called xforms-jsp. Under this directory, there is one
distinct subdirectory per example, for instance:
xforms-jsp/guess-the-number or xforms-jsp/flickr-search. Instead of
generating plain HTML, JSP files will generate XHTML + XForms, which
is then transformed by PresentationServer in HTML that the browser can
understand. This is done with the help of a filter declared in the
web.xml. In the PresentationServer web.xml, it is declared as follow:

<filter>
    <filter-name>ops-main-filter</filter-name>
    <filter-class>org.orbeon.oxf.servlet.OXFServletFilter</filter-class>
    <init-param>
        <param-name>oxf.main-processor.name</param-name>
        <param-value>{http://www.orbeon.com/oxf/processors}pipeline</param-value>
    </init-param>
    <init-param>
        <param-name>oxf.main-processor.input.config</param-name>
        <param-value>oxf:/config/filter.xpl</param-value>
    </init-param>
    <init-param>
        <param-name>oxf.error-processor.name</param-name>
        <param-value>{http://www.orbeon.com/oxf/processors}pipeline</param-value>
    </init-param>
    <init-param>
        <param-name>oxf.error-processor.input.config</param-name>
        <param-value>oxf:/ops/xforms/xforms-server-error.xpl</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>ops-main-filter</filter-name>
    <url-pattern>/xforms-jsp/*</url-pattern>
</filter-mapping>

The most important part is the url-pattern defined under
<filter-mapping>. It reads: /xforms-jsp/*. This means that all the
data generated by URL that starts with /xforms-jsp/ will be
post-processed by PresentationServer. We tell PresentationServer what
post-processing needs to happen in the web.xml: here we run the
pipeline oxf:/config/filter.xpl, which applies the epilogue on the
data generated by JSP. The epilogue will transform XHTML + XForms into
HTML and in some cases apply a theme.

Generating XHTML and XForms in JSP

The JSP generates XHTML + XForms, like a view linked from the page
flow would. To be recognized as XHTML, you need to set the appropriate
content type in your JSP by calling
response.setContentType("application/xhtml+xml"). So your JSP will
typically look like:

<% response.setContentType("application/xhtml+xml"); %>
<xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:ev="http://www.w3.org/2001/xml-events">

    <xhtml:head>
        <xhtml:title>Guess The Number</xhtml:title>
        <xforms:model>
            <xforms:instance>
                ...
            </xforms:instance>
        </xforms:model>
    </xhtml:head>
    <xhtml:body>
        <xhtml:h1>My Page</xhtml:h1>
        <xforms:input ref="..."/>
        ...
    </xhtml:body>
</xhtml:html>

Implementing XForms Services with JSP

The backend of your forms is implemented in what we loosely call
"services", that is URLs that can be used with an <xforms:submission>.
Most of the time, XML is being posted to the service and XML is
returned by the service. Since services take XML as input and generate
XML, XPL is an ideal tool to implement services. However, you can also
use JSP. If you do, one of the first thing you will want to do in your
JSP file is to set the appropriate content type for the reponse:
response.setContentType("application/xml"). Using the dom4j API, you
can create an object that represents the posted document with:
Document queryDocument = xmlReader.read(request.getInputStream()). You
will then use this object to gather data about the query sent to your
service.

In XForms you reference the service implemented with JSP in the action
attribute of <xforms:submission>, as usual. For instance:

<xforms:submission id="do-query" method="post" replace="instance"
        ref="instance('query')"
        instance="photos"
action="/xforms-jsp/flickr-search/service-search.jsp"/>

Alex
--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/

  

-- You receive this message as a subscriber of the [hidden email] mailing list. To unsubscribe: [hidden email] For general help: [hidden email] ObjectWeb mailing lists service home page: http://www.objectweb.org/wws



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: JSP + XForms

Alessandro  Vernet
Administrator
Hi Adrian,

Nice catch. I was running the wrong error pipeline in web.xml. And
that came from some code I just copied from an email you sent last
November, as you can see without testing it :). The fix is checked in,
but you can just edit your web.xml and when we define the filter
ops-main-filter, change the value of oxf.error-processor.input.config
as follows:

<init-param>
    <param-name>oxf.error-processor.input.config</param-name>
    <param-value>oxf:/config/error.xpl</param-value>
</init-param>

Alex

On 3/22/06, Adrian Baker <[hidden email]> wrote:

>  Should the error pipeline work with this approach of using a filter?
>
>  We can get a form working fine using this approach, however when there is
> an exception we just see the raw XML dump of the exception rather than the
> pretty OPS exception page.
>
>  Adrian
>
>
>  Alessandro Vernet wrote:
>  Can I use XForms without going through the page flow controller? Can I
> generate XForms with my own JSP or servlet? The question comes up from
> time to time and in fact the answer is: yes, you can. But in the past
> this was not documented and there were no examples in
> PresentationServer showing how to do it. If this is what you wanted,
> you were on your own.
>
> We now have two new examples showing how to generate XForms with JSP
> and how to implement a "service" that can be called by XForms with a
> JSP. You can find both of those examples in the latest "unstable
> build", as usual available from:
>
> http://forge.objectweb.org/nightlybuilds/ops/ops/
>
> You can see two examples online, but the interesting things are in the
> source, and for this you'll need to get a build. Nevertheless the two
> examples are up on:
>
> http://www.orbeon.com/ops/xforms-jsp/guess-the-number/
> http://www.orbeon.com/ops/xforms-jsp/flickr-search/
>
> Deployment
>
> In the PresentationServer web archive (WAR file), all the JSPs are in
> a directory called xforms-jsp. Under this directory, there is one
> distinct subdirectory per example, for instance:
> xforms-jsp/guess-the-number or xforms-jsp/flickr-search. Instead of
> generating plain HTML, JSP files will generate XHTML + XForms, which
> is then transformed by PresentationServer in HTML that the browser can
> understand. This is done with the help of a filter declared in the
> web.xml. In the PresentationServer web.xml, it is declared as follow:
>
> <filter>
>  <filter-name>ops-main-filter</filter-name>
> <filter-class>org.orbeon.oxf.servlet.OXFServletFilter</filter-class>
>  <init-param>
>  <param-name>oxf.main-processor.name</param-name>
> <param-value>{http://www.orbeon.com/oxf/processors}pipeline</param-value>
>  </init-param>
>  <init-param>
>  <param-name>oxf.main-processor.input.config</param-name>
>  <param-value>oxf:/config/filter.xpl</param-value>
>  </init-param>
>  <init-param>
>  <param-name>oxf.error-processor.name</param-name>
> <param-value>{http://www.orbeon.com/oxf/processors}pipeline</param-value>
>  </init-param>
>  <init-param>
>  <param-name>oxf.error-processor.input.config</param-name>
> <param-value>oxf:/ops/xforms/xforms-server-error.xpl</param-value>
>  </init-param>
> </filter>
> <filter-mapping>
>  <filter-name>ops-main-filter</filter-name>
>  <url-pattern>/xforms-jsp/*</url-pattern>
> </filter-mapping>
>
> The most important part is the url-pattern defined under
> <filter-mapping>. It reads: /xforms-jsp/*. This means that all the
> data generated by URL that starts with /xforms-jsp/ will be
> post-processed by PresentationServer. We tell PresentationServer what
> post-processing needs to happen in the web.xml: here we run the
> pipeline oxf:/config/filter.xpl, which applies the epilogue on the
> data generated by JSP. The epilogue will transform XHTML + XForms into
> HTML and in some cases apply a theme.
>
> Generating XHTML and XForms in JSP
>
> The JSP generates XHTML + XForms, like a view linked from the page
> flow would. To be recognized as XHTML, you need to set the appropriate
> content type in your JSP by calling
> response.setContentType("application/xhtml+xml"). So your JSP will
> typically look like:
>
> <% response.setContentType("application/xhtml+xml"); %>
> <xhtml:html xmlns:xforms="http://www.w3.org/2002/xforms"
>  xmlns:xhtml="http://www.w3.org/1999/xhtml"
>  xmlns:ev="http://www.w3.org/2001/xml-events">
>
>  <xhtml:head>
>  <xhtml:title>Guess The Number</xhtml:title>
>  <xforms:model>
>  <xforms:instance>
>  ...
>  </xforms:instance>
>  </xforms:model>
>  </xhtml:head>
>  <xhtml:body>
>  <xhtml:h1>My Page</xhtml:h1>
>  <xforms:input ref="..."/>
>  ...
>  </xhtml:body>
> </xhtml:html>
>
> Implementing XForms Services with JSP
>
> The backend of your forms is implemented in what we loosely call
> "services", that is URLs that can be used with an <xforms:submission>.
> Most of the time, XML is being posted to the service and XML is
> returned by the service. Since services take XML as input and generate
> XML, XPL is an ideal tool to implement services. However, you can also
> use JSP. If you do, one of the first thing you will want to do in your
> JSP file is to set the appropriate content type for the reponse:
> response.setContentType("application/xml"). Using the dom4j API, you
> can create an object that represents the posted document with:
> Document queryDocument = xmlReader.read(request.getInputStream()). You
> will then use this object to gather data about the query sent to your
> service.
>
> In XForms you reference the service implemented with JSP in the action
> attribute of <xforms:submission>, as usual. For instance:
>
> <xforms:submission id="do-query" method="post" replace="instance"
>  ref="instance('query')"
>  instance="photos"
> action="/xforms-jsp/flickr-search/service-search.jsp"/>
>
> Alex
> --
> Blog (XML, Web apps, Open Source):
> http://www.orbeon.com/blog/
>
>
>
> ________________________________
>
>
> --
> You receive this message as a subscriber of the [hidden email]
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>
>
>
>
> --
> You receive this message as a subscriber of the [hidden email]
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>
>
>

--
Blog (XML, Web apps, Open Source):
http://www.orbeon.com/blog/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet