Parse JS SDK : Manually mark attribute as Dirty - parse-javascript-sdk

I am experiencing very occasional instances where the parse js sdk does not detect that an Array attribute has changed ... and is therefore not including it in the payload on a save().
I can see there is Parse.Object.dirty(key) which will return if the field is dirty.
But is there a way to manually mark an attribute as dirty ?

Related

How to customize segment using query string or cookie in Adobe CQ5.6?

How to customize segment using query string or cookie in Adobe CQ5.6?
My requirement as follows:
I wanted to target querystring parameters in Segment which is added in my Experience, Teaser, Promotion, Voucher for owned site.
Thanks in advance.
You can define your own segment at outlined here: https://docs.adobe.com/docs/en/cq/5-6-1/administering/segmentation.html#Defining%20a%20New%20Segment
In step 6 where you edit the segment, you need to supply a JavaScript expression that will resolve to a boolean, true or false. You can put any JavaScript expression here that meets your need, so you can include script that will have a complex expression if you want. But rather than write a complex JavaScript expression here, it would be better to write JavaScript that exposes a function which returns true or false and then include that JavaScript function on your pages via a client library. Then, in the segment, you can simply invoke the function rather defined in your client library than try to write a complex expression.
As long as the JavaScript expression defined in the segment evaluates to true/false, the segment will be usable.
Without your own JavaScript you can easily fetch query string values of look at cookies. See these other questions for details on that:
What is the shortest function for reading a cookie by name in JavaScript?
How can I get query string values in JavaScript?

Alfresco Java backed web-script lookup by cmis:objectId

I am writing my first java-backed webscript for Alfresco community edition. I am implementing document properties / preview service, and I take a parameter which is the cmis:objectId of the document in question. I'm having trouble getting started because I haven't been able to access the document based on the cmis id.
What is the best way to get a document (NodeRef?) based on the cmis:objectId when operating server-side in a web-script controller? I see Jeff Potts' great examples on how to implement web scripts, but the mixing of the Java API and CMIS concepts has me stuck. Should I just use the search service and find the object based on the cmis:objectId property? Any pointers appreciated.
Well, the answer is a little ugly, but hopefully this helps someone...
A good way to look up the NodeRef using an 'opaque' objectId should be to use CMISServices, obtained from the registry in your java backed web script, i.e.
docRef = registry.getCMISService().getLatestVersion(docIdStr, false);
Unfortunately, there's a bug in the Alfresco code (or so it seems to me, admittedly a bit of a newbie). The alfresco CMISServicesImpl.getLatestVersion() uses a getObject() method under the covers. That method takes an objectId String as a parameter, but then strips off the version information at the end (i.e. the ";1.0" part of the objectId) and then checks to see if the remaining string is a valid NodeRef. In doing so, it checks it against this pattern (in NodeRef.java):
private static final Pattern nodeRefPattern = Pattern.compile(".+://.+/.+");
If the validation fails, you get a CMISInvalidArgumentException, with a message that xxxxx "is not an object ID".
So, to make a long story short, when I call the web script using a parameter for the objectId like this:
29ea5a16-12a8-497d-aad3-f43969e8a672;1.0
I get the CMIS exception. But, if I call the method with an objectId parameter that looks like this:
workspace://SpacesStore/29ea5a16-12a8-497d-aad3-f43969e8a672;1.0
... then, the "CMIS" lookup succeeds and I get my desired NodeRef back. Of course, all that the CMIS services are doing under the covers is stripping off the ";1.0" from the object ID, treating it as a NodeRef string, and doing the lookup using that.
In other words, you can't do it the right way in 4.2. The best thing to do is as #Gagravarr says and tweak your own objectId string to turn it into a NodeRef. Hopefully it's fixed in 5.x.

Meteor autoform does not wait for element to exist in DOM

I'm adding a rendered template to the document via:
Blaze.renderWithData(Template.page, Session.get(toAdd[i]), document.getElementById('pages'))
This works great... except sometimes with autoform. I'm unsure what's triggering it to happen but some of my autoforms (that can exist inside Template.page, they're added to that template dynamically via the data passed in) show, while other throw a client error:
Uncaught TypeError: Cannot read property 'formValues' of undefined :: autoform-inputs.js:162
markChanged :: autoform-inputs.js:169
updateTrackedFieldValue :: afFieldInput.js:72
There's a timeout set to 0 in that afFieldInput.js on line 71. Upping this to 500 fixes the error above but is hacky and causes other issues.
The best I can surmise, autoform is attempting to get the form from the DOM by id before it exists in the DOM, probably it exists as a document fragment via Blaze, if I had to guess.
I can confirm that AutoForm.templateInstanceForForm is getting the correct form ID, but that document.getElementById(formId) is returning null.
The other possibility is that Blaze is, for some reason, failing to render the template but not warning me.
I was WAY off.
I had changed the schema, but was trying to open a doc with improper data for the new schema. Going to post this answer in case someone comes across the same error.
Also, don't pass in objects or functions all the way to the template that autoform doesn't expect, apparently. You can access them still, but remove them from the attr object by declaring attr as a function in the helper, returning this.attr sans any objects that don't need to be sent on to the template.

.Net Inline Schema/XML Programmatic Generation for Excel

I have a set of data rendered using ASP.Net (VB.Net) to a web page. I now want to export that data to XML. I have created some code to generate a schema, however, I don't know what to do next. I want to have the schema be in-line with the XML data, and I would like the compiler to check to make sure that the data I'm entering for the XML content validates against the included schema. Anyone know of a way to do this? The idea is for me to be able to open the resultant file in Excel with fields of the correct type.
I've build XML documents before, and this is my first schema document I've created programmatically. However, I've never worked with inline schema's, much less used them to strongly-type the XML being added to the document.
I've read over the following, which were quite helpful, but neither of which addressed the issue I mention above:
http://www.aspfree.com/c/a/XML/Generating-XML-Schema-Dynamically-Using-VBNET-2005-Essentials/
http://blogs.msdn.com/b/kaevans/archive/2007/06/05/inline-an-xml-schema-into-your-xml-document.aspx
I have no idea what you mean by "... I would like the compiler to check to make sure that the data I'm entering for the XML content validates against the included schema."
The compiler never checks that. If you want to validate your XML Document against a schema programmatically, you should probably use http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidator.aspx.
But for inlining the schema with your document, you sort of answered your own question. The second link in your question, to http://blogs.msdn.com/b/kaevans/archive/2007/06/05/inline-an-xml-schema-into-your-xml-document.aspx, is exactly what you are trying to do.
You can think of an inline XML Schema as a document-within-a-document. Well, using Kirk's example, the outermost document is more of a container which uses the undefined namespace (no schema). His example uses a document root of "DerekDoc" that belongs to the undefined namespace. You can name yours whatever you want.
Inside that root are essentially two documents. One is the inline XML Schema. You would just add it as a child element of the root. The other is the XML document that you intended to conform to the XML Schema. You will need to use the xmlns attribute to set this element to the namespace defined by your XML Schema (the target namespace of the schema).
It might work (I haven't tried it) to set the root element to the target namespace of the schema, but it might be harder for clients to validate the document since it's a forward reference.

How to maintain the cache in the servlet?

I want to maintain db cache(some keywords) in the servlet. When I am typing for 'a' I have 1000 keywords in Db which starts with 'a' and presently I am using js file to store all the keywords in cache. I want to maintain the DB cache in servlet also and decrease the browser cache and next hitting keyword matches in the servlet Db, I want to retrieve the top 10 keywords for the this hitting.
Can you tell me how can I create the servlet cache? Can you provide any pseudo code for that?
Thanks,
Murali
I can imagine you have a Servlet that accesses the Database in order to retrieve the top 10 keyboards based on the input delivered. That means whenever an A is pressed in the input field, you must use an XMLHttpRequest to call the servlet with that input.
The servlet should return you a list of keywords which you should parse and translate properly to your user again. (you could do this in multiple ways. An easy way is to just let the servlet respond with HTML for you,which you can set with Javascript in an element (innerHTML)).
As for caching, the servlet could use some cache and identify the requested input. You can build an own cache by generating a key from the input and the result of that input should be put into a Map.
You could also use an existing caching framework, like EHCache.

Resources