the world of model driven development

Archive for the ‘modeler’ Category

Enumerations: The Mapping’s Revenge

In the periods of yore, we great pioneers of Mendix waded deep into the murky depth of the modeler handling web service mappings after web service mappings. From these times came an enumeration mapper of inspired thought: Keeping Enumerations as Entities

As you can see from this article it allowed us to get away from pesky manual comparison microflows of strings to enumerations. Unfortunately this methodology has its drawbacks, first of all the enumerations were stored in the database which implies constant database queries when mapping. Now if we could only get away from this…

Well good news! today we have come with more gifts for you intrepid modelers: An alternate method for determining an enumeration from a string.

So how do we do it. Well firstly lets look at the problem, we have a few situations (xml, webservices) where we can receive a string we need to map into an enumeration. So what we are looking for is a method to input the string and retrieve the enumeration value. Now java actions and microflows only return specific enumerations, so unfortunately we cannot get away from this. However we can make an easy way to retrieve this.

So in the new method we create a non persistent entity we call “EnumerationMap”, to which we add the enumerations we wish to map.

The ext step is to create a java action which given a name for the enumeration and its value (caption or value but case sensative) can return the EnumerationMap entity populated with the found value. We can then build a nice and simple microflow which returns the enumeration as required (see below). and voila, now only one annoying entity(although non persistent) in the model and no db queries required.

To see the magic sauce inside the java action please download the example project package here (v 4.0.1)

Please let me know if there are any thoughts or queries

Shrink-wrap your widgets and themes on demand

If you are fortunate to develop on a Mac or *nix system and run your Mendix project on a shared folder with your Windows VM, there is a little bash script you can use to compress your widget- or theme-artifacts as they change. I’m sure there are other ways of doing this on a Windows machine, and if you know of a suitable approach, please let us know.

The first step is to put your code folder somewhere outside of your project, since you don’t want to commit this to TeamServer™. If you do, use your SVN tools to ignore that folder for the purposes of development. After you’ve set it up, launch your IDE.

I use Appcelerator’s TitaniumStudio™  as my preferred editor when writing JavaScript, in conjunction with FireBug or Chrome’s developer tools for the interactive command prompt. This is handy for real-time prototyping and then using those changes in your editor.

The problem I find is, every time I make small adjustments to my code, I have to compress the files back into a zip-file and restart my modeler to see the effects. The same actions apply to theming. You make minor CSS changes and the ritual of compressing restarting repeats.

I Googled around to brush up on bash scripting and I wrote a little looping bash script that executes a command every second, making sure my widget or theme package is always up to date. Here it is, continuous.sh:

#!/bin/sh
cycle() {
 while [ 1 ] 
  do sleep 1
  eval $*
done
}

Then you automagically shrink-wrap your package by running:

$ ./continuous.sh “zip -r -u path-to-your-widget/MyWidget.mpk path-of-widget-files-folder/*”

Now every time I make a change to my code, the archive gets updated automatically. I’m not a command-line wizard, but this does the job for me. All I need to do now, is restart my modeler. One day hopefully, I’ll be able to automate this too.

A video explains it a bit better if you have trouble following along:

To infinity loops and beyond

Last week ended on a high note; our blog was mentioned by the Mendix Tech blog! It was great seeing a picture of our blog on theirs, and a thought occurred to me; what if I post a picture of their blog displaying a picture of our blog, would this cause an infinite loop? Well, theres only one way to find out! Before I do however, I just want to thank Mendix Tech Blog and co for their recognition, we appreciate it and we love reading the helpful and insightful articles and posts on your blog. Here goes..

..so if you are reading this, it means that all is well and that the internet survived my evil infinite loop experiment. But since we are on the topic of loops and evil experiments, have you ever looped your Mendix Modeler into infinity? Lets investigate some basic recurring looping scenarios.

Event handlers

In Mendix 101, you’ll learn that you should never commit the same entity on which the event handler was triggered, with the exception of “Commit without Events“. If you do, this will cause a cascade event to occur and will loop until your java memory runs out. Luckily, this happens really quickly and you are presented with a thick red line in your console output stating a Stack Overflow exception or “An unhandled error occurred in the MxRuntime.

The consequences of you actions are fairly benign and you’ll realize the error of your ways soon, unless you only find this inside production. Hopefully you are exercising the best practice of testing your app properly before deploying it to production, right?

To infinity and beyond

So, lets see what a real infinite loop could look like, one which runs away. When this occurs, there isn’t a real obvious symptom or sign informing you of the situation, unless you have introduced a logging- or some other feedback artifact and and you happen to be monitoring your app. In most cases, you will probably start by suspecting it when your server feels like its dying a slow death.

If you do and want to follow your gut, open up the Windows Task Manager (Ctrl-Shift-Escape for short) and check if your CPU reports unusually high activity by a javaw.exe process.

Lets simulate a loop using a simple microflow. We’ll see that our javaw.exe process quickly ramps up in memory, but levels; mine stopped climbing at 304Mb, results may vary. However the constantly high CPU usage should be a dead giveaway that something is not right.

If you are running the modeler, you’ll find that its futile stopping the server, so if you are in the mood of gambling with which colour wire to cut, you’ll have to kill the active javaw.exe process which will cause your computer and modeler to return to a state of normality.

Thats some looping scenarios in a nutshell. We’ll be covering some looping patterns in the future, but unless you love reaching terminal velocity while playing portal or other such fun hobbies, try avoid infinite loops in your modeler.

Why your Barista is Happy about the easy Entity Creation and Change Feature

I love mendix. If I’m not modelling then my mind is thinking about things I can model all the time. When the opportunity allows for it I hang out at a local Vida e Cafe, have a couple of awesome coffees and smash out some model solutions or pet POC’s.

Some times my coffee arrives while I’m in the middle of a Microflow, to leave the Microflow in order to grab my coffee would break my concentration putting a potential delay on the modelled solution. The other option is to ignore my coffee until the Microflow has been completed. Luckily for me Mendix 4 comes with some new features that make modelling solutions even quicker than before.

Create then Change – the Barista’s Frustration

In previous Mendix Modeller versions if you had to create an entity that required the population of data then you would have to do it in two separate action activities. You would have to create an blank and empty entity before creating a change activity which enabled you to populate that entity with specific data. These two actions meant it took slightly longer to complete a Microflow putting the enjoyment of your coffee at higher and higher risk depending on the number of entities created and changed per Microflow.

Enjoying my Coffee with Create And Change

Mendix 4 has changed that. You can now create and change entities in a single activity. I no longer have to create an entity, which is destined for change in any case, before creating a second activity to do so. The result is more elegant, refined and quicker 1 step create and edit process instead of a 2 step process.

Why this is Really Good News

1. The obvious thing is that Microflows can be completed quicker and have a more natural, even easier to understand, flow which is great when working directly with a business level client to create a business Microflow.

2. The thing to really get excited about is how responsive the Mendix dev community is. The modeller is already a shiny, good quality product however they’re not stopping there. Each release brings with it something small that makes the product even better. Signs of a bright future for modellers and Mendix clients everywhere.

3.  The last thing is that obviously there’s now less chance of my coffee getting cold.

Do you have any favourite features on Mendix v4? We’d love you hear more about it in the comments section below!

Epic Mendix 4 Release

May the 4th be with you came and went, and though it seemed to be a fitting date for the announcement of the next version of the Mendix modeler, it came today none the sooner and promises to be yet another smashing release.

We were provisioned with a courtesy copy of the beta, and it is absolutely packed with features. It hallmarks an array of productivity enhancements and new technology, including the ability to develop mobile-based web forms. Its one of the major highlights of the new release but in no way overshadows the countless other tweaks, enhancements and new features included with the new modeler. We find the new additions very welcome and timely, since we’re already benefitting by it in a big way.

It’s epic feature discovery and has the same kind of excitement that accompanies a new release of a Star Wars episode; for those who are fans. We won’t be covering everything in a single post, its too much to cover, so we will attempt to uncover some, if not all of the new features, in the weeks to come.

Grab some popcorn and enjoy our little fan “film introduction” we made for the Beta and go grab the Modeler and see what you can find out!

Enumerations as Entities

Enumerations within most normal languages are annoying to maintain and build logic off of. In most cases I have seen String variables or manually mapped integers being used. My experiences within the system analysis, database and business intelligence combination always led me to using database table entries with business logic attributes, although convincing the developers of their benefit was not always an easy battle. But, more on that transition in another post. So in comes Mendix with a more formal, easier-to-combine into business enumeration. But as we all use them on a daily basis (or at least should be) I won’t go into diatribes about their benefits, proper usages and so on. Instead this article will revolve around a Java function entity combination we use to get around the two issues we have had with enumerations.

The first common issue we faced was associating attributes with an enumeration. Creating an entity with the enumeration as a unique attribute solves the issue. However, the problem comes in maintaining this entity when creating new enumeration values particularly across multiple environments.

The second issue we are commonly faced with is mapping web service string results into enumerations (A nightmare for anyone who has ever tried). Creating a microflow to map these manually is a terrible solution but unfortunately the one we tend towards. Not only does it create clunky technical microflows but it also creates maintenance issues.

So what do we do make our lives simpler? Well fortunately the team from Mendix have provided the reflection module a perfect spot to get inspiration from. So using this starting point we construct a Java function to be called during the start-up microflows which using code inspired liberally from the reflection module runs through an enumeration set and populates an entity and voila we have a self-building entity to run our business logic and web service mappings off of.

Now words are great but let’s not recreate work for everyone and get to an example. So here we have a module (I will work on adding it to the store soon) EnumEntityBuilder with a simple entity FruitEnumEntity add it to a play project and link the FruitEnumEntity-Overview form from the navigation. I have provided 3 buttons to play with “Build”, “Clear” and “Find a fruit”. Build runs the Java function which populates the enumeration entity, the grid on the page will provide them. The second function clears the entities so knock yourself out adding new and removing new fruits. “Find a fruit” pops up a text search dialog to emulate a web service mapping to find that elusive enumeration.

Well I hope this can help you in future projects to save time and build more robust logic. And once more here is that example module: EnumEntityBuilder.mpk.

7 Hotkeys of Highly Effective People

Clicking is sometimes a drag, especially when you are on fire. You don’t want to break your momentum by taking your hands off of the keyboard to invoke some action on the screen. You need hotkeys.

I’ve watched releases of the modeler carefully, and now and then a new hotkey sneaks in without huge fanfare. Here are some that my fingers find most handy.

F5, Run Baby Run

I develop on a Mac, and leverage many of its tools, and the command-line is one of them. Sure not all Business Engineers will be power users, but sometimes you’ll find some Business Engineers need a little more umf now and then. For instance, when designing themes for Mendix, I need to make minor adjustments to my theme and apply it real quick back into the zipfile. After making these changes I cmd-tab to my terminal, hit the “up” key to get my last zip bash command, then cmd-tab back to my Mendix modeler, and hit F5. This gets repeated frequently if my design changes with many little iterations. Better yet, let me just show you 1 iteration. Notice the mouse cursor stays in one place.

Shift-F5, Stop

What goes up, must come down. Use Shift-F5 if you need to stop your server. You’ll probably use this infrequently.

F2, Garden-Variety Rename for Windows

This is a bit redundant, since you can start typing away at captions in your microflows or widgets on your forms. The only time this will be useful, is if your properties pallet has focus on another field than the Caption field.

Ctrl-Left & Ctrl-Right, Moving stuff

This one I absolutely love. Entities with lots of attributes generate grids on forms that contain a horde of columns and search fields. If only there was a way to sort them quickly. Talk is cheap. Lets see it in action.

F11, Maximize and Restore

And as you’ve seen in the previous video, F11 is a must if you work on a screen with little real estate. Use this key to maximize your workspace.

Ctrl-G, Goto Artifact

This one is handy if you know what artifact you want to navigate to within your model, without hunting for it in the Project Explorer.

Another handy trick, is using the Mouse’s middle button on the microflow canvas. Its helps you pan your view, and using the mouse wheel, helps you zoom in and out if you don’t use a Magic Trackpad™.

Productivity is like Formula1 racing. Every little improvement helps, even if it contributes a 1 or 2%. Once you try hotkeys, you will find your ergonomics improve, your fingers do the work and helps you move with incredible ease through your modeling routine letting you focus even more.

I’m burning to see more hotkeys in future versions of Mendix.

Design a site like this with WordPress.com
Get started