开发者

Instance data on success page

开发者 https://www.devze.com 2023-04-05 22:12 出处:网络
I have made a page that is suppose to be a common exit point (success page) for all Orbeon applications made both manually creating XFroms and by Orbeon Builder. The page is really simple as it is onl

I have made a page that is suppose to be a common exit point (success page) for all Orbeon applications made both manually creating XFroms and by Orbeon Builder. The page is really simple as it is only supposed to show a generic message that is specified in a form that gets redirected to the page after submission. This feels like a trivial task, yet I have struggled a lot with it.

The documentation says:

The "POST" solution If your XForms page responds to an HTTP POST containing XML, then it can access the content of the POST data with a special URL called input:instance: <xforms:instance id="user-data" src="input:instance"/> This results in the user-data instance being populated with the XML data posted to the XForms page. It's as easy as this! NOTE: Nothing prevents you to combine this method with getting data from the request or a service.

My page-flow.xml


    <config xmlns="http://www.orbeon.com/oxf/controller"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:oxf="http://www.orbeon.com/oxf/processors">

        <page id="main" path-info="/thankyou/" view="thankyou.xhtml"/>
        <page id="test" path-info="/thankyou/test" view="test.xhtml">
            <action when="/form/fromPage = 'test'">
                <result page="main"/>
            </action>
        </page>

        <epilogue url="oxf:/config/epilogue.xpl"/>
    </config>

thankyou.xhtml


    <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">
    <xhtml:head>
      <xhtml:title>Thank you</xhtml:title>
      <xforms:model xmlns:xforms="http://www.w3.org/2002/xforms">
      <xforms:instance id="form-instance" src="input:instance"/>

      <xforms:bind id="form-binds" nodeset="instance('form-instance')">
        <xforms:bind id="success-bind" ref="/form/success/successPageText"/>
      </xforms:bind>
      </xforms:model>
    </xhtml:head>
    <xhtml:body>
      <xhtml:p>
        <xhtml:output ref="instance('form-instance')/form/success/successPageText"/>
      </xhtml:p>
      开发者_JAVA技巧<xhtml:p>
        <xhtml:output bind="success-bind"/>
      </xhtml:p>
      <xhtml:p>
        <xhtml:a href="http://www.google.com">Away from here</xhtml:a>
      </xhtml:p>
    </xhtml:body>
    </xhtml:html>

test.xhtml


    <xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
      xmlns:xxforms="http://orbeon.org/oxf/xml/xforms">

      <xhtml:head>
        <xhtml:title>Thankyou page test</xhtml:title>
        <xforms:model id="form-model">
          <xforms:instance id="form-instance">
            <form>
              <input>text here</input>
              <fromPage>test</fromPage>
              <success>
                <successPageText>
                  This is a test.
                </successPageText>
              </success>
            </form>
          </xforms:instance>

          <xforms:bind id="form-binds" nodeset="instance('form-instance')">
            <xforms:bind id="input-bind" ref="/form/input" type="xs:string" required="true()"/>
          </xforms:bind>

          <xforms:submission id="main-submission" method="post" action="/thankyou/test"
            ref="instance('form-instance')" validate="false" replace="all"/> 
        </xforms:model>
      </xhtml:head>

      <xhtml:body>
        <xhtml:table>
          <xhtml:tr>
            <xhtml:td>
              <xforms:input bind="input-bind" id="input-control">
                <xforms:label>Type something here </xforms:label>
              </xforms:input>
            </xhtml:td>
          </xhtml:tr>
          <xhtml:tr>
            <xhtml:td>
              <xforms:submit submission="main-submission" id="submit-control">
                <xforms:label>Test</xforms:label>
                <xforms:setvalue ev:event="DOMActivate">submit</xforms:setvalue>
              </xforms:submit>
            </xhtml:td>
          </xhtml:tr>
        </xhtml:table>
      </xhtml:body>
    </xhtml:html>

The thankyou page gets loaded when submitting from the test page, but the value set for the 'successPageText' is not shown.

I have tested with a Java servlet that when submitting from other pages/forms the xml data is included with the post, but I am unable to figure how to use it on the thankyou page.


The main reason your example doesn't work is that in test.xhtml you are posting to yourself. Instead, you should post to the target page. So write the submission as:

<xforms:submission id="main-submission" method="post" 
    action="/20110920-so-thankyou/"
    ref="instance('form-instance')" validate="false" replace="all"/>

The pattern of posting to yourself, and then determining in page-flow.xml what the next page should be, is considered to be deprecated. It still works, there are still situations where it makes sense, but in the majority of the cases, the cost of the added complexity is higher than the benefits you get from this decoupling.

Finally, a couple of things very specific to your example:

  • In thankyou.xhtml, you were using <xhtml:output>, which you'll want to change to <xforms:output>.
  • The XPath expression in the first output should be instance('form-instance')/success/successPageText without form. Remember: instance() returns the root element, not the document element.
0

精彩评论

暂无评论...
验证码 换一张
取 消