Build Dynamic Xpath - Mendix Forum

Build Dynamic Xpath

13

Hi, I have pretty significant issue with the way you data source and filter data and do complex retrieves on your database.

 

Problem

When you have an overview page for an entity that has many attributes, you will want to filter on those attributes. When that data set is large, the filtering method must be very optimized. Right now, if you want to filter on those, you will need to create microflows that have way too many and confusing paths to select the correct retrieve action. Since you do NOT want to retrieve all of the data and than subtract and iterate over those lists for all those attributes (because major performance impact), you will have to create a path for every possible filter combination. For example; with two attributes that is no problem; only four paths. But with five attributes this grows exponentially to 32!

 

I have read about people suggesting java actions to do this. But there are so many reasons as to why this is a bad idea:

  1. This is not type-safe. Since the java code does not know the entity/attribute names, you will always need to hardcode them, making it very dangerous. This makes changing attributes names impossible, since you will have to change it in literally all your java actions, when you don’t even know where this attribute name is placed, since there is no check on that. 
  2. In combination with the first, this is very un-future-proof. When that project is reopened after a year or so, there can be major issues.
  3. Only java programmers will be able to adjust that code. A mendix developer will have no idea. Very bad practice.
  4. Your find-usages functionality is completely gone, since mendix does not check custom java code.
  5. Such a complex system should not be necessary for a very common and basic functionality.

 

I really want to inform people to be very careful with java actions as complex as this. I also want people to stop suggesting these kinds of things, since there can be major issues resulting from that, where problem solving is incredibely complex. Especially through the complex system and stacktraces that mendix supplies.

ONLY USE JAVA ACTIONS WHEN ARE AN EXPERIENCED DEVELOPER, KNOW WHAT YOU ARE DOING, AND ONLY AS LAST LAST RESORT.

 

My solution

Make it possible to build an xpath fully dynamic, instead of sort of hardcoding it into the retrieve action. It can be as simple as being able to pass a string variable into the xpath box of the retrieve action, and then build up that string variable in the microflows using exclusive splits. In the example case of filtering on five attributes, this would give the option to create a microflow with only five splits after each other followed by a single retrieve. Way easies, way more good practice.

 

 

asked
1 answers

Luca,

This capability currently exists in the Grid Search widget package.  You can find it here:  https://appstore.home.mendix.com/link/app/49364/

The AnySearch widget enables you to create dynamic XPath as a Mendix developer without any Java work needed.  I have used this successfully and it works really well.  See a snippet from the documentation below:

Hope that helps,

Mike

Created