• 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

Questions about jstl tags : useBean forEach set

 
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have an ArrayList of "Person" beans in my request scope. I want to construct javabeans of "Person"s looping with a foreach tag. Is that possible? Note that I also want to cast the bean to an interface. Also note that only the ArrayList is in the request scope. The individual Person beans are not, or at least not directly.

How do I set all properties at once, i.e. name, firstName, age, etc??

Thanks in advance,

Julien.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a really odd thing to be trying to do. Perhaps you can explain what you are trying to really accomplish, as in and of itself, this doesn't make a whole lot of sense to do.
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
The problem is that I have an Arraylist of Persons in my request scope and that I want to obtain as many javabeans of Persons as there are persons in the ArrayList. Note that I also want to cast the resulting bean.
Julien.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Julien Martin:

The problem is that I have an Arraylist of Persons in my request scope and that I want to obtain as many javabeans of Persons as there are persons in the ArrayList.



But for what purpose? Via the EL you have access to each and every instance of Person in the list. There is no need to create separate beans or separate references to the existing beans. Why do you feel that you need to do that?

Originally posted by Julien Martin:

Note that I also want to cast the resulting bean.



Why? This will serve no purpose unless you are referencing them from scriplets, in which case why use the JSTL and EL at all?
[ January 09, 2006: Message edited by: Bear Bibeault ]
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Bear Bibeault,

This is what my jsp looks like: there is too much scriplet code.



I know you might not see why I try to achieve this (why do it?) : the cast and setting the multiple properties but I would be grateful if you could give me the answer (how to do it?).

Thanks in advance,

Julien.
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You dont require the cast to ArrayList or a Collection from a request attribute because it is implicitly taken care of the jstl tags (You can iterate only Collections, Map or Arrays)

If you are referring to the cast, when you retrieve each object from the collection, I dont think that's needed as methods would be correctly
(polymorphically) resolved.

And here's the jstl -



And finally as Bear said, you have access to all the beans via EL. You do not require seperate javabeans. Probably a bit more of reading would help.

cheers,
ram.
 
reply
    Bookmark Topic Watch Topic
  • New Topic