JSP: add value to map/array/collection field of a bean

S

Stefan Siegl

Hello,

i was just wondering if there isn't a way to actually add a value to a
collection field of a bean. using <jsp:setProperty> you could only set
a "normal" field of the collection. I mean in JSP 2.0 with EL you now
have to ability to read values from a collection like ${foo[bar]}, so
why isn't there a possibility to add something to a collection. There
are a few workarounds i thought of:
1) use scriptlets:
<jsp:useBean name="foo" ...>
<% foo.add("test"); %>

2) create a custom tag to add a value to a bean like
<my:addBook beanVar="foo" bookName="bookname" />

why isn't there a standard way to do it like
3)
<c:add nameOfBean="foo" propertyName="bar" valueToAdd="test"/>

Thanks,
Stefan

PS: i hope this is the right NG but i did not find any on JSP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top