Jsp - arraylist

Hi,

I have a page where I can add properites to a project and when i write in some textfields and then click more properties I don't want what I just wrote to be written to the database I wan't it saved in an arraylist until I click save and then all properties from the arraylist will be saved to database. If I leave the page without saving and go to another project I wan't the arraylist to be empty but I don't wan't to create an arraylist for each project and have in memory. The first page where I start is a projectpage and if I click on a project I go to it and can add properties like a shoppingcart but if I go back it has to be cleared and not saved for the hole session.

I solved it by making a static arraylist in my javabean where I have created getters and setters for my variables and then making a method that will save the variables in the arraylist. If i go back to the first page without saving I call a method in the bean that clears the arraylist. I tried with different scopes like page, request and so on but none of them seems to what I want. If I don't make the arraylist static it won't be saved when I click add more properties.

What I basically wan't to do is create a shoppingcart for one page and if I leave without saving it will be cleared.

I don't know if anyone understands what I'm trying to do and if anyone does can you tell me if this is the best way or if there is any alternatives.

/Johan

[1477 byte] By [ripita] at [2007-11-27 10:39:47]
# 1

there are lots of ways to do this but basically you want to use request scoping since you want a new, fresh (and empty) list each time the page loads.

i'm not sure where your issue is because it sounds like it's doing what you need it to already. you have all the text fields on screen, and if the user fills them out and clicks Save, then store in the database (DB). otherwise, don't do anything.

try breaking this down into little parts and get each tiny thing to work before you move to the next. let us know when you get stuck.

den2681a at 2007-7-28 19:03:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi

that was the problem the list was empty when I used page or request scope I don't want to write it to db before i hit save all not when the page reloads. Then there can be 10 records in the list. The way I did solved the problem but I wondered if there was a better way to solve it.

ripita at 2007-7-28 19:03:07 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...