• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

use of JavaBean in JSP

 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic