Looking through the code and the exception.  This appears to be a bug.  It
appears that OGNL is mistaking the TreeMap.Values Collection as a
java.util.Set, when it attempts to coerce it in ognl.SetPropertyAccessor,
you get the noted exception.  This should probably be reported as a bug,
but one workaround would be to change your PersonService code like this:

    static public Collection<Person> getPeople(){
        logger.debug(people.values());
        logger.debug(people.values().getClass().toString());
        return new ArrayList<>(people.values());
    }

  (*Chris*)


On Sat, Jan 12, 2013 at 1:22 PM, Chris Pratt <thechrispr...@gmail.com>wrote:

> You're right Dave, somehow I replied to the wrong email.  Looking over the
> code now.
>   (*Chris*)
>
>
> On Sat, Jan 12, 2013 at 1:08 PM, Dave Newton <davelnew...@gmail.com>wrote:
>
>> (Isn't it around where the iterator tag is in that source? I thought
>> that *was* the OP's code this second barf of source.)
>>
>> Dave
>>
>>
>> On Sat, Jan 12, 2013 at 4:04 PM, Chris Pratt <thechrispr...@gmail.com>
>> wrote:
>> > You said in your original post that you used the <s:iterator> tag,
>> > correct?  Can I see how you used it?
>> >   (*Chris*)
>> >
>> >
>> > On Sat, Jan 12, 2013 at 3:06 AM, fusillator <fusilla...@gmail.com>
>> wrote:
>> >
>> >> Sorry for my misunderstanding, I changed the code of the wiki tutorial
>> >> about wildcard
>> >>
>> >> These is the view:
>> >>
>> >> <%@ page language="java" contentType="text/html; charset=UTF-8"
>> >>     pageEncoding="UTF-8"%>
>> >> <%@ taglib prefix="s" uri="/struts-tags" %>
>> >> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
>> >> http://www.w3.org/TR/xhtml1/**DTD/xhtml1-transitional.dtd<
>> http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
>> >> ">
>> >> <html xmlns="http://www.w3.org/1999/**xhtml <
>> http://www.w3.org/1999/xhtml>
>> >> ">
>> >> <head>
>> >> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>> >> <title>List of people</title>
>> >> </head>
>> >> <body>
>> >> <h3>List of persons:</h3>
>> >> <s:if test="people.isEmpty">
>> >> <ol>
>> >> <s:iterator value="people">
>> >> <li>
>> >> <s:property value="firstName" /> <s:property value="lastName" />
>> >> <s:url action="removePerson" var="urlremove"><s:param name="code"
>> >> value="id" /></s:url>
>> >> <s:url action="editPerson" var="urledit"><s:param name="code"
>> value="id"
>> >> /></s:url>
>> >> <s:a href="%{urledit}">Edit</s:a>
>> >> <s:a href="%{urlremove}">Remove</s:**a>
>> >> </li>
>> >> </s:iterator>
>> >> </ol>
>> >> </s:if>
>> >> <s:else>
>> >> No person inserted
>> >> </s:else>
>> >> <s:url action="editPerson" var="urlnew" />
>> >> <s:a href="%{urlnew}">Insert a new person</s:a>
>> >> </body>
>> >> </html>
>> >>
>> >> and this is the action class:
>> >>
>> >> package org.apache.struts.tutorial.**wildcard.action;
>> >>
>> >> import java.util.Collection;
>> >> //import java.util.List;
>> >> import org.apache.struts.tutorial.**wildcard.service.**PersonService;
>> >> import org.apache.struts.tutorial.**wildcard.model.Person;
>> >> import org.apache.log4j.Logger;
>> >> import com.opensymphony.xwork2.**ActionSupport;
>> >>
>> >> public class PersonAction extends ActionSupport {
>> >>
>> >>     private static final long serialVersionUID = 1L;
>> >>
>> >>     private static final Logger logger =
>> Logger.getLogger(PersonAction.**
>> >> class.getName());
>> >>
>> >>     private Collection<Person> people=PersonService.**getPeople();
>> >>     private int code=-1; //parametro passato da view
>> >>     private Person personBean;
>> >>     private PersonService personService=new PersonService();
>> >>
>> >>     @Override
>> >>     public String execute(){
>> >>         return SUCCESS;
>> >>     }
>> >>
>> >>     public String edit(){
>> >>         setPersonBean(personService.**getPerson(code));
>> >>         return INPUT;
>> >>     }
>> >>
>> >>     public String save(){
>> >>         personService.savePerson(**getPersonBean());
>> >>         return SUCCESS;
>> >>     }
>> >>
>> >>     public String remove(){
>> >>         personService.removePerson(**code);
>> >>         return SUCCESS;
>> >>     }
>> >>
>> >>     public Collection<Person> getPeople() {
>> >>         return people;
>> >>     }
>> >>
>> >>     public void setPeople(Collection<Person> people) {
>> >>         this.people = people;
>> >>     }
>> >>
>> >>     public int getCode() {
>> >>         return code;
>> >>     }
>> >>
>> >>     public void setCode(int code) {
>> >>         this.code = code;
>> >>     }
>> >>
>> >>     public Person getPersonBean() {
>> >>         return personBean;
>> >>     }
>> >>
>> >>     public void setPersonBean(Person personBean) {
>> >>         this.personBean = personBean;
>> >>     }
>> >>
>> >> }
>> >>
>> >> and my modified PersonService class:
>> >>
>> >> package org.apache.struts.tutorial.**wildcard.service;
>> >>
>> >> //import java.util.ArrayList;
>> >> import java.util.Collection;
>> >> //import java.util.List;
>> >> import java.util.SortedMap;
>> >> import java.util.TreeMap;
>> >>
>> >> import org.apache.log4j.Logger;
>> >> import org.apache.struts.tutorial.**wildcard.model.Person;
>> >>
>> >> public class PersonService {
>> >>
>> >>     private static final Logger logger = Logger.getLogger(**
>> >> PersonService.class.getName())**;
>> >>
>> >>     //static private List<Person> peopleList=new ArrayList<Person>();
>> >>     static private SortedMap<Integer,Person> people=new
>> >> TreeMap<Integer,Person>();
>> >>     static {
>> >>         people.put(new Integer(1), new
>> Person(1,"Paolino","Paperino")**);
>> >>         people.put(new Integer(2), new Person(2,"Paperon","De
>> Paperoni"));
>> >>         people.put(new Integer(3), new Person(3,"Archimede","**
>> >> Pitagorica"));
>> >>         //generateList();
>> >>     }
>> >>     /*
>> >>     static void generateList(){
>> >>         peopleList.clear();
>> >>         for (Integer i : people.keySet()){
>> >>             peopleList.add(people.get(i));
>> >>         }
>> >>     }
>> >>     */
>> >>     static public Collection<Person> getPeople(){
>> >>         logger.debug(people.values());
>> >>         logger.debug(people.values().**getClass().toString());
>> >>         return people.values();
>> >>     }
>> >>
>> >>     public Person getPerson(int code){
>> >>         if (code<0)
>> >>             return new Person(-1,"","");
>> >>         else
>> >>             return people.get(new Integer(code));
>> >>     }
>> >>
>> >>     public void savePerson(Person person){
>> >>         logger.debug(person);
>> >>         if (person.getId()>=0){
>> >>             people.put(new Integer(person.getId()),**person);
>> >>         } else {
>> >>             int id = people.isEmpty() ? 1 :
>> people.lastKey().intValue()+1;
>> >>             person.setId(id);
>> >>             people.put(new Integer(id),person);
>> >>         }
>> >>         //generateList();
>> >>     }
>> >>
>> >>     public void removePerson(int code){
>> >>         people.remove(new Integer(code));
>> >>         //generateList();
>> >>     }
>> >>
>> >> }
>> >>
>> >>
>> >> The mapping definitions are:
>> >>
>> >> <action name="*Person" class="org.apache.struts.**
>> >> tutorial.wildcard.action.**PersonAction" method="{1}">
>> >>             <result name="success">/view.jsp</**result>
>> >>             <result name="input">/input.jsp</**result>
>> >> </action>
>> >>
>> >> The model Person is a pojo with 3 attributes: firstName, lastName, id
>> >>
>> >> thanks for the support
>> >>
>> >> Il 12/01/2013 11:50, Umesh Awasthi ha scritto:
>> >>
>> >>  I believe what *Chris* has asked is to copy the code from your JSP
>> page
>> >>>
>> >>> i believe you must be using <s:iterator> tag in your JSP page to
>> iterate
>> >>> some list
>> >>> so please copy that code from your JSP and provide here
>> >>>
>> >>>
>> >>>
>> >>> On Sat, Jan 12, 2013 at 4:16 PM, fusillator <fusilla...@gmail.com>
>> wrote:
>> >>>
>> >>>  Hi Chris, not really sure how to find that code... Anyway this has
>> been
>> >>>> my
>> >>>> steps:
>> >>>> $ for lib in /opt/struts-2.3.7/lib/* ; do jar tvf $lib | grep tld &&
>> echo
>> >>>> $lib; done
>> >>>>    3349 Wed Aug 10 12:51:32 CEST 2005
>> META-INF/sitemesh-decorator.****
>> >>>> tld
>> >>>>    3013 Sat May 15 11:55:14 CEST 2004 META-INF/sitemesh-page.tld
>> >>>> /opt/struts-2.3.7/lib/****sitemesh-2.4.2.jar
>> >>>> 346038 Tue Nov 06 08:13:06 CET 2012 META-INF/struts-tags.tld
>> >>>> /opt/struts-2.3.7/lib/struts2-****core-2.3.7.jar
>> >>>> 136496 Tue Nov 06 08:24:22 CET 2012 META-INF/struts-dojo-tags.tld
>> >>>> /opt/struts-2.3.7/lib/struts2-****dojo-plugin-2.3.7.jar
>> >>>>     752 Tue Nov 06 08:27:06 CET 2012 META-INF/tags/JsonPlugin.tld
>> >>>> /opt/struts-2.3.7/lib/struts2-****json-plugin-2.3.7.jar
>> >>>>       0 Tue May 13 21:39:54 CEST 2008 META-INF/tld/
>> >>>>   27808 Tue May 13 21:39:54 CEST 2008 META-INF/tld/tiles-jsp.tld
>> >>>> /opt/struts-2.3.7/lib/tiles-****jsp-2.0.6.jar
>> >>>>
>> >>>> $ jar xvf /opt/struts-2.3.7/lib/struts2-****core-2.3.7.jar
>> >>>> META-INF/struts-tags.tld
>> >>>>   \decompresso: META-INF/struts-tags.tld
>> >>>>
>> >>>> $ grep -n "<name>iterator</name>" META-INF/struts-tags.tld
>> >>>> 4881:    <name>iterator</name>
>> >>>>
>> >>>> and the tag definition in the tld file is:
>> >>>>
>> >>>> <tag>
>> >>>>      <description><![CDATA[Iterate over a iterable
>> value]]></description>
>> >>>>      <name>iterator</name>
>> >>>>
>> <tag-class>org.apache.struts2.****views.jsp.IteratorTag</tag-****class>
>> >>>>      <body-content>JSP</body-****content>
>> >>>>      <!-- here a lot of not interesting attributes-->
>> >>>> </tag>
>> >>>>
>> >>>> $ find src -name IteratorTag.java
>> >>>> src/core/src/main/java/org/****apache/struts2/views/jsp/****
>> >>>> IteratorTag.java
>> >>>>
>> >>>> $ cat src/core/src/main/java/org/****apache/struts2/views/jsp/**
>> >>>> IteratorTag.java
>> >>>> /*
>> >>>>   * $Id: IteratorTag.java 741179 2009-02-05 16:55:14Z musachy $
>> >>>>   *
>> >>>>   * Licensed to the Apache Software Foundation (ASF) under one
>> >>>>   * or more contributor license agreements.  See the NOTICE file
>> >>>>   * distributed with this work for additional information
>> >>>>   * regarding copyright ownership.  The ASF licenses this file
>> >>>>   * to you under the Apache License, Version 2.0 (the
>> >>>>   * "License"); you may not use this file except in compliance
>> >>>>   * with the License.  You may obtain a copy of the License at
>> >>>>   *
>> >>>>   *  http://www.apache.org/****licenses/LICENSE-2.0<
>> http://www.apache.org/**licenses/LICENSE-2.0>
>> >>>> <http://**www.apache.org/licenses/**LICENSE-2.0<
>> http://www.apache.org/licenses/LICENSE-2.0>
>> >>>> >
>> >>>>   *
>> >>>>   * Unless required by applicable law or agreed to in writing,
>> >>>>   * software distributed under the License is distributed on an
>> >>>>   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> >>>>   * KIND, either express or implied.  See the License for the
>> >>>>   * specific language governing permissions and limitations
>> >>>>   * under the License.
>> >>>>   */
>> >>>>
>> >>>> package org.apache.struts2.views.jsp;
>> >>>>
>> >>>> import javax.servlet.http.****HttpServletRequest;
>> >>>> import javax.servlet.http.****HttpServletResponse;
>> >>>> import javax.servlet.jsp.****JspException;
>> >>>>
>> >>>> import org.apache.struts2.components.****Component;
>> >>>> import org.apache.struts2.components.****IteratorComponent;
>> >>>>
>> >>>> import com.opensymphony.xwork2.util.****ValueStack;
>> >>>>
>> >>>> /**
>> >>>>   * @see IteratorComponent
>> >>>>   */
>> >>>> public class IteratorTag extends ContextBeanTag {
>> >>>>
>> >>>>      private static final long serialVersionUID =
>> -1827978135193581901L;
>> >>>>
>> >>>>      protected String statusAttr;
>> >>>>      protected String value;
>> >>>>      protected String begin;
>> >>>>      protected String end;
>> >>>>      protected String step;
>> >>>>
>> >>>>      public Component getBean(ValueStack stack, HttpServletRequest
>> req,
>> >>>> HttpServletResponse res) {
>> >>>>          return new IteratorComponent(stack);
>> >>>>      }
>> >>>>
>> >>>>      protected void populateParams() {
>> >>>>          super.populateParams();
>> >>>>
>> >>>>          IteratorComponent tag = (IteratorComponent) getComponent();
>> >>>>          tag.setStatus(statusAttr);
>> >>>>          tag.setValue(value);
>> >>>>          tag.setBegin(begin);
>> >>>>          tag.setEnd(end);
>> >>>>          tag.setStep(step);
>> >>>>      }
>> >>>>
>> >>>>      public void setStatus(String status) {
>> >>>>          this.statusAttr = status;
>> >>>>      }
>> >>>>
>> >>>>      public void setValue(String value) {
>> >>>>          this.value = value;
>> >>>>      }
>> >>>>
>> >>>>      public void setBegin(String begin) {
>> >>>>          this.begin = begin;
>> >>>>      }
>> >>>>
>> >>>>      public void setEnd(String end) {
>> >>>>          this.end = end;
>> >>>>      }
>> >>>>
>> >>>>      public void setStep(String step) {
>> >>>>          this.step = step;
>> >>>>      }
>> >>>>
>> >>>>      public int doEndTag() throws JspException {
>> >>>>          component = null;
>> >>>>          return EVAL_PAGE;
>> >>>>      }
>> >>>>
>> >>>>      public int doAfterBody() throws JspException {
>> >>>>          boolean again = component.end(pageContext.****getOut(),
>> >>>> getBody());
>> >>>>
>> >>>>          if (again) {
>> >>>>              return EVAL_BODY_AGAIN;
>> >>>>          } else {
>> >>>>              if (bodyContent != null) {
>> >>>>                  try {
>> >>>> bodyContent.writeOut(****bodyContent.****getEnclosingWriter());
>> >>>>                  } catch (Exception e) {
>> >>>>                      throw new JspException(e.getMessage());
>> >>>>                  }
>> >>>>              }
>> >>>>              return SKIP_BODY;
>> >>>>          }
>> >>>>      }
>> >>>>
>> >>>> }
>> >>>>
>> >>>> Thanks a lot for your help.
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> Il 11/01/2013 20:21, Chris Pratt ha scritto:
>> >>>>
>> >>>>  Can you cut and paste your <s:iterator> code into the email so we
>> can
>> >>>>> see?
>> >>>>>     (*Chris*)
>> >>>>>
>> >>>>>
>> >>>>> On Fri, Jan 11, 2013 at 11:12 AM, fusillator <fusilla...@gmail.com>
>> >>>>> wrote:
>> >>>>>
>> >>>>>   Hi all, I'm new to struts2/java matters, so be sympathetic please.
>> >>>>>
>> >>>>>> I've a question about <s:iterator> tag
>> >>>>>>
>> >>>>>> I recently used it to loop on a Iterable collection of type
>> >>>>>> java.util.TreeMap$Values retrieved by the method
>> >>>>>> java.util.TreeMap.values()
>> >>>>>>
>> >>>>>> getting the following cast exception:
>> >>>>>>
>> >>>>>> 2013-01-11 18:45:00,520 DEBUG org.apache.struts.tutorial.**
>> >>>>>> wildcard.service.******PersonService.getPeople:33 [Person [1:
>> Paolino
>> >>>>>> Paperino], Person [2: Paperon De Paperoni], Person [3: Archimede
>> >>>>>> Pitagorica]]
>> >>>>>> 2013-01-11 18:45:00,523 DEBUG org.apache.struts.tutorial.**
>> >>>>>> wildcard.service.******PersonService.getPeople:34 class
>> >>>>>> java.util.TreeMap$Values
>> >>>>>> 2013-01-11 18:45:00,523 DEBUG org.apache.struts.tutorial.**
>> >>>>>> wildcard.service.******PersonService.getPeople:34 class
>> >>>>>> java.util.TreeMap$Values
>> >>>>>> gen 11, 2013 6:45:01 PM org.apache.jasper.compiler.*****
>> >>>>>> *TldLocationsCache
>> >>>>>> tldScanJar
>> >>>>>> WARNING: Caught an exception while evaluating expression
>> >>>>>> 'people.isEmpty'
>> >>>>>> against value stack
>> >>>>>> java.lang.ClassCastException: java.util.TreeMap$Values cannot be
>> cast
>> >>>>>> to
>> >>>>>> java.util.Set
>> >>>>>>           at ognl.SetPropertyAccessor.******getProperty(**
>> >>>>>> SetPropertyAccessor.java:47)
>> >>>>>>           at com.opensymphony.xwork2.ognl.******accessor.**
>> >>>>>> XWorkCollectionPropertyAccesso******r.getProperty(**
>> >>>>>> XWorkCollectionPropertyAccesso******r.java:93)
>> >>>>>>           at
>> ognl.OgnlRuntime.getProperty(******OgnlRuntime.java:2300)
>> >>>>>>
>> >>>>>> The used variable is reported by log4j.
>> >>>>>> Is there any restriction on the iterator tags?
>> >>>>>> Could someone suggest me a tutorial/howto about ognl/value stack?
>> >>>>>>
>> >>>>>> Best regards
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> ------------------------------******--------------------------**--**
>> >>>>>> --**---------
>> >>>>>> To unsubscribe, e-mail: user-unsubscribe@struts.****apac**he.org<
>> >>>>>> http://apache.org**>
>> >>>>>> <user-unsubscribe@**struts.**apache.org <http://struts.apache.org
>> ><
>> >>>>>> user-unsubscribe@**struts.apache.org<
>> user-unsubscr...@struts.apache.org>
>> >>>>>> >
>> >>>>>> For additional commands, e-mail: user-h...@struts.apache.org
>> >>>>>>
>> >>>>>>
>> >>>>>>
>> >>>>>>  ------------------------------****----------------------------**
>> >>>> --**---------
>> >>>> To unsubscribe, e-mail: user-unsubscribe@struts.**apac**he.org<
>> http://apache.org>
>> >>>> <user-unsubscribe@**struts.apache.org<
>> user-unsubscr...@struts.apache.org>
>> >>>> >
>> >>>> For additional commands, e-mail: user-h...@struts.apache.org
>> >>>>
>> >>>>
>> >>>>
>> >>>
>> >>
>> >>
>> ------------------------------**------------------------------**---------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<
>> user-unsubscr...@struts.apache.org>
>> >>
>> >> For additional commands, e-mail: user-h...@struts.apache.org
>> >>
>> >>
>>
>>
>>
>> --
>> e: davelnew...@gmail.com
>> m: 908-380-8699
>> s: davelnewton_skype
>> t: @dave_newton
>> b: Bucky Bits
>> g: davelnewton
>> so: Dave Newton
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
>

Reply via email to