Skip to Content
author's profile photo
Former Member

MVC Controller Communication

Hi Guys,

after a short glance at the MVC tutorial on help.sap.com i want to create my own application.

I have one main contoller, two sub-controller of which one has a model calss connected that gets data from function modules.

One subcontroller calls different views that gets data from function module calls.

My problems are:

1) how can i get two subcontroller to communicate with each other? is there a direct way without main controller possible and if not, can i manage the communication. is it possiblejust with DO_HANDLE_DATA and DO_REQUEST?

2) does it always have to be the way with data collection via model class that the result of a function from the model is stored first in an attribute of model class and then has to be set as page attribute of the called view?

Can anyone please help me as there is no clear help from sap...

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    author's profile photo
    Former Member
    Oct 05, 2005 at 04:31 AM

    hi,

    For 1st problem.

    you can use application class variables to communicate b/w two controllers.

    For your 2nd problem.

    in MVC its the controller which is basically controlling the flow of application hence for sending data to your view you have to send via controller using set page attributes.

    However you can also pass data directly to the view without intervention of controller i.e straight from one view to other or from model directly to view.

    for this you have to make use of application class. and just use application class attributes and access them througout application as global variables or set view attributes via them. you can access them as:

    application->variable_name

    hope this helps you, else reply,

    Regards,

    Hemendra

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Christian,

      it's always best to not only rely on the help, but also consult SDN as a resource first 😊

      Welcome!

      Make sure you read this forum post:

      MVC: DO_FINISH_INPUT after return from sub-controller

      Especially the last part from Rainer about DO_FINISH_INPUT and the GLOBAL_EVENT parameter.

      By the way, why do you want to make two subcontrollers communicate without using the main controller?

      Every controller has M_PARENT and M_SUBCONTROLLERS as attributes, why do you not want to use them - any special reason for that?

      Cheers,

      Max

  • author's profile photo
    Former Member
    Oct 05, 2005 at 04:44 AM

    Hi Christian,

    You can use model class to communicate between two subcontrollers. for this you have to instanciate your model at appriate places in both sub controllers. in this case you will be using only model class other than DO_HANDLE_DATA and DO_REQUEST.

    Ya in 2nd case you are right you get attribute values through model class, But for this you need not to set each attribute in page attribute of view. Just set your model with TYPE REF TO..[your model class].And then you are able to retrieve value by <%=model->attribute%>.

    I hope this helps you.

    Regards

    Amit

    Add comment
    10|10000 characters needed characters exceeded