This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm new in JSP and use of JavaBeans within , and at the vary begin I have a sort of problem, and it's about the logic inside JavaBeans, or I have an incomplete information (data) within the project I'm studying. This is a simple page using bean:
And this is a bean(a Java's class file), where is determinated bean's logic :
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???
[Edit: Added code tags - Amit] [ November 05, 2008: Message edited by: Amit Ghorpade ]
Firstly please make sure you use code tags while posting code.Unformatted code is difficult to read and results in less response for your post. Read this for more information. You can add code tags to your current post by clicking .
Well, it's a book example code, and it make me confused just as You are... Probably, in the background where I have no access, it use a real algorithm for displaying mentioned images...What do you think?
Well it looks like the .. part in the bean adds the remaining image file names to the ArrayList and every page refresh increments the index.
Joined: Sep 26, 2008
Well, it since to me I'm only one who doesn't understand... With each reload there is an increment for one, but "what file is added", aren't specified!!! Here we have a specified file to be added into ArrayList. When we increment for one, what file name will be added with? The rest three images, as much as I have in folder, have some totally different names. Here we add particular image, path, but what image path we add after we made increment???
Okay to test my assumption, can you put a new image file say abcd.gif in that folder? Or rename the existing dilbert2001113293109.gif to renamed.gif and see if it shows up. Since the file names are hard coded, it is unlikely that the new file will be displayed.
Hope this helps
Joined: Sep 26, 2008
Of course it won't, I had tried that. So the solution is that somewhere else in the some library is a real code, algorithm, for this example, where he display just a specific images, stated within? I mean, there is no some "magic" of Bean, which involve each four images to be displayed on reload?
First, when quoting code from a book, let us know the name of the book. This not only gives the author proper credit, in a case like this can be very helpful to you. Someone reading your post may actually have the book and will be able to read the section to see if you've missed something.
If this section is actual code from the book:
then it's incomplete.
Did you remove the rest of the calls to fileNames.add and replace them with the elipse (...) or did the authors of the book do this? If it was the authors, then I assume they expected you to fill in the rest of the file names.
Did you download the code that you're running or did you type it and compile it yourself? [ November 05, 2008: Message edited by: Ben Souther ]
No, it's ok. It's a portion of code... But the way I had presented the problem, is based on my assumption, which was believe that somehow beans load all content of some source, or else... However, thaks both of you for directing me at...