cancel
Showing results for 
Search instead for 
Did you mean: 

HashMap problem in Activiti

zlatan316
Champ on-the-rise
Champ on-the-rise
Hi,

I have the below code which gives me a HashMap and sets it as the variable.

   @Override
   public void execute(DelegateExecution execution) throws Exception {      
      Reader readerObj = new Reader();
      readerObj.run(); // Creates values in a HashMap within Reader.
      
      MainClass mc = new MainClass();
      mc.map = readerObj.getMap(); // Passes the created HashMap into a new global one.
      mc.decision = true;
      execution.setVariable("decisionVar", mc.decision);
      execution.setVariable("mapVar", mc.map); // Sets the HashMap Variable      
   }


I then want to ideally get something from the HashMap. I tried using ${mapVar.IsEmpty()} on a flow to return a true condition, but it gives me the message "Unknown method used in expression ${mapVar.IsEmpty()}. IsEmpty() is a method that belongs to the HashMap<> collection.

Can someone please explain where I am going wrong?
5 REPLIES 5

trademak
Star Contributor
Star Contributor
Is IsEmpty the exact method name you used? It should be isEmpty() to start with. Is that working?

Best regards,

Oh lord, that was it. I feel like such a fool Smiley Indifferent Thank you!

Just out of interest, if I was to retrieve something from the HashMap and check it is a string of "123". would the below expression work?

${mapVar.Get('key')=="123"}

The reason I ask is I always though '==' is a way to compare boolean rather than Strings.

jbarrez
Star Contributor
Star Contributor
yeah, altough it's probably lower-case 'get'. Equality in javascript is always == or even === (type check)

zlatan316
Champ on-the-rise
Champ on-the-rise
Thats interesting, as I just tried using the below expressions for two flows coming from an exclusivegateway.

${mapVar.get('MAIN_KEY-time_slot')=="true"} and ${mapVar.get('MAIN_KEY-time_slot')=="false"}

…but I think the map is empty as mapVar.isEmpty() evaluates to true. I get the message "No outgoing sequence flow of the exclusive gateway 'exclusivegateway1' could be selected for continuing the process".

EDIT: I've discovered the passing of the map is what isn't working correctly
<code>
Reader readerObj = new Reader();
readerObj.run(); // Populates HashMap in Reader class.
MainClass mc = new MainClass();
//mc.map = readerObj.getMap(); //This does NOT work. In activiti, nothing evaluates.
mc.map.put("MAIN_KEY-time_slot", "true"); //This works, and can use an expression to evaluate it.
</code>

Any idea why?

jbarrez
Star Contributor
Star Contributor
Is that put done *after* you added it to the execution? It's possible you need to  do that up front.

Anyway, use a map is never a good idea (it gets serialized).
Any reason  why using plain vars is not an option? It would simplify a lot of things (you could check the database tables contents yourself for example)