How to specify delimiter for list.each function in ColdFusion 11? - coldfusion

I have adopted the CFScript syntax for most of the work with ColdFusion now, since with the new version of ColdFusion v11(codenamed Splender), almost all the short-comings of the script style syntax has been given serious thoughts. Thought suprisingly, I came across a requirement where I needed to iterate throught the list with variable delimiter. So I choose the list.each function in CF11 and not any other option would do since I also need the current index value along the way as well.
list.each(function(element,index,list){
writeOutput("#index#:#element#;");
}, ";")
The problem is that this function surprisingly does not seem to support a custom delimiter.
To save the time, I would like to mention that I already tried the for (element in...) with a count variable for my needs.
var idx=1;
for (element in "a,b,c,d,e"){
writeOutput(element);
LOCAL.idx++;
}
But I would appreciate some help with the original list.each function in CF11, is it even possible somehow to implement? or is it what I think a shortcoming.

I'm not using CF11, but i would point you to this bug report, which seems to say the HF3 does exactly what you want.
If that doesn't work, or in the meantime, you could convert it to an array and use ArrayEach().

Related

Is there a way to get scrollstate from Lazyrow

I have made a LazyRow that i now want to be able to get the scrollposition from. What i understand Scrollablerow has been deprecated. (correct me if im wrong) The thing is that i cant make a scrollablerow so i thought lets make a lazy one then. but i have no clue how to get scrollposition from the lazyrow. i know how to get index but not position if that eaven exists. here is what i have tried.
val scrollState = rememberScrollState()
LazyRow(scrollState = scrollstate){
}
For LazyScrollers, there are separate LazyStates.
I think there's just one, in fact, i.e. rememberLazyListState()
Pass that as the scroll state to the row and then you can access all kinds of info. For example, you could get the index of the first visible item, as well as its offset. There are direct properties for this stuff in the object returned by the above initialisation. You can also perform some more complex operations using the lazyListState.layoutInfo property that you get.
Also, ScrollableRow may be deprecated as a #Composable, but it is just refactored, a bit. Now, you can use the horozontalScroll() and verticalScroll() Modifiers, both of which accept a scrollState parameter, which expects the same object as the one you've created in the question.
Usually, you'd use LazyScrollers since they're not tough to implement and also are super-performant, but the general idea is that they are used with large datasets whereas non-lazy scrollers are okay for small sized lists and stuff. This is because the lazy ones cache only a small fraction of the entire list, making your UI peformant, which is not something regular scrollers do, and not a problem for small datasets.
They're like equivalents of RecyclerView from the View System

Coldfusion/Lucee How to output this variable containing brackets [] in the name?

I'm using this x-editable plugin (https://vitalets.github.io/x-editable/demo-bs3.html) and specifically the "Custom input, several fields" located towards the bottom of the demo.
First, everything is working just fine on the implementation but I'm struggling with how to save the submitted data (see screen shot below further down). I don't know how to reference value[address1] in my sql statement without Lucee thinking its a structure (I hope that makes sense in what I'm trying to say here). When I try to reference the variable reports via writeDump(form.value[address1]), Lucee provides me the following error:
key [value] doesn't exist
How do I reference form fields in the image? Should I change how the data is being submitted perhaps using jQuery's serialize() method?
It was much easier than I thought. I didn't even know you could do this!
local.address1 = form['value[address1]'];
Thanks to the comment made by #Matt-Busche in the SO question, ColdFusion Variable Name with brackets.

Infragistics FilterMenuFormatString

Would someone kindly help me understand this property. Below is their explanation:
<ig:TextColumn.FilterColumnSettings>
<ig:FilterColumnSettings FilterMenuFormatString="{}{Regex}"/>
</ig:TextColumn.FilterColumnSettings>
When you are applying the format through XAML and using special symbols in it you should escape it with {}.
I don't understand how to translate this to a pattern and replace. I'd like to replace the first underscore in the string with a double underscore (trying to defeat the RecognizesAccessKey behavior of the checkbox, without creating a new control template).
The FilterMenuFormatString allows you to apply a FormatString to the values displayed in the filter list similar to what the String.Format method does.
Note that the behavior that you are trying to workaround will be addressed in the Next NetAdvantage for WPF/Silverlight service release which is currently scheduled for April 5th according to the release schedule.
If you need to workaround the behavior before then you can use the workaround suggested on the Infragistics forums to set the RecognizesAccessKey of the ContentPresenter to false in the default templates.

Query with RegExp and Array

I have a class Post, with the following scope:
scope :by_tag, ->(tag){ where(:desc => /##{Regexp.escape(tag)}/) }
It works very well with one tags, but I can't make it work with various tags.
For example: I cant make it give me the posts tagged with #rails AND #regexp.
With criteria union I can make it return me the posts tagged with #rails OR #regexp.
How can I get it to work? I'm using mongoid, btw.
Thanks in advance.
Just fount that is not an OR. What happens is that the second time I call by_tag, it overrides the previous. I believe that's because it's the same property.
Someone know how to fix this? Thanks
Regexp queries tend to be really slow. Instead, store an array of tags and use $in to query the array.
With Mongoid 2.x use all_in
scope :by_tags, ->(*tags) { all_in(tags: *tags) }
With Mongoid 3 use all merge strategy
scope :by_tags, ->(*tags) { all(tags: *tags) }

How to split a comma delimited string into an array in cfscript

Is there an easy way to split a comma delimited string into an array using cfscript?
Something similar to the following JavaScript:
var a = "a,b,c".split(",");
var a = ListToArray("a,b,c,d,e,f");
https://cfdocs.org/listtoarray
Your two main options are listToArray(myList) and the java method myList.split(), as noted in previous answers and comments. There are some things to note though.
By default ColdFusion list functions ignore empty list items.
As of ColdFusion version 8, listToArray takes an optional third argument, includeEmptyFields, which is a boolean controlling that behavior, defaulting to false.
For example:
listToArray("asdf,,,qwer,tyui") is ["asdf", "qwer", "tyui"]
listToArray("asdf,,,qwer,tyui", ",", true) is ["asdf", "", "", "qwer", "tyui"]
Re java split:
Like other java functionality that pokes up through the ColdFusion layer, this is undocumented and unsupported
In Adobe ColdFusion 8, 9, and 10, but not in Railo, this is a syntax error:
a = "asdf,,,qwer,tyui".split(",")
But this works:
s = "asdf,,,qwer,tyui";
a = s.split(",");
As far as I can see, Adobe ColdFusion treats the result of .split() like a ColdFusion array:
CFDumps show it as an array
It's 1-based
You can use arrayLen on it
You can modify its elements in ColdFusion
There may be other behaviors I didn't check that aren't like a CF array, but as above, it's unsupported
In Railo:
Debug dumps show it as Native Array (java.lang.String[])
The other statements about its very array-like behavior are still true
That's in contrast to real java arrays, created with createObject("java", "java.util.ArrayList").
NOTE: That's only partly correct; see edit below.
For instance, in Adobe ColdFusion, elements of a java ArrayList can't be modified directly with CFML
In general, Railo handles java arrays more like ColdFusion ones than ACF
Edit: Thanks Leigh, I stand corrected, I should stick to what I know, which is CF way more than java.
I was reacting to the comment saying that the result of .split() "is not a ColdFusion array, but a native Java array. You won't be able to modify it via CF", which is not the case in my experience. My attempt to clarify that by being more specific was ill-informed and unnecessary.