aspose file tools*
The moose likes JSP and the fly likes use of JavaBean in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "use of JavaBean in JSP" Watch "use of JavaBean in JSP" New topic
Author

use of JavaBean in JSP

Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
Greetings,

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 ]
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

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 .



What do the ... mean? Is the posted code real ?


SCJP, SCWCD.
|Asking Good Questions|
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
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?
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

You seem to have ignored the add code tags part of my post.

Well, it's a book example code

QuoteYourSources
[ November 05, 2008: Message edited by: Amit Ghorpade ]
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399



And this is a bean(a Java's class file), where is determinated bean's logic:





Ok, do you have an answer now?
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6


Ok, do you have an answer now?


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.
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
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???
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

The partial code is the root of all confusions

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
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
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?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Goran Markovic
Ranch Hand

Joined: Sep 26, 2008
Posts: 399
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...
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

I mean, there is no some "magic" of Bean, which involve each four images to be displayed on reload?


Yes you got it right

As you can see this is just a sample code so the file names are hard coded and for the sake of brevity the book has left out the remaining lines which simply add more files.

However, thaks both of you for directing me at...

You are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use of JavaBean in JSP