Re: [Xsltforms-support] Dynamic loading of instance into a model
Brought to you by:
alain-couthures
From: Kostis A. <ank...@gm...> - 2010-06-09 10:08:07
|
Hi Dhiradj, This logic belongs to an <xf:action> listening to 'xforms-submit-error' event. You then can add the following action in your <xf:submission> to detect what you want: <xf:action ev:event="xforms-submit-error" if="event('response-status-code')='404'" > <xf:message>Instance Missing!</xf:message> </xf:action> Please, report if it works, i've written the above code without actually trying it. For available event() properties, see http://www.w3.org/TR/xforms11/#submit-evt-submit-error Regards, Kostis On Wed, Jun 9, 2010 at 12:57 PM, Dhiradj Badloe <dh...@gm...> wrote: > Hello Kostis, > > I have another question. When there's no instance found, i want to display a > message to the user that there's no instance? Is there a good way how to do > this? Thanks. > > Dhiradj > > On Wed, Apr 21, 2010 at 12:10 PM, Kostis Anagnostopoulos > <ank...@gm...> wrote: >> >> The code for the registration of the new functions fails. >> (you should see the errors in your broswer's console) >> If it is indeed this provlem, i think it is the '>' character that >> gets xsl-translated badly in IE. >> >> Try removing completely the argument-number checks on the url-param() >> function. >> >> >> Kostis >> >> On Wed, Apr 21, 2010 at 12:53 PM, Dhiradj Badloe <dh...@gm...> >> wrote: >> > In IE8 i still have problems with the workaround from Alain. I keep >> > getting >> > this error "XSLTForms Exception Error >> > initializing:Function http://example.com/local url-param() not found". >> > I >> > have not tested it yet in IE6/7. >> > >> > Regards, >> > Dhiradj >> > >> > On Tue, Apr 20, 2010 at 2:23 PM, Kostis Anagnostopoulos >> > <ank...@gm...> >> > wrote: >> >> >> >> In IE6 and IE7 that i tested it, it works OK. >> >> The workaround is only neccesary on Firefox. >> >> >> >> Do you see any problems? >> >> >> >> Kostis >> >> >> >> >> >> On Tue, Apr 20, 2010 at 2:38 PM, Dhiradj Badloe <dh...@gm...> >> >> wrote: >> >> > Hi Kostis, >> >> > >> >> > Is there also a workaround for Internet Explorer? >> >> > >> >> > Regards, >> >> > Dhiradj >> >> > >> >> > On Tue, Apr 20, 2010 at 12:08 PM, Kostis Anagnostopoulos >> >> > <ank...@gm...> wrote: >> >> >> >> >> >> Hi Dhiradj, >> >> >> >> >> >> Actually it is indeed possible to use a distinct namespace for >> >> >> user-defined- functions on Firefox, >> >> >> as long as you apply the "bogus-namespaced-attribute" workaround >> >> >> regarding Mozilla's bug: >> >> >> https://bugzilla.mozilla.org/show_bug.cgi?id=94270 >> >> >> (It could be usefull if you had the time to register and vote for it >> >> >> ;-)) >> >> >> >> >> >> The workaround consists of adding a bogus attribute in your >> >> >> function's >> >> >> namespace in the <html> element. >> >> >> >> >> >> >> >> >> Here is a working example from Alain COUTHURES: >> >> >> (notice the local:dummy="dummy" attribute) >> >> >> >> >> >> <html xmlns="http://www.w3.org/1999/xhtml" >> >> >> xmlns:xf="http://www.w3.org/2002/xforms" >> >> >> xmlns:local="http://example.com/local" >> >> >> local:dummy="dummy"> >> >> >> <head> >> >> >> <title>Testing local XPath functions</title> >> >> >> <script> >> >> >> XPathCoreFunctions['http://example.com/local sample'] = >> >> >> new XPathFunction(false, XPathFunction.DEFAULT_NONE, >> >> >> false, >> >> >> function() { return "a test"; } ); >> >> >> </script> >> >> >> <xf:model> >> >> >> <xf:instance> >> >> >> <dummy xmlns=""/> >> >> >> </xf:instance> >> >> >> </xf:model> >> >> >> </head> >> >> >> <body> >> >> >> <p>This is <xf:output value="local:sample()" />.</p> >> >> >> </body> >> >> >> </html> >> >> >> >> >> >> >> >> >> Regards, >> >> >> Kostis >> >> >> >> >> >> >> >> >> >> >> >> On Tue, Apr 20, 2010 at 11:25 AM, Dhiradj Badloe <dh...@gm...> >> >> >> wrote: >> >> >> > Hi Kostis, >> >> >> > >> >> >> > First, I would like to thank you for your support. >> >> >> > >> >> >> > Your solution works! I have followed the workaround and removed >> >> >> > "<xf:setfocus control="ctrl-numberFrom" />" and it works flawless. >> >> >> > >> >> >> > Thanks once again! >> >> >> > >> >> >> > Best regards, >> >> >> > Dhiradj Badloe >> >> >> > >> >> >> > >> >> >> > >> >> >> > On Mon, Apr 19, 2010 at 5:54 PM, Kostis Anagnostopoulos >> >> >> > <ank...@gm...> >> >> >> > wrote: >> >> >> >> >> >> >> >> (I'm not sure what you are asking me...) >> >> >> >> >> >> >> >> Actually you don't need to fill-in anything into @src. >> >> >> >> You can skip this attributes and insert a <dummy/> element within >> >> >> >> <xf:instance>. >> >> >> >> >> >> >> >> The actual content of the instance would be set on 'xforms-ready' >> >> >> >> from >> >> >> >> the document specified in URL. >> >> >> >> >> >> >> >> Only in case it fails to load it, then the @src or the <dummy> >> >> >> >> content >> >> >> >> would matter. >> >> >> >> >> >> >> >> >> >> >> >> Did it work? >> >> >> >> >> >> >> >> Kostis >> >> >> >> >> >> >> >> On Mon, Apr 19, 2010 at 6:20 PM, Dhiradj Badloe >> >> >> >> <dh...@gm...> >> >> >> >> wrote: >> >> >> >> > Thanks! If my xforms code is as follow: >> >> >> >> > <xf:model id="InlineWerken"> >> >> >> >> > <xf:instance id="inlinewerken" src="vte_406207_d.xml" >> >> >> >> > /> >> >> >> >> > </xf:model> >> >> >> >> > what do I need to fill in for "src"? >> >> >> >> > >> >> >> >> > On Mon, Apr 19, 2010 at 4:32 PM, Kostis Anagnostopoulos >> >> >> >> > <ank...@gm...> >> >> >> >> > wrote: >> >> >> >> >> >> >> >> >> >> You are right, I just checked it, there is a not-yet-fixed bug >> >> >> >> >> in >> >> >> >> >> Firefox (and IE?) regarding extension functions. >> >> >> >> >> >> >> >> >> >> You are also right that i forgot the workaround: >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> https://sourceforge.net/mailarchive/message.php?msg_name=w2o...@ma... >> >> >> >> >> >> >> >> >> >> Basically it boils down to using as namespace for the custom >> >> >> >> >> functions >> >> >> >> >> the refered one within the error. >> >> >> >> >> So, just replace everywhere the string: >> >> >> >> >> "http://some-url.net/nfuncs/" >> >> >> >> >> with: >> >> >> >> >> "http://www.w3.org/2005/xpath-functions" >> >> >> >> >> >> >> >> >> >> Kostis >> >> >> >> >> >> >> >> >> >> On Mon, Apr 19, 2010 at 5:13 PM, Dhiradj Badloe >> >> >> >> >> <dh...@gm...> >> >> >> >> >> wrote: >> >> >> >> >> > Hi Kostis, >> >> >> >> >> > >> >> >> >> >> > Thanks! I keep getting this error "XSLTForms Exception Error >> >> >> >> >> > initializing: >> >> >> >> >> > Function http://www.w3.org/2005/xpath-functions url-param() >> >> >> >> >> > not >> >> >> >> >> > found". >> >> >> >> >> > Have >> >> >> >> >> > you seen this before or do you know what's the cause of it? >> >> >> >> >> > Sorry >> >> >> >> >> > for >> >> >> >> >> > disturbing. >> >> >> >> >> > >> >> >> >> >> > Regards, >> >> >> >> >> > Dhiradj >> >> >> >> >> > >> >> >> >> >> > On Mon, Apr 19, 2010 at 3:59 PM, Kostis Anagnostopoulos >> >> >> >> >> > <ank...@gm...> >> >> >> >> >> > wrote: >> >> >> >> >> >> >> >> >> >> >> >> Hi Dhiradj, >> >> >> >> >> >> >> >> >> >> >> >> Check also the wiki: >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> http://en.wikibooks.org/wiki/XSLTForms/XSLTForms_only_Extensions#User-Defined_Functions >> >> >> >> >> >> >> >> >> >> >> >> Regards, >> >> >> >> >> >> Kostis >> >> >> >> >> >> >> >> >> >> >> >> On Mon, Apr 19, 2010 at 4:43 PM, Dhiradj Badloe >> >> >> >> >> >> <dh...@gm...> >> >> >> >> >> >> wrote: >> >> >> >> >> >> > Hi Kostis, >> >> >> >> >> >> > >> >> >> >> >> >> > Thanks for your reply and great solution! >> >> >> >> >> >> > Right now i'm having a problem with xpath-functions >> >> >> >> >> >> > url-param(). >> >> >> >> >> >> > As >> >> >> >> >> >> > far >> >> >> >> >> >> > as I >> >> >> >> >> >> > can see this function is not (yet) implemented in >> >> >> >> >> >> > XSLTForms. >> >> >> >> >> >> > Is >> >> >> >> >> >> > this >> >> >> >> >> >> > true? >> >> >> >> >> >> > >> >> >> >> >> >> > Regards, >> >> >> >> >> >> > Dhiradj Badloe >> >> >> >> >> >> > >> >> >> >> >> >> > On Mon, Apr 19, 2010 at 12:00 PM, Kostis Anagnostopoulos >> >> >> >> >> >> > <ank...@gm...> wrote: >> >> >> >> >> >> >> >> >> >> >> >> >> >> Hi, >> >> >> >> >> >> >> >> >> >> >> >> >> >> I had the same requirement and i succeeded in loading >> >> >> >> >> >> >> the >> >> >> >> >> >> >> dynamically-named document on "xforms-ready" (you can >> >> >> >> >> >> >> try >> >> >> >> >> >> >> "xforms-model-construct-done"). >> >> >> >> >> >> >> The name of the file was specified as a URL-parameter, >> >> >> >> >> >> >> and >> >> >> >> >> >> >> i >> >> >> >> >> >> >> used >> >> >> >> >> >> >> a >> >> >> >> >> >> >> custom XPath function to read it from page's url as >> >> >> >> >> >> >> query-parameter. >> >> >> >> >> >> >> >> >> >> >> >> >> >> Here is the action loading the dynamic-document (put it >> >> >> >> >> >> >> in >> >> >> >> >> >> >> your >> >> >> >> >> >> >> model): >> >> >> >> >> >> >> <xf:action ev:event="xforms-ready"> >> >> >> >> >> >> >> <xf:setfocus control="ctrl-numberFrom" /> >> >> >> >> >> >> >> <xf:send submission="submit-init-doc" >> >> >> >> >> >> >> if="nfuncs:url-param('init-doc') != ''"/> >> >> >> >> >> >> >> </xf:action> >> >> >> >> >> >> >> >> >> >> >> >> >> >> You need a proper submission element, i.e.: >> >> >> >> >> >> >> <xf:submission id="submit-init-doc" >> >> >> >> >> >> >> method="GET" validate="false" >> >> >> >> >> >> >> replace="instance" instance="inlinewerken" >> >> >> >> >> >> >> > >> >> >> >> >> >> >> <xf:resource value="nfuncs:url-param('init-doc')" >> >> >> >> >> >> >> /> >> >> >> >> >> >> >> </xf:submission> >> >> >> >> >> >> >> >> >> >> >> >> >> >> To add the custom nfuncs:url-param() function, do the >> >> >> >> >> >> >> following: >> >> >> >> >> >> >> <html xmlns:nfuncs="http://some-url.net/nfuncs/" > >> >> >> >> >> >> >> <head> >> >> >> >> >> >> >> <script type="text/javascript"> >> >> >> >> >> >> >> //<![CDATA[ >> >> >> >> >> >> >> function parseUrlParam(url, param) { // from >> >> >> >> >> >> >> http://www.netlobo.com/url_query_string_javascript.html >> >> >> >> >> >> >> if(!param) >> >> >> >> >> >> >> return url; >> >> >> >> >> >> >> name = >> >> >> >> >> >> >> param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); >> >> >> >> >> >> >> var regexS = "[\\?&#]"+param+"=([^&#]*)"; >> >> >> >> >> >> >> var regex = new RegExp( regexS ); >> >> >> >> >> >> >> var results = regex.exec( url ); >> >> >> >> >> >> >> if( results == null ) >> >> >> >> >> >> >> return ''; >> >> >> >> >> >> >> >> >> >> >> >> >> >> return results[1]; >> >> >> >> >> >> >> }; >> >> >> >> >> >> >> XPathCoreFunctions['http://some-url.net/nfuncs/ >> >> >> >> >> >> >> url-param'] >> >> >> >> >> >> >> = >> >> >> >> >> >> >> new XPathFunction(false, >> >> >> >> >> >> >> XPathFunction.DEFAULT_NONE, >> >> >> >> >> >> >> false, >> >> >> >> >> >> >> function(field) { >> >> >> >> >> >> >> if (arguments.length > 1) { >> >> >> >> >> >> >> throw { >> >> >> >> >> >> >> name : "url-param() : Invalid number of >> >> >> >> >> >> >> arguments!", >> >> >> >> >> >> >> message : "url-param() The function must >> >> >> >> >> >> >> have >> >> >> >> >> >> >> at-most >> >> >> >> >> >> >> one argument." >> >> >> >> >> >> >> }; >> >> >> >> >> >> >> } >> >> >> >> >> >> >> >> >> >> >> >> >> >> return parseUrlParam(window.location.search, >> >> >> >> >> >> >> field); >> >> >> >> >> >> >> } >> >> >> >> >> >> >> ); >> >> >> >> >> >> >> //]]> >> >> >> >> >> >> >> </script> >> >> >> >> >> >> >> </head> >> >> >> >> >> >> >> <body>... >> >> >> >> >> >> >> >> >> >> >> >> >> >> Then, you can invoke your xform with a URL like this: >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> http://you_server.net/your_xform_page.xml?init-doc=vte_406207_d.xml >> >> >> >> >> >> >> >> >> >> >> >> >> >> (code-fragments above were modified by hand, not >> >> >> >> >> >> >> actually >> >> >> >> >> >> >> tested >> >> >> >> >> >> >> if >> >> >> >> >> >> >> they still work OK) >> >> >> >> >> >> >> >> >> >> >> >> >> >> Hope it works, >> >> >> >> >> >> >> Kostis Anagnostopoulos >> >> >> >> >> >> >> >> >> >> >> >> >> >> On Mon, Apr 19, 2010 at 11:38 AM, Dhiradj Badloe >> >> >> >> >> >> >> <dh...@gm...> >> >> >> >> >> >> >> wrote: >> >> >> >> >> >> >> > Hello, >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > I have a question about the dynamic loading of an >> >> >> >> >> >> >> > instance >> >> >> >> >> >> >> > into >> >> >> >> >> >> >> > a >> >> >> >> >> >> >> > model. >> >> >> >> >> >> >> > Here's in example of my code: >> >> >> >> >> >> >> > <xf:model id="InlineWerken"> >> >> >> >> >> >> >> > <xf:instance id="inlinewerken" >> >> >> >> >> >> >> > src="vte_406207_d.xml" >> >> >> >> >> >> >> > /> >> >> >> >> >> >> >> > </xf:model> >> >> >> >> >> >> >> > The xml file is read from a local folder. This name of >> >> >> >> >> >> >> > the >> >> >> >> >> >> >> > XML >> >> >> >> >> >> >> > file >> >> >> >> >> >> >> > will >> >> >> >> >> >> >> > be >> >> >> >> >> >> >> > different every time.(based on exports from another >> >> >> >> >> >> >> > application). >> >> >> >> >> >> >> > I'm >> >> >> >> >> >> >> > looking for a solution how to dynamically load the >> >> >> >> >> >> >> > instance >> >> >> >> >> >> >> > in >> >> >> >> >> >> >> > the >> >> >> >> >> >> >> > model. >> >> >> >> >> >> >> > Can someone help or advise me on this? Thanks! >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > Regard, >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > Dhiradj >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > ------------------------------------------------------------------------------ >> >> >> >> >> >> >> > Download Intel® Parallel Studio Eval >> >> >> >> >> >> >> > Try the new software tools for yourself. Speed >> >> >> >> >> >> >> > compiling, >> >> >> >> >> >> >> > find >> >> >> >> >> >> >> > bugs >> >> >> >> >> >> >> > proactively, and fine-tune applications for parallel >> >> >> >> >> >> >> > performance. >> >> >> >> >> >> >> > See why Intel Parallel Studio got high marks during >> >> >> >> >> >> >> > beta. >> >> >> >> >> >> >> > http://p.sf.net/sfu/intel-sw-dev >> >> >> >> >> >> >> > _______________________________________________ >> >> >> >> >> >> >> > Xsltforms-support mailing list >> >> >> >> >> >> >> > Xsl...@li... >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > https://lists.sourceforge.net/lists/listinfo/xsltforms-support >> >> >> >> >> >> >> > >> >> >> >> >> >> >> > >> >> >> >> >> >> > >> >> >> >> >> >> > >> >> >> >> >> > >> >> >> >> >> > >> >> >> >> > >> >> >> >> > >> >> >> > >> >> >> > >> >> > >> >> > >> > >> > > > |