What scope does <cfquery> use by default on a .cfm template? Will they be collected by the gc once a request ends?
The default scope in .cfm is VARIABLES.
<cfquery name="x">
is equivalent to
<cfquery name="VARIABLES.x">
Not using the scope in front of a variable makes ColdFusion look for the variable in other scopes (starting with VARIABLES for the above case). There are exceptions based on the context, even in a .cfm template (local variables). You can learn more about it in the official docs, here
and here It's worth knowing this.
And yes, when the request finishes, the variables are marked for garbage collection. You do not have to explicitly "delete" or "null" them.
Related
Looking for something to change a mode or parameter based on value of register bit(s). Something like an 'on_modify' for a bit collection. Does that already exist?
I don't think so, though the reverse (update a parameter and have it reflected in the register) is supported if that is any good to you.
See the last example about binding register bits to a live parameter here - http://origen-sdk.org/origen//guides/models/parameters/#Live_Updating_Parameters
Adding some new functionality to bit collection so that it supported something like the following API should not be too difficult:
my_reg.my_bits.on_data_changed do |data|
do_something.based_on(data)
end
The on_data_changed method would just store the given block in the bit collection instance and then trigger it whenever the write method is called.
JsConfig.BeginScope allows me to customize serialization for specific operation without affecting global config. However, how do I provide custom SerializeFn for specific type for the duration of the scope? It seems JsConfig< T > is always static and ignores the scope completely?
Configuration on JsConfig<T> is only configurable statically and is not an available option on JsConfigScope.
I've got a component called app-globals which for the moment only has javascript with a variable in it. When clicking a button I want to not only change the variable value, but bind that value to a number of places throughout the app.
I can't find any documentation for this.
Any help?
That question is already answered here:
Polymer global variables
In short, use objects to store globals:
"By using an object with data properties, as in the edited version
above, and only ever reading from and assigning to the data properties
of that object rather than overwriting the object itself, changed
values are shareable between instances."
What's the difference? When should I prefer one over another?
And some minor questions related to this:
if I have object data, when is saveObject called?
it looks like garbage collector recycles all my domino handles. I tried to downcast then clone it, but it didn't help (how does it know its still a domino object?). Is there a workaround?
if I create "var tmpVar = new package.TestClass()" from xPages, it gets recycled on update. But if I create java object from bean it stays there. Correct?
Managed beans are exactly that, managed by the XPages runtime. They are created as and when there is a first call to them. Although they have an empty constructor, managed-properties elements in the faces-config allow you to define values (and I believe you can add SSJS code to the faces-config to compute the values).
Object data sources allow you to handle what's created when, and it means they can be scoped to a smaller level than viewScope - to a Panel or Custom Control. The saveObject method is called by a Save All Datasources event. In reality, if you're coding object data sources, you'll code a button and call the relevant method rather than use a simple action.
Java variables can get recycled, but Domino objects are only recycled via two methods. The first is calling recycle() methods, the second is at the end of each request, when the session gets recycled. Because recycle() calls recycle all child elements, everything gets recycled at the end of a request. Which is why you can't store Domino objects in scoped variable or any other persisted object (i.e. a bean). Note that objects like DateTimes, RichTextStyles etc are children of the session, not of any more granular Domino object like a NotesItem or NotesRichTextItem.
var tmpVar = new package.TestClass() will only get persisted beyond the current request if you store tmpVar somewhere. If you're using that code in a crerateObject method, return tmpVar will pass that instance of TestClass into the Data Object.
I go back and forth on pure Managed Beans vs. Data Object. I was using a lot of Data Objects for a while but then ran into some issue with the JSF lifecycle I think that I just couldn't make work. Not sure if a repeat or custom control was involved. So I pretty much have gone back and given up on them for now.
Other then that problem I had I'm not sure there's a ton of difference. I think dataObject can tend to be a little more confusion. Since you can set it on an XPage - but you can change the scope of it to session or application I believe. But if you do then that seems messier and hard to find then making the bean in the faces-config.
I'm not sure about the saveObject part of your question.
You never want to put a pure domino object inside a bean, or scoped variable because they are not serializable and will be tossed by the garbage collector at some point that will likely be most inconvenient to you.
if you just do "var tmpVar = new package.TestClass()" then yeah that will get killed pretty quick because of limited life of that variable. if you want to create an object that way and keep it around longer put it in a true scope: viewScope.put("myObject", tmpVar);
I have a video where I tried to give examples of I think 4 ways to use java Objects. In the blog posting are some really good comments by Tim Tripcony which might give you further information.
http://www.notesin9.com/2013/08/01/notesin9-122-working-with-java-objects-in-xpages/
I am working on this project https://github.com/tanema/express-helpers that I forked fixed up and added new functionality to.
What I want to do it, instead of having to use form_tag_end() or even end_tag('tagname') I would just like to use a end() method. For this to work I need some sort of stack implementation for when a start tag is issued push onto the stack ect. I cannot just make a variable in the module called tagStack and just use that because it would create a race condition where the module is being used at the same time by two requests and the stack order gets messed up.
I was thinking if there was some way to have access to the request variable I would just store it in that and delete the variable if empty but I can't figure out how to do that.
Any suggestions?
Create your variable within a closure; it will be available within the scope of the instance, but not outside the instantiation of the functions, and will be garbage collected when the specific instances go out of scope.