I'm new in JavaBeans, and at the vary begin I have a sort of problem, and it's about the logic insede JavaBeans, or I have an incomplete information (data) within the project I'm studying.
This is a simple page using bean:
<title>A dose of Dilbert</title>
<h1>A dose of Dilbert</h1>
In the "images" folder there is stored a four images, variously named (dilbert2001113293109.gif, dilbert2001166171108.gif, and so on...)
Each time I reload the page (above) I got a different images displayed on the page. Well, it should be a logic of bean, right?
But according to bean above, I cannot find any logic or program flow that allow an images of completely different names to be invoked (displayed)???? When bean is called, we retrieve a his getter method value, and here it is this line : " return (String) fileNames.get(index);" But no where in the code we store an images of different name in the collection but in one place?
So where is the place where were stored a remained three images from the folder????
You are using a BEAN on one a single page without defining the scope of it. So by default the scope of bean is PAGE.
This means when the page is loaded, there is a bean initialized and same is available to that particular page.
Now in your bean, the method getFileName(), increases everytime the value of variable "index", and reading the name from list of that index.
Definitely everytime you refresh the page, the value of "index" will be increased and you will get the next image_file_name.
For better understanding, i will suggest to run the application in debug mode and put the dubug point inside your bean methods.