How does a widget communicate with other components?

2
Hi all, I am trying to create a generic widget where users can select (one or multiple) regions on maps. The base part of the widget is ready (JS + xml). I can include the widget in the modeler in my project, the map shows up and regions can be selected. In my widget I have functions ready for retrieving the selected regions and I can trigger something on an event (for example a click on the map). Now I am working on communicating the selected areas to other components. As you can probably tell, I am not very used to the Mendix platform yet. I am trying to understand how other components can "subscribe" to my widget so they can use the selected regions (which is a list of "region codes") for example for filtering datagrids or for other purposes. On a concept level I am trying to understand whether to use a "listen"-function or something like "events", or microflows? My guess is that I want to trigger an event (change or update event?) which somehow holds the region-codes of the selected regions (array of strings). Or trigger a change event and expose some kind of method for other components to retrieve the selected regions? From the documentation I cannot seem to figure out how to do this. Is this where microflows come into play or something?
asked
2 answers
2

Best idea is to change/update a referenceset with the selected regions and trigger an after change microflow that updates the object to which they are all connected with a refresh in client.

Edit: The object in this case would be the actual mendix object of the dataview that is being shown. You would get this object in your widget through the applyContext() function, which gives you the currentobject in the dataview. (Assuming your widget uses the dataview object, if not, you can't really have a direct object connection as it wouldnt know what object you want).

From there on, you can set a reference in your XML to which the selected regions need to be written and use that reference on your current object (of the dataview) to set the regions. You can trigger a microflow after this to further process this new reference.

From there, your logic-chain lands you back in the modeler/runtime(instead of the widget, who's job should now be done). In the modeler you can now do whatever you wish with the newly selected regions, like displaying them in a datagrid. (If saved properly in the widget, all you would need is a refresh in client change on the object and a reference set selector / datagrid constrained on the refset in your dataview.

answered
0

Hi,

You mention "an object to which they are all connected". How can I create such an object in the widget and keep it isolated from the other components? I am trying to keep the widget as independent as can be.

Can I create a new object for each instantiated widget and (for example) fill that with all regions in the map (can be different per map) and a flag for selected/not selected? Or just an object with a list of the selected regions)?

Is there any kind of example or documentation where I can figure this out?

Thanks in advance!

answered