Re: [Xsltforms-support] [PATCH] No usefull message for non-existent bind-ids
Brought to you by:
alain-couthures
From: Kostis A. <ank...@gm...> - 2010-04-08 18:06:35
|
Hi, I implemented the most part of the changes i suggested on this thread and the development process with xsltforms is now much smoother! With the patch i attach, it is now possible to explicitely detect 2 types of binding-errors and produce 'xform-binding-exception': 1) Any empty or missing @bind attributes on XFElements (XFControl, XFGroup, XFItem, XFItemset, XFLabel, XFRepeat, AJXTree) 2) Any bad @bind IDREF attributes refering to non-existent xf:bind element IDs. The 'xforms-binding-exception' gets thrown I) either once, during xform-refresh phase, listing all binding-errors, II) or afterwards, on each error specifically as it is met. Patch against rev383. PATCH DESCRIPTION --------------------------------- I added on the 'xforms' global var the member-variable: bindErrMsgs : [], // binding-error messages gathered during refreshing This array gets updated with any binding errors detected while (xforms.building = true). At the end of xforms.refresh(), a 'xforms-binding-exception' is thrown targeted on the default-model with all these gathered errors, and then the array-var is cleared. The code performing the error-gathering check happens, * for the empty-bindings, inside the new function: XFElement.evaluateBinding(binding, ctx) * for the non-existent bind-IDs, inside the pre-existing function (as demonstrated by my previous patch): Binding.evaluate(ctx, depsNodes, depsElements) On binding-errors detected during non-building phase, the exception is thrown directly from within the above 2 functions, targeted on the affecting binding's element. I was carefull enough on the patch to preserve tab-stops and formatting. Finally, i fiddled i little with css on div#statusPanel to prepare it for longer pre-formated error-messages, by specifying min-width and min-height instead of fixed frame size. NOTES: ------------ Issues to be considered regarding improvements on the patch are the follwoing: a) Whether the Binding.evaluate() is the correct place to perform the check for non-existent bind-IDs. ** Does it improperly scream with searches returning null targets on xf:actions?, as i tried to explain in my previous email here? ** Should check be moved above on call-stack so the err-msg contain affecting's element id (apart from the bad bind-ID)? b) Did i use the xforms.error() function correctly? ** Specifically, is the 1st argument on all invocation sites always valid? ** Has the xforms.defaultModel always a value? What happens when it does not? c) Should we also apply the error-gathering on XFCoreElement descedant binding evaluations? (XFInstance, XFSubmision, XFAction, etc) d) Detect more binding-error types, i.e. null search results for binding target objects on repeats, etc. e) How does this patch behave with respect to xforms-1.1 test-suite? Due to insufficient permissions on my wortkplace's computer i couldn't build and test the xsltforms from sources, therefore i tested the patch-changes on my xsltforms.js mannually, directly. I hope everything works as i described above. If there is interest, i can send a patch against /trunk/build/xsltforms.js I tested the patch against the previous 2 xforms i have already attached on this thread, namely 'emptyBindings.xml', and 'nonExistentBindId.xml' and the updated test xform 'textBindingsErrors.xml' i attached here, and with a rather complicated xform i'm currenty working on, and i found no problems. i hope it weren't all these too pedantic... Regards, Kostis On Thu, Apr 8, 2010 at 3:57 AM, Kostis Anagnostopoulos <ank...@gm...> wrote: > After searching through the specs, i realized that my patch in > function Binding.evaluate() > would case the engine to scream > even for non-existent bidnings on actions, which it is not correct(!), > according to Xforms.1.1-chapter 4.7, see: > * http://www.w3.org/TR/xforms11/#idref-resolve > * http://www.agencexml.com/xforms-tests/testsuite/XForms1.1/Edition1/Chapt04/4.7/4.7.a.xhtml > > Nevertheless, the problem is very annoying when building xforms > because is difficult to debug typos, > particularly when merging from different forms. > > The proper behavior would be to issue 'xforms-binding-exceptions', asd > spec'ed by XForms1.1 chapter 4.5.1 > > > Additionaly i found that there is another category of annoying > fail-to-report binding problems. > These are when a 'bind', 'ref', 'nodeset' and 'value' IDERF attributes > are themselfs the empty-string ('') or absent altogether. > These problems cannot be detected from within Binding.evaluate() since > there is no binding object to begin with! > > The problem is demonstrated with the 'emptyBindings.xml' xforms below. > > > > Ideally, i would like to have a solution that gathers all these errors > and reports them at once on model-construction with a single > xforms-binding-exception, > or afterwards, with some alert with a descriptive messages > facilitating pin-pointing the error > (since i have managed to build a formthat these errors were not > detected from the start) > > Yet this check cannnot happen inside Binding.evaluate() but must be > separate for > * XFControl, > * XFCoreElement, and > * XFElement. > > > > In a summury, i'm thinking that it may be necessary to add 3 > functions, one per each super-class, > namely "evaluateBindings()" with different arguments each (3, 1, 1 respectively) > and they would perform the various sanity checks before invoking > this.binding.evaluate(). > Their behavior on these 2 error categories would be different > depending on whether the model has been constructed or not. > > Am i thinking along the correct lines, Alain? > > Regards, > Kostis > > > > file: emptyBindings.xml > ------------------- > <?xml version="1.0" encoding="UTF-8"?> > <?xml-stylesheet href="xsltforms/xsltforms.xsl" encoding="UTF-8" > type="text/xsl"?> > <html > xmlns="http://www.w3.org/1999/xhtml" > xmlns:xf="http://www.w3.org/2002/xforms" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=" > http://www.w3.org/2002/xforms > http://www.w3.org/MarkUp/Forms/2007/XForms-11-Schema.xsd > " >> > <head> > <title>Control with Empty bind-id</title> > <xf:model> > <xf:instance> > <root /> > </xf:instance> > > <xf:bind id="bind-with-no-nodeset"/> > </xf:model> > </head> > > <body> > <xf:output id="should-not-fail-1" bind="bind-with-no-nodeset" /> > <xf:repeat id="should-not-fail-3" bind="bind-with-no-nodeset" /> > <xf:select1 id="should-not-fail-2" ref="/." > > <xf:itemset bind="bind-with-no-nodeset" /> > </xf:select1> > > The control's empty-binding below fail with un-helpful err-messages. > <xf:output /> > <xf:output ref="" /> > <xf:output value="" /> > > <xf:select1 > > <xf:itemset /> > </xf:select1> > <xf:select1 > > <xf:itemset nodeset="" /> > </xf:select1> > > <xf:select > > <xf:itemset /> > </xf:select> > <xf:select > > <xf:itemset nodeset="" /> > </xf:select> > > <xf:repeat /> > <xf:repeat nodeset="" /> > > <xf:group /> > <xf:group ref="" /> > > <xf:label /> > <xf:label ref="" /> > > </body> > </html> > > > > On Thu, Apr 8, 2010 at 1:05 AM, Kostis Anagnostopoulos > <ank...@gm...> wrote: >> When a control's 'bind' attrribute refers to an xf:bind that does not exist, >> the javascript just fails with Null-Pointer message on browser console >> instead of reporting the bad bind-id. >> >> Reported against rev383, all browsers. >> >> The simple xform below reproduces the problem, and >> the following patch just issues a useful alert-window for each >> non-existent bind-id: >> >> Regards, >> Kostis >> >> file: nonExistentBindId.xml: >> ------------------ >> <?xml version="1.0" encoding="UTF-8"?> >> <?xml-stylesheet href="xsltforms/xsltforms.xsl" encoding="UTF-8" >> type="text/xsl"?> >> <html >> xmlns="http://www.w3.org/1999/xhtml" >> xmlns:xf="http://www.w3.org/2002/xforms" >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >> xsi:schemaLocation=" >> http://www.w3.org/2002/xforms >> http://www.w3.org/MarkUp/Forms/2007/XForms-11-Schema.xsd >> " >>> >> <head> >> <title>Control with non-existent bind-id</title> >> >> </head> >> >> <body> >> The output control's binding below silently fails >> (with an un-helpful null-pointer err-message visible only on the >> browser's console). >> <xf:output bind="missing-bind-id" /> >> <xf:output bind="missing-bind-id2" /> >> </body> >> </html> >> >> >> file: nonExistentBindId.diff >> ---------------- >> Index: src/js/main/Binding.js.xml >> =================================================================== >> --- src/js/main/Binding.js.xml (revision 383) >> +++ src/js/main/Binding.js.xml (working copy) >> @@ -48,7 +48,14 @@ >> var result = null; >> if (this.bind) { >> if (typeof this.bind == "string") { >> - this.bind = $(this.bind).xfElement; >> + var idel = $(this.bind); >> + if (!idel) { >> + alert("Non-Existent bind-id: "+this.bind); >> + >> + // Do not fail here, to search for more missing ids. >> + return ''; >> + } >> + this.bind = idel.xfElement; >> } >> result = this.bind.nodes; >> copyArray(this.bind.depsNodes, depsNodes); >> > |