From: Joern T. <joe...@be...> - 2011-10-17 11:40:40
|
Am 15.10.11 01:53, schrieb Nate Marks: > Hi everyone, > I'm using betterform and existdb and learning from the many helpful > examples I've seen, but I'm baffled by this. I have an xquery that > generates an xform. the submit in the xform calls another xquery > (successfully) to replace the instance named 'response'. All that > seems to work, but I'm doing something wrong on the submit such that > the value of 'input' never gets captured by the get-id.xq, so the > response I get back is based on the default get-parameter value ("yy > ook'). I'd really appreciate another pair of eyes. hm, sorry - i don't understand what the actual problem is here. Just one thing - you probably should be careful to use replace="all" on your submission. This will always shut down your current form - which is probably not what you'd like to do. You cannot directly return a new form from a submission. This won't get processed. Instead you can use a load action to achieve the same thing. > > NOTE: if it looks familair, it's because I'm smashing up Dan McCreary's > CRUDs example as an educational tool:D > > Here's the xform: > > xquery version "1.0"; > > (: XQuery to construct an XForm for either a new or update :) > > (: media-type for Firefox plugin to render :) > declare option exist:serialize "method=xhtml media-type=application/xhtml+ > xml indent=yes"; > > let $new := request:get-parameter('new', '') > let $id := request:get-parameter('id', '') > > return > (: check for required parameters :) > if (not($new or $id)) > then ( > <error> > <message>Parameter "new" and "id" are both missing. One of these two > arguments is required for form.</message> > </error>) > else > let $server-port := substring-before(request:get-url(), > '/exist/rest/db/') > let $collection := '/db/app-organization/data' > > (: put in the appropriate file name :) > let $file := if ($new) > then ('new-instance.xml') > else ( concat( $server-port, '/exist/rest', $collection, '/', > $id, '.xml')) > return > <html xmlns="http://www.w3.org/1999/xhtml" > xmlns:xf="http://www.w3.org/2002/xforms" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:ev="http://www.w3.org/2001/xml-events" > > <head> > <title>Edit Item</title> > <style language="text/css"> > <![CDATA[ > @namespace xf url("http://www.w3.org/2002/xforms"); > body {font-family: Arial, Helvetica; sans-serif;} > > /* This line ensures all the separate input controls appear > on their own lines */ > xf|output, xf|input, xf|select, xf|select1, xf|textarea > {display:block; margin:5px 0;} > > /* Makes the labels right aligned in a column that floats to > the left of the input controls. */ > xf|output > xf|label, > xf|input > xf|label, > xf|secret > xf|label, > xf|select > xf|label, > xf|select1 > xf|label, > xf|textarea > xf|label > {text-align:right; padding-right:10px; width:160px; float:left;} > > /* the input values are left aligned */ > xf|value { > text-align: left; > } > > .description textarea { > height: 4em; /* a bit less than four lines to > demonstrate scrolling */ > width: 500px; > } > > ]]> > </style> > <xf:model> > <!-- this line loads either the new instance or the current data file > into the form model --> > <xf:instance xmlns="" src="{$file}" id="my-faq"/> > > <xf:submission id="save" method="post" action="{if ($new='true') then > ('save-new.xq') else ('update.xq')}" instance="my-task" replace="all"/> > > > <xf:instance id="request" xmlns=""> > <data> > <input>abcdefghi</input> > <pattern>def</pattern> > <replacement>123</replacement> > </data> > </xf:instance> > <xf:instance id="response" xmlns=""> > <data/> > </xf:instance> > > <xf:submission id="submit" method="get" action="get-id.xq" > replace="instance" instance="response"/> > > > > </xf:model> > </head> > <body> > <a href="../index.xhtml">Item Home</a> > <a > href="../views/list-items.xq">List all Items</a> > <h2>Edit Item</h2> > > {if ($id) > then ( > <xf:output ref="id" class="id"> > <xf:label>ID:</xf:label> > </xf:output> > ) else ()} > > <xf:input ref="instance('request')/input"> > <xf:label>Name:</xf:label> > </xf:input> > > <xf:input ref="//organization/@CRM-reference"> > <xf:label>CRM Reference:</xf:label> > </xf:input> > > <xf:textarea ref="//organization/@notes" class="description"> > <xf:label>Notes:</xf:label> > </xf:textarea> > > <xf:trigger> > <xf:label>Submit</xf:label> > <xf:action ev:event="DOMActivate"> > <xf:send submission="submit"/> > </xf:action> > </xf:trigger> > </body> > </html> > > > > Here's the get-id.xq > > > xquery version "1.0"; > declare namespace exist = "http://exist.sourceforge.net/NS/exist"; > declare namespace system="http://exist-db.org/xquery/system"; > declare namespace request="http://exist-db.org/xquery/request"; > declare option exist:serialize "method=xml media-type=text/xml indent=yes"; > > let $doublequote := """ > let $singlequote := "'" > > let $name := request:get-parameter('input', 'yyy ook') > > let $name := replace($name,$doublequote,'') > let $name := replace($name,$singlequote,'') > let $name := normalize-space($name) > let $assetid := replace($name,' ','-') > > return > <results> > <newname>{$name}</newname> > <new-assetid>{$assetid}</new-assetid> > </results> > > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure contains a > definitive record of customers, application performance, security > threats, fraudulent activity and more. Splunk takes this data and makes > sense of it. Business sense. IT sense. Common sense. > http://p.sf.net/sfu/splunk-d2d-oct > > > > _______________________________________________ > Betterform-users mailing list > Bet...@li... > https://lists.sourceforge.net/lists/listinfo/betterform-users |