Reputation: 8959
Im trying to store an array list in session like so:
private Map session = ActionContext.getContext().getSession();
The array list looks like this:
private ArrayList<Integer> numbersEntered = new ArrayList<Integer>();
If the array list doesn't already exist in session it is added but Im having problems adding new data to the array list and updating the session with that data. So - my problem is how do I get what is already in session, store it temporarily, add to it based on the user input and re-add to the session?
if ( !session.containsKey(arrayListID) )
{
// Place the number the user entered into the session
session.put(arrayListID, numbersEntered);
} else {
// Retrieve session data
}
I retrieve what was stored initially and placed it in a string but because it was anm array list it was stored like: [12]. I don't want to have to convert it or split the string...Let me know if you need more info here.
Cheers
Upvotes: 1
Views: 12575
Reputation: 341
if ( !session.containsKey(arrayListID) )
{
// Place the number the user entered into the session
session.put(arrayListID, numbersEntered);
} else {
ArrayList<Integer> list = (ArrayList<Integer>) session.get(arrayListID);
list.add( 1 /* what you want */);
// Retrieve session data
}
Upvotes: 2