• Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions about jstl tags : useBean forEach set

 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!