1
votes

I am changing my code to use binds in XForms (which is better practice than using nodesets everywhere!) but I am getting errors.

The error message I receive is: "Error: XForms Error (8): id (data_criterion) does not refer to a bind element..."

From tutorials/guides I have been using, it seems as though this should work, but clearly I am missing something! (btw, I was modeling my binding code after the examples here: http://en.wikibooks.org/wiki/XForms/Bind)

I originally thought the problem was due to the fact I was using xf:select controls as opposed to xf:input like the examples, but even once I dumbed down my code to the most simplistic code, I still receive errors!

This is the model code I am using:

 <xf:model id="select_data">

     <xf:instance id="criteria_data" xmlns="">
         <file>
             <criteria>
                 <criterion></criterion>
             </criteria>
         </file>
     </xf:instance>

     <bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>

</xf:model>

As for the ui code, this is what I have:

<xf:input bind="data_criterion">
    <xf:label>Enter criteria:</xf:label>
</xf:input>

The error message I receive is: "Error: XForms Error (8): id (data_criterion) does not refer to a bind element..."

Anyone have any insight to what the problem is? Also, is there any special usage of bindings and xf:select (with xf:itemset) controls that I should be aware of? (I am ultimately using a lot of xf:select controls on my form..)

Thanks in advance!

EDIT:

I ran the code through this validator, and I got this message (refers to the bind line): "Warning: Should the following element have the XForms namespace applied?: bind (line 66)"

1
I don't see how using binds is better practice. When you don't have any validation rule for an element, then you don't need the bind and its less to write. Less code means less bugs. - Tambet
The way I see it, it is like using variables and less "hard coding". That way, if the model changes, I do not have to search through the entire document to make changes to every nodeset that should change. This could cause a lot of headaches and errors later on when modifying and maintaining code. Using binds means only one change for the document, whereas without them, it could be a hundred! Right? Therefore, I believe it is better practice. (Plus I read it somewhere ;) lol. - developer
agreed. I think the point is that "using binds is better practice" is not necessarily always true. Adding a bind adds a level of indirection, which in some cases just means you have more code to write, read, maintain, and understand, with limited benefits. - avernet

1 Answers

2
votes

A couple of things you might want to change:

  1. Not sure of this is the reason for the error, but the nodeset expression should be instance('criteria_data')/criteria/..., without file. Remember: instance() returns the root element, not the document node. (This one you took care by updating the question; good)
  2. You are missing the xf on the bind. It should be: <xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>.

See below a full example with your code, which works fine for me under Orbeon Forms:

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
      xmlns:xforms="http://www.w3.org/2002/xforms"
      xmlns:xf="http://www.w3.org/2002/xforms"
      xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
      xmlns:ev="http://www.w3.org/2001/xml-events"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
    <xhtml:head>
        <xhtml:title>SO Bind</xhtml:title>
        <xf:model id="select_data">

            <xf:instance id="criteria_data" xmlns="">
                <file>
                    <criteria>
                        <criterion>Gaga</criterion>
                    </criteria>
                </file>
            </xf:instance>
            <xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>
       </xf:model>

    </xhtml:head>
    <xhtml:body>
        <xf:input bind="data_criterion">
            <xf:label>Enter criteria:</xf:label>
        </xf:input>
    </xhtml:body>
</xhtml:html>