on 05-04-2006 6:49 AM
Hi to all,
In MVC based BSP application how to access application class in controller and models?
I had seen application attributes in controller class.
Suggest me how to use data binding using example, if there.
Regards,
you can access the application class attributes in a controller by creating object of application class as:
data: application type ref to <name of app class>.
CREATE OBJECT application TYPE <name of app class>.
Hope this helps,
Regards,
Ravikiran.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This will create an object of the application class in the controller. If any attribute is declared as <b>Static</b> in the application class, and if the application is stateful, the data stored in the attribute will hold his value throughout the application, even though we declare a new object. I have used it in a similar kind of sicenario involving controllers and page with flow logic, and works fine for me.
Regards,
Ravikiran.
Hi Bhupendra Singh,
Data: co_application type ref to <Application class name>.
CREATE OBJECT co_application TYPE <Application class name>.
Create a page attribute in your view namely...
vi_application type ref to <Application class name>
Now it the controller add the lines below for assigning the controller's application class object to the view's application object in the page attribute.
Data: main_view type ref to if_bsp_page.
main_view = create_view( view_name = 'exercise.htm' ).
main_view->set_attribute( name = 'vi_application'
value = co_application ).
Hope it solves your problem.
Regards,
Maheswaran.B
Hi,
if your app is stateful you don't have to instantiate a new application object it is already known in your controller but not typed correctly. You have to cast it:
Data: co_application type ref to <Application class name>.
co_application ?= application.
Now you have full acces to your application object.
Regards,
Sebastian
Sorry for my last post. Now this is the right one
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/bsp/bsp model data binding made easy.pdf
Regards,
Ravikiran.
There seems to have been several question on the use of the application class in the last few days. More concerning however is that there has been a lot of really incorrect information posted in the forums about application classes and their scope/lifetime. In this thread for instance one person states that application objects only have lifetime within the layout of a MVC and you have to recreate them within the controller. This is INCORRECT.
For an excellent overview of the application class functionality please have a look at the following Help Link:
http://help.sap.com/saphelp_nw2004s/helpdata/en/21/8cec3ada87e076e10000000a11405a/frameset.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't understand. Sebastian Behne has already provided you with the correct way of accessing the Application object within the controller. Did this not work for you? You marked his answer as "solved your problem".
All controller classes have an attribute called application. It is type ref to object. Therefore it is generically typed and can refer to any object class. This attibute is inherited through your controller class's super class - CL_BSP_CONTROLLER2.
Because of the generic type on the application class is must be cast into the specific type before it can be use. This is the code sample that has been supplied to you.
Once you have the application class in your controller it is quite simple to just pass the object reference into your model. If I am going to have a lot of interaction between the model and the application class, I create an attribute in the model for the application class. I then can call a method of the model from the controller and pass the reference to the application class as an importing paramter. This method can set the reference into the model attribute for easy access later. This does however tie your model to use with just this BSP application.
Hi Bhupendra singh,
The life time of the application object is limited to the layout page. It has no effect in the controller.
So you need to create a object of application class as told by the Ravikiran.C in the previous reply.
Hope it solves your problem.
Regards,
Maheswaran.B
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.