Not been using CF long, but I have hit (an undoubtedly simple) stumbling block dealing with lists.
I have a component called user that has a list property called roles:
property type="List" name="roles" default="";
(I have set accessors=true so get the setter for free)
Now I want to set the roles as a list, and my understanding (what google tells me) is that initialising lists is just as simple as creating a comma separated string, for example "USER,ADMIN,SUPER" etc.
My problem is, I am trying to set it as a single item list:
user.setRoles("user");
and I am getting the error
The roles argument passed to the SETROLES function is not of type List.
Can anyone point out what I am doing wrong/what I need to do so CF recognises the single item string as a list?
Thanks
Well lists are really just strings with delimiters. What if you change the type to string?
Related
I have a list of a custom object Product like this:
Product:[type=fruit, productValue=apple], Product:[type=fruit, productValue=pinapple], Product:[type=vegetable, productValue=potato],Product:[type=vegetable, productValue=carrot]
I want to obtain two lists due to the first value (type=fruit/vegetable), in Apex WITHOUT using a for cycle.
Expected result: fruitList=['apple','pinapple'] and vegetableList = =['potato','carrot']
How can I split them?
I suggest you can create a Wrapper class for Product with two variable type and productValue with String data type, as written below -
public class Product{
String type;
String productValue;
}
Then use the Wrapper instance to get the list of type and productValue easily with the help of JSON.serilize() and JSON.deserilize()
Please, let me know if it helps you out or not.
Thanks.
There is no way to split them without a loop. Unless you do it before you obtain the list. I would suggest either 2 queries to get the list of products, or just do the loop to split them up. Depends on where you are with governor limits.
In the original TI-BASIC (for TI-83/84+) is there a way to check if a list has been defined?
Currently calling dim(⌊LIST) will return an error if the list is not defined.
Is there a way to handle that error gracefully?
Possible Workaround:
The only hacky way I can think of doing so is to redefine the list with more items than you're expecting such as 99→dim(⌊LIST) and check if the first few values are not zero. But that seems wasteful and slow.
Any suggestions?
Unfortunately there doesn't seem to be a clean, simple function for checking if a list already exists, but thanks to harold who posted this as a comment, there is a workaround:
The SetUpEditor command.
This is typically used for specifying which lists are displayed in the list editor, but the command has the side-effect of creating a zero-length list if it does not exist yet.
So here's some sample code, with comments:
"Create two empty lists if they do not exist yet
SetUpEditor FOO,BAR
"Check the size of FOO
dim(∟FOO)→X
"Clean up by returning the list editor back to
"its default state (∟1-∟6)
SetUpEditor
If you have control during the lists's creation, then another workaround would be to use another list with only one element (or a list of another fixed size, or a letter variable) as a flag that indicates this main list exists.
Something like this, for lists LMAIN and LFLAG:
1->dim(LFLAG
If 5784923472≠LFLAG(1
Then
"assume LMAIN does not exist because flag hasn't been set
"insert optional other code here
0->dim(LMAIN
5784923472->LFLAG(1
End
I have a list of constructed objects called RecentCard which is basically an object with user id, pic, and name. I have created a list arranged in order of most recent interaction based on timestamp. However i need to get rid of the second occurence and onwards of any duplicated object. I am comparing just the ids since users may have the same name or photo, and i cannot remove duplicates from a simple list of uids because then i could lose the order of corresponding photos and names.
For example the list would look something like this :
List<RecentCard> recentCards= [RecentCard(uid:as721dn18j2,name:mike,photourl:https://sadadasd1d1),RecentCard(.....]
I have searched for solutions but all of them are dealing with like primitive types like simple lists of strings and the solutions didn't work for me. For example this post: How to delete duplicates in a dart List? list.distinct()? Read below
The first answer's link is no longer available, the next answer with sets is something i tried but it simply doesnt work i have no idea why maybe because its not a primitive type. The next answer with the queries package didn't work because i was using the list to build a listview.builder and so when i called list.length it said i couldnt call that on an iterable or something. The final solution wouldn't work because it said String is not a subtype of RecentCard.
I tried using two forloops with the second just comparing first value to the next couple but that doesnt work because if a duplicate is found, the object is removed and the length is messed up so some elements get skipped.
Any ideas? I feel like its very simple but im not sure how to do it.
You have to use Set to store seen cards and then filter away those ones that are already in the set.
final seenCards = Set<String>();
final uniqueCards = recentCards.where((card) => seenCards.add(card.uid)).toList();
Using struts2 how can I keep list values just after click in a jsp button, going through the action and returning to jsp again? Doing this click several times again.
I've been watching that to keep a value from a variable that isn't a list I just need to declare it in the action with it's getter and setter, and put a hidden field or textfield in the jsp, but regarding lists don't worked like that.
You are correct that we need a getter and setters for the respected property in our action class to send and receive date from Action class to JSP and in reverse order.
But since for collection, its not possible to store it in a single field, so you have few options here.
If List is a simple List of String you can create a comma separated string and can use that to go from action to JSP and in reverse order (easy to convert that to list), i will not recommend this approach.
Second option i am thinking to set the list in session and you can always retrieve the list in your action class at any time as per your choice.
If I'm not mistaken, it seems that FinalBuilder 7's action list parameters only support input values. Is there any way I can simulate a workaround for return parameters? I do not want to store return parameters in a global temp variable or even a stack, because I'm calling the same action list multiple times asynchronously.
Here is sample of what I want to do. (Notice the shared use of the same action list)
Async Action Group
+-Action Group
| +-Run Action List - [Do Some Calculation]
| +-Replace variable A with return parameter from previous action list
+-Action Group
+-Run Action List - [Do Some Calculation]
+-Replace variable B with return parameter from previous action list
I'm currently using an INI file in the action list to save return values. The calling method passes a parameter to the action list specifying to which INI key to save to. The calling method then reads the value from the INI from the key.
Surely there has to be a more elegant way to do this?
I have never seen any way to return variables from action lists.
That would be an excellent suggestion to post in the FinalBuilder Wish List forum.
Many of requests in the past there are now features of the product.
I think it would require giving scope to variables to something like an Action Group to pull it off. But it would help some of my scripts as well. Update: I found that FB 7 supports Local Variables. But it still does not address the needs of this answer.