Dear friends of JSTL

I'm new to JSTL and looking for some ideas how to maintain collections with
JSTL and EL.

I have a bean with a List and a Map type property like this:

        public class TestBean  {        
                private List list = new ArrayList();
                private Map map = new HashMap();
        
                public TestBean () {
                        list.add("initial value 1");
                        list.add("initial value 2");
                        map.put ("simple value","the initial simple value");
                        map.put ("listvalue", list );
                }
        
                public List getList() {
                        return list;
                }
                                
                public Map getMap() {
                        return map;
                }       
        }


Getting the values from my collections is easy and elegant:

        <c:forEach var="litem" items="${testbean.listitems}" >
          <c:out value="${litem}"/><br/>
        </c:forEach>

        <c:forEach var="mitem" items="${testbean.map}" >
          <c:out value="${mitem.key}"/> = <c:out
value="${mitem.value}"/><br/>
        </c:forEach>

But how to add a new items to the collections? I tried this

        <c:set target="${testbean}" property="list" value="${myvalue}"/>

But this bean method 

        public void setList( String value ) {
                list.add ( value );
        }

does not work because it does not meet the parameter expectations ( List vs.
String ) for beans.
I know that I can write more setZZZ() methods to add something to the List
but it breaks somehow the naming conventions for beans (getXxx, setXxx). And
how to add a new entry to the map? 


Thanks in advance
Peter

--
To unsubscribe, e-mail:   <mailto:taglibs-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-user-help@;jakarta.apache.org>

Reply via email to