How to change xforms model via Javascript?

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

How to change xforms model via Javascript?

Martin Hoffmann-5
Hello guys,

I found the following snippet, to change a value in the xforms model
via Javascript. This is conform to W3C spec, I think. Unfortunately,
this does not work with Orbeon.

In the post http://mail-archive.objectweb.org/ops-users/2006-06/msg00043.html Alex says, that DOM access via Javascript is currently not implemented.

My use case is that I would like to get the remote ip from the client machine -
usually server-side accessed via "request.getRemoteHost();". The problem is in XForms I do not have the request object anymore. So I tried to include a JSP
page within the xform. There is a hidden field with the hostname. This works fine. Now, I want to copy the value to the xforms model. But do not have any idea how this can be done with your implementation.

Is there any possibility to write to the model via Javascript? I am using Intalio BPMS and the xform is a workflow task. The form output goes back to my business process. So I am a bit restricted and I would like to do it directly within the XHTML page.

Cheers,
Martin.

Snippet:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:event="http://www.w3.org/2001/xml-events">
<head>
  <script language="javascript">
    function changeMe(){
      var model = document.getElementById("myModel");
      var instance = model.getInstanceDocument ("myInstance");
      var textElements = instance.getElementsByTagName("text");
      textElements[0].firstChild.nodeValue = 'Changed!';
      model.rebuild();
      model.refresh();
     }
  </script>
  <xforms:model id="myModel">
    <xforms:instance id="myInstance">
      <text xmlns="">Change Me!</text>
    </xforms:instance>
    <xforms:instance id="script">
      <script url="javascript:changeMe()"/>
    </xforms:instance>
  </xforms:model>
</head>
<body>
  <xforms:input ref="/text"/>
  <xforms:trigger>
    <xforms:label>Change!</xforms:label>
    <xforms:load resource="javascript:changeMe()" event:event="DOMActivate"/>
  </xforms:trigger>
</body>
</html>



--
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: How to change xforms model via Javascript?

Ryan Puddephatt
Martin,
    The code you have included won't work with Orbeon, one reason why it isn't implemented is this is a possible security risk in cases where not all the instance data is shown to the user.

Orbeon do have some extention functions within their JavaScript API, goto http://www.orbeon.com/ops/doc/reference-xforms-ng#xforms-javascript of the Orbeon documentation, this may well cover what you need

You can change the value of an input on screen, but not an xpath in the instance. The rebuild and refresh should be done automatically, but you would need to create a external events (also in the documentation) or a hidden trigger to force this.

Hope this helps

Ryan

Ryan Puddephatt
Software Engineer
 
Teleflex Group - IT UK
1 Michaelson Square
Livingston
West Lothian
Scotland
EH54 7DP
 
e> [hidden email]
t> +44(0)1506 407 110
f> +44(0)1506 407 108
w> www.teleflex.com



[hidden email] wrote:
Hello guys,

I found the following snippet, to change a value in the xforms model
via Javascript. This is conform to W3C spec, I think. Unfortunately,
this does not work with Orbeon.

In the post http://mail-archive.objectweb.org/ops-users/2006-06/msg00043.html Alex says, that DOM access via Javascript is currently not implemented.

My use case is that I would like to get the remote ip from the client machine -
usually server-side accessed via "request.getRemoteHost();". The problem is in XForms I do not have the request object anymore. So I tried to include a JSP
page within the xform. There is a hidden field with the hostname. This works fine. Now, I want to copy the value to the xforms model. But do not have any idea how this can be done with your implementation. 

Is there any possibility to write to the model via Javascript? I am using Intalio BPMS and the xform is a workflow task. The form output goes back to my business process. So I am a bit restricted and I would like to do it directly within the XHTML page.

Cheers,
Martin.

Snippet:

<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:xforms="http://www.w3.org/2002/xforms" 
      xmlns:event="http://www.w3.org/2001/xml-events">
<head>
  <script language="javascript"> 
    function changeMe(){
      var model = document.getElementById("myModel");
      var instance = model.getInstanceDocument ("myInstance");
      var textElements = instance.getElementsByTagName("text");
      textElements[0].firstChild.nodeValue = 'Changed!';
      model.rebuild();
      model.refresh();
     }
  </script>
  <xforms:model id="myModel"> 
    <xforms:instance id="myInstance">
      <text xmlns="">Change Me!</text>
    </xforms:instance>
    <xforms:instance id="script"> 
      <script url=<a class="moz-txt-link-rfc2396E" href="javascript:changeMe()">"javascript:changeMe()"/>
    </xforms:instance>
  </xforms:model>
</head>
<body> 
  <xforms:input ref="/text"/>
  <xforms:trigger>
    <xforms:label>Change!</xforms:label>
    <xforms:load resource=<a class="moz-txt-link-rfc2396E" href="javascript:changeMe()">"javascript:changeMe()" event:event="DOMActivate"/>
  </xforms:trigger>
</body>
</html>

  

-- 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: How to change xforms model via Javascript?

Hank Ratzesberger
In reply to this post by Martin Hoffmann-5

Martin,

Below is a pipleline, and following and xstl snippet, that will
expose all the request parameters.  You need to put the xslt
snippet in an xhtml file with the xsl namespace defined.  (I
added that now...) The standard epilogue.xpl pipleline will
transform this for you as is, and you don't need to add the
<xsl:stylesheet>

HTH,
Hank Ratzesberger
UCSB


<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:oxf="http://www.orbeon.com/oxf/processors">
 <p:param name="data" type="output" />
 <!-- Aggregate the HTTP request parameters with the site preferences. -->
 <p:processor name="oxf:request">
  <p:input name="config">
   <config>
    <include>/request</include>
   </config>
  </p:input>
  <p:output name="data" id="request"/>
 </p:processor>
 <!-- Default processing is to Process xml data with stylesheet -->
 <p:processor name="oxf:identity">
 <p:input name="data" href="aggregate('root', #request)"/>
 <p:output name="data" ref="data"/>
 </p:processor>
</p:config>


<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
   xmlns:f="http://orbeon.org/oxf/xml/formatting"
   xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
   xmlns:xi="http://www.w3.org/2001/XInclude"
   xmlns:widget="http://www.orbeon.com/oxf/xml/widget"
   xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xsl:version="2.0">
...
    <ul>
     <li> container-type: <xsl:value-of select="/root/request/container-type" /> </li>
     <li> content-length: <xsl:value-of select="/root/request/content-length" /> </li>
     <li> content-type: <xsl:value-of select="/root/request/content-type" /> </li>
     <li> parameters: </li>
     <ul>
       <xsl:for-each select="/root/request/parameters/parameter" >
      <li> name: <xsl:value-of select="id" /> </li>
      <li> value: <xsl:value-of select="value" /> </li>
       </xsl:for-each>
     </ul>
     <li> protocol: <xsl:value-of select="/root/request/protocol" /> </li>
     <li> remote-addr: <xsl:value-of select="/root/request/remote-addr" /></li>
     <li> remote-host: <xsl:value-of select="/root/request/remote-host" /></li>
     <li> scheme: <xsl:value-of select="/root/request/scheme" /> </li>
     <li> server-name: <xsl:value-of select="/root/request/server-name" /> </li>
     <li> server-port: <xsl:value-of select="/root/request/server-port" /> </li>
     <li> is-secure: <xsl:value-of select="/root/request/is-secure" /> </li>
     <li> auth-type: <xsl:value-of select="/root/request/auth-type" /> </li>
     <li> remote-user: <xsl:value-of select="/root/request/remote-user" /> </li>
     <li> context-path: <xsl:value-of select="/root/request/context-path" /> </li>
     <li> headers: </li>
       <ul>
      <xsl:for-each select="/root/request/headers/header" >
        <li> name: <xsl:value-of select="name" /> </li>
        <li> value: <xsl:value-of select="value" /> </li>
      </xsl:for-each>
       </ul>
     <li> method: <xsl:value-of select="/root/request/method" /> </li>
     <li> path-info: <xsl:value-of select="/root/request/path-info" /> </li>
     <li> request-path: <xsl:value-of select="/root/request/request-path" /> </li>
     <li> path-translated: <xsl:value-of select="/root/request/path-translated" /> </li>
     <li> query-string: <xsl:value-of select="/root/request/query-string" /> </li>
     <li> requested-session-id: <xsl:value-of select="/root/request/requested-session-id" /> </li>
     <li> request-uri: <xsl:value-of select="/root/request/request-uri" /> </li>
     <li> request-url: <xsl:value-of select="/root/request/request-url" /> </li>
     <li> servlet-path: <xsl:value-of select="/root/request/servlet-path" /> </li>
    </ul>



----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, March 27, 2007 8:55 AM
Subject: [ops-users] How to change xforms model via Javascript?


> Hello guys,
>
> I found the following snippet, to change a value in the xforms model
> via Javascript. This is conform to W3C spec, I think. Unfortunately,
> this does not work with Orbeon.
>
> In the post http://mail-archive.objectweb.org/ops-users/2006-06/msg00043.html Alex says, that DOM access via Javascript is
> currently not implemented.
>
> My use case is that I would like to get the remote ip from the client machine -
> usually server-side accessed via "request.getRemoteHost();". The problem is in XForms I do not have the request object anymore. So
> I tried to include a JSP
> page within the xform. There is a hidden field with the hostname. This works fine. Now, I want to copy the value to the xforms
> model. But do not have any idea how this can be done with your implementation.
>
> Is there any possibility to write to the model via Javascript? I am using Intalio BPMS and the xform is a workflow task. The form
> output goes back to my business process. So I am a bit restricted and I would like to do it directly within the XHTML page.
>
> Cheers,
> Martin.
>
> Snippet:
>
> <html xmlns="http://www.w3.org/1999/xhtml"
>      xmlns:xforms="http://www.w3.org/2002/xforms"
>      xmlns:event="http://www.w3.org/2001/xml-events">
> <head>
>  <script language="javascript">
>    function changeMe(){
>      var model = document.getElementById("myModel");
>      var instance = model.getInstanceDocument ("myInstance");
>      var textElements = instance.getElementsByTagName("text");
>      textElements[0].firstChild.nodeValue = 'Changed!';
>      model.rebuild();
>      model.refresh();
>     }
>  </script>
>  <xforms:model id="myModel">
>    <xforms:instance id="myInstance">
>      <text xmlns="">Change Me!</text>
>    </xforms:instance>
>    <xforms:instance id="script">
>      <script url="javascript:changeMe()"/>
>    </xforms:instance>
>  </xforms:model>
> </head>
> <body>
>  <xforms:input ref="/text"/>
>  <xforms:trigger>
>    <xforms:label>Change!</xforms:label>
>    <xforms:load resource="javascript:changeMe()" event:event="DOMActivate"/>
>  </xforms:trigger>
> </body>
> </html>
>
>


>
> --
> 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