Skip to main content
Senior
December 16, 2024
Solved

Using a presenter in a container to communicate with model

  • December 16, 2024
  • 3 replies
  • 1363 views

Hi, I was wondering the safety regarding using a presenter within a container? I need the container, on click, to send information to the model. I cannot do this from the view, because this is a onclick function. 

Is it safe for me to define/set the presenter of the screen in the container then use it in the container?

Best answer by GaetanGodart

Ok but then you do not have to bypass the use of the view.

So the example I shared would work for you.
Clicking on the button inside the custom container triggers an interaction that emits a trigger.
This trigger is caught on the view level in an interaction that call a function.
This function calls a function in the presenter that call a function in the model and the information is passed.
Now you can do the same but also send a parameter in the function.

 

Tell me if you can achieve what you want.

 

Regards,

3 replies

Andrew Neil
Super User
December 16, 2024

Is this a TouchGFX question?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
PriyankAuthor
Senior
December 16, 2024

I put it under IDE since that is where the code for this would go, however yes, I am using TouchGFX for development as well.

Andrew Neil
Super User
December 16, 2024

As the question is all about TouchGFX stuff (presenter, container, model, view, onclick function), I'll move it.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
GaetanGodart
Technical Moderator
December 17, 2024

Hello @Priyank ,

 

I am not familiar with "onclick function".

In my knowledge, the simplest way is to use the view. Find attached an example of this.

I have tried to bypass the use of the view but without much success.

Why do you want to use the presenter? What is preventing you from; using the view?

 

Regards,

PriyankAuthor
Senior
December 17, 2024

Hi @GaetanGodart ,

 

The reason I want to use the presenter is because the container holds data that the model needs. The container is a button, and it has a virtual function which I called onClick, when clicked. When clicked it sets a variable I created on the container to true. I need now to send this value to the model so the model knows it was clicked. So essentially, clicking the container will set the containers variable to true and simultaneously send this to the model. I already have a callback attached to this because the screen changes using other information from the container.

Another example I would need this is for the keyboard container. Although the keyboard is able to change the value of a text area on screen, the model, which holds the data/data structure, needs to be sent the data as soon as the keyboards submit button is clicked. Context: I have a keyboard container on each screen where the keyboard is used.

GaetanGodart
GaetanGodartBest answer
Technical Moderator
December 17, 2024

Ok but then you do not have to bypass the use of the view.

So the example I shared would work for you.
Clicking on the button inside the custom container triggers an interaction that emits a trigger.
This trigger is caught on the view level in an interaction that call a function.
This function calls a function in the presenter that call a function in the model and the information is passed.
Now you can do the same but also send a parameter in the function.

 

Tell me if you can achieve what you want.

 

Regards,