3 Replies Latest reply on May 27, 2009 6:08 PM by kukeltje

    Delegate config map of lists

      Hi,

      I'm trying to use a map of lists inside of an ActionHandler, but I am not able to correctly configure the list; I get an error saying that it cannot convert a String to a List. Here is the config:


      ...
      <action name="my-action" class="com.sample.action.MyActionHandler">
       <fields>
       <entry>
       <key>one</key>
       <value>
       <list>
       <element>one-1</element>
       <element>one-2</element>
       </list>
       </value>
       </entry>
       <entry>
       <key>two</key>
       <value>
       <list>
       <element>two-1</element>
       <element>two-2</element>
       </list>
       </value>
       </entry>
       </fields>
      </action>
      ...
      



      
      public class MyActionHandler implements ActionHandler {
      
       private Map<String, List<String>> fields;
      
       @Override
       public void execute(ExecutionContext context) throws Exception {
       ...
       }
      
       public Map<String, List<String>> getFields() {
       return fields;
       }
      
       public void setFields(Map<String, List<String>> fields) {
       this.fields = fields;
       }
      
      }
      
      


      Here is the stack trace:


      16:52:38,732 [main] ERROR GraphElement : action threw exception: java.lang.String cannot be cast to java.util.List
      java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
       at com.sample.action.MysActionHandler.execute(CheckRequiredFieldsActionHandler.java:17)
       at org.jbpm.graph.def.Action.execute(Action.java:122)
       at org.jbpm.graph.def.GraphElement.executeAction(GraphElement.java:259)
       at org.jbpm.graph.def.GraphElement.executeActions(GraphElement.java:215)
       at org.jbpm.graph.def.GraphElement.fireAndPropagateEvent(GraphElement.java:185)
       at org.jbpm.graph.def.GraphElement.fireEvent(GraphElement.java:169)
       at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:452)
       at org.jbpm.taskmgmt.exe.TaskInstance.end(TaskInstance.java:393)
       at com.sample.SimpleProcessTest.executeTask(SimpleProcessTest.java:103)
      
      


      Does anyone know why this won't work? Thanks...

        • 1. Re: Delegate config map of lists
          kukeltje

          correct. afaik, the 'value' can only contain Strings, or the likes, no maps, lists etc...

          • 2. Re: Delegate config map of lists

            Can you clarify what this part of the documentation means?

            maps. In this case, each element of the field-element is expected to have one subelement key and one element value. The key and element are both parsed using the conversion rules recursively. Just the same as with collections, a conversion to java.lang.String is assumed if no type attribute is specified.


            (from http://docs.jboss.org/jbpm/v3/userguide/jpdl.html#configtypefield)

            I would have figured that parsing the elements recursively meant that the elements could any type, and that they'd be parsed like a base element. Maybe I'm misinterpreting what the docs are saying?

            Thanks again....

            • 3. Re: Delegate config map of lists
              kukeltje

              Yes, you are 'misinterpreting' the docs. You can pass in maps, collections etc, but each value can only be a simple type (String, Integer etc, but no map, list, collection)

              You *can* pass in arbitrary complex XML structures that will be converted to Document if you use that as the type in your class