Widget update method and conditional visibility

Hello, we have recently converted our application from Mx 6.9.1 to Mx 7.0.2, and we have experienced problems in some pages where a customized widget was contained into containers with conditional visibility. For what I could see, the problems were caused by the fact that the update methods of the widget was called a number of times equal to the number of visibility checks. We have solved the problems by adding some checks on the update method, so avoiding to build unnecessary components, but I would like to have some clarification about when the update method is triggered: from the documentation I understood that it is called when the context object of the widget changes (meaning that it is really another object), but this should not be related with conditional visibility. Thanks in advance.  
4 answers

It is correct that update is triggered when the object changes. But, a widget usually subscribes to changes on the object as well. This means that if an attribute changes (which is used in conditional visibility?), an update or updateRendering (a common private method) is triggered as well.

Is it possible for you to share the widget code? (For example on Github or https://gist.github.com)



I cannot share the code, but I run a test project.

Starting from the boilerplate I just modified the update function in the following way

        update: function (obj, callback) {
            logger.debug(this.id + ".update");
            let textDiv = dom.create("div", {});
            textDiv.innerHTML = this.messageString; 


In my test project I have a very simple domain model; I have a popup with nested containers having conditional visibility based on three booleans, and as I open the popup the update function is called three times, and I see three times my message. I removed the updateRendering function, all other methods, and I am not subscribing to any object in the widget. 



Hi Lucia,

This behavoir is probably fixed in Mendix 7.3 release


  • When a widget is conditionally visible, the condition is reevaluated when the context object of the containing data view changes. This happens when, for example, you are navigating to a new page or when the data view is a listening data view and the selection of the widget it is listening to changes. When the conditionally visible widget was shown, it acted like it got a new context object twice, so it executed database queries twice. That seemed like a waste of time and resources, so we fixed it. (Ticket 50714)





Update; the the name implies is update whenever the client assumes an update might be relevant to any of its children.

Though one, would be more efficient.

The update function should based on the received object, change the widget if needed. Though it is not good to "add"/"append" stuff in the update as you don't know how many times it will be called. So start from scratch every update or update you content

The constructor and postCreate function is called one. 

And the update function often call an updateRendering function that will display based on the content of the context. 

Please note the difference betwean update and subcribe. 

update, when the context changes. Subscribe is in you own control 


It not recomended to let your subscribute update to call you update function, most times its call the updateRendering