Mendix Passing Null Attribute Values to Java Function

0
Hi Everyone,   I've recently been working with the Word Template module created by Ivo Sturm and it's working brilliantly for the most part. I've recently had a use case though that requires a table to be added to a document dynamically.    Using the Word module you define a table in an entity that is committed to the Mendix database which is then passed to the Java function that in turn uses the Apache POI library to create the document. So far, so good!   The problem I'm running into is that while the table definition is created and is most definitely committed to the database before being sent to the Java function, when the entity arrives in the function constructor the attributes exist, but the values are null so the function crashes in runtime.    It took a while to figure this out and further research seems to point squarely at the entity not being committed before calling the Java function, so I checked this and that doesn't seem to be the issue here. Can anyone point me towards any other possible reasons why this would be happening?    Hopefully I've provided a decent description of the problem, but I'm happy to expand with screenshots etc if required!   Thanks in advance!
asked
6 answers
0

Hi David,

There's a JavaAction named: End Transaction and start transaction in community commons, use this JavaAction before calling your java action, this way, your transaction will be committed, before calling your custom Java action,

 

So.. Before calling your java action, use EndTransaction then StartTransaction and then call the JavaAction, this way it should work.

 

Hope it helps,

Thank you!

answered
0

Hi David, I am the creator if this module. Reading this I don't directly have a clue. Perhaps it is good to enable TRACE logging for the module. I added quite some trace logging to see what happens with the data fed to the Java action. Let me know what that brings! If that doesn't bring you what you need, happy to have a quick peek if you can share the actual project or a test project.

 

 

answered
0

Here's a screenshot of how I have the End- and StartTransaction CC functions set up...

 

image.png

answered
0

OK, so I've narrowed it down a bit further - it appears that the Enumerations (or, even more specifically, the captions) are null once passed to the Java Function. So these lines:

 

Enum_FontType fontType = tbleCell.getFontType(); <-- this is OK

String fontTypeString = "Normal";

if (fontType != null) { <-- this is OK as well, the attribute exists

fontTypeString = fontType.getCaption(); <-- this results ing the fontTypeString being null

}

 

Where attributes that are not enumerations are passed through, like tableCell.getFontColor() or tableCell.getValue(), the values are fine and can be used (although the getFontColor() failed as I specified 'Red' in my test). 

 

I couldn't see in the function where Enum_FontType was declared so I suspect that's in the Apache POI library somewhere. I'm going to dig into that a bit but I thuoght the extra info might help!

answered
0

Hi Everyone,

 

Update on this one. I created a new project / app and re-added the WordTemplate module to it. I had to create an app in 10.24.x as the WordTemplate module has been upgraded beyond the 10.18.x version I was using. Created a template and ran it through and it worked flawlessly. As far as I could tell, the java function was the same as the old version, but didn't receive null values like the old version did. Would the next best stap be to upgrade the app and re-add the new version of the module?

answered
0

Hi David,

 

Great to hear the new version worked. It is hard to say why it worked as I don't know the details of your app. If you would like to be certain; could you share with me from which version you are upgrading to which version? And whether you upgrade via the module in the Marketplace or extracting it from the demo project? And whether you have the excel importer and/or exporter modules in your app? If so, which version? These modules also use the Apache POI library and can conflict when using different versions from the word template you are using.

 

 

 

 

answered