on 10-11-2004 1:41 PM
I'm dealing with the following problem:
MVC application, tableview in subcontroller, using iterator, creating inputfield in render_cell_start, _value via data binding - everything working ok so far.
Now I need to not return this inputfield as p_replacement_bee, but run render_to_string to first and make the p_replacement_bee a html_bee, because I have to alter the html output of this inputfield.
After debugging into <b>if_bsp_beerender_to_string</b>, going down to the METHOD IF_BSP_PAGEGET_ATTRIBUTE, I found out:
This method is trying to retrieve an attribute from my controller with the attribute name of <b>MODEL</b>, but the name of the controller attribute is <b>MY_MODEL</b>.
In my application I always use MODEL as the page attribute, and MY_MODEL as name for controller classes attributes. Always worked fine until this special requirement came up.
While debugging I altered the name of the attribute that the method IF_BSP_PAGE~GET_ATTRIBUTE is looking for to MY_MODEL (the right controller attribute), and it worked.
So, my question is:
Is the name of the page attribute required to be the same as the controller attribute here?
Or is there an dead-easy hint I overlooked?
(renaming all page attributes to match controller attribute names is not exactly the prefererred solution, unless it was meant to be that way).
Cheers,
Max
Max,
I still have this question of yours on my watch list. Somehow, I suspect I understand the question. Can not be sure. So let me just answer any question here.
What does model binding actual bind to seems to be the question? We have a name/id for the total model, we have a controller id, we have the attribute name of the model, etc. Most of these are not interesting.
When you write a binding string, it is of the form: "//ABC/XYZ". This means ABC is the name of attribute on the view (the current execution context!) of the model. XYZ is just the name of the data on the model. Important: ABC is not the model name/id, or anything like controller name. It is the name that you actually used in the attributes tab of your view (that thing you declared as TYPE REF to something that has a IF_BSP_MODEL interface implemented).
So given this string, it explains why the call if_bsp_page->get_attribute( 'XYZ' ) is made. Given the name, we now require the reference onto the actual model class.
It is not required that the attribute name be the same everywhere. The important aspect here is the execution context. For some reason, while it is processing the tags, it thinks that the controller is "on top of context stack", and this causes the confusion. Vaguely, I can remember that there was something problem in this area. Have forgotten the exact details.
What you should look at, is to use a binding for the htmlb tableView. Then, during the interator calls, there is a p_call_binding string that should be correct.
If all of the above does not help (what I suspect), you will have to open an OSS message. This is so we can actually debug through and see what is the execution context.
brian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Slightly off-topic.
It seems to me that it would be great if ABAP Objects allowed me to define virtual attributes, as is possible in some other OO languages.
This feature allows the developer to specify a method that is to be called whenever an attribute is accessed. So for example, an MVC binding of //ABC/XYZ, would resolve to (if I understand correctly):
whatever = <model_instance>->xyz.
But instead of the attribute XYZ needing to have been populated already, if XYZ was virtual then at runtime a method such as GET_XYZ would be called:
METHOD get_xyz.
* Do whatever, such as buffered DB access
* R_XYZ is a returning parameter of same type as XYZ
R_XYZ = <whatever>.
ENDMETHOD.
That's all.
Scott
The model classes works about this way. The code first checks for a getter and/or setter method. If these are available, they are used. They must just have a predefined signature. Otherwise generic ABAP is used to update values.
For ABAP, AFAIK, such virtual attributes were planned long time ago. Just never made it into reality. Would also have liked it a few times
...
just couldn't let that problem rest, on a monday morning full of energy
...
Ok, think I solved my problem, all I needed were some kind words from Brian (once again
After paying attention to the execution context I found out that of course I passed on a page_context parameter to my render_to_string method, but as I did just use it for non-data-binding bees before, I was not aware that I was just passing on any page_context that I obviously got ahold of ...
Then, sure as hell, this would cause an error when trying to get that attribute, as the used page-context was the one from the controller class, and there is no such attribute in this class.
So, "all" I had to do was to make sure that I get the right page_context (the right one being the page-context of the view) into my render_to_string call method. Adding this line to my view at the very top ...
model->page_context = me->_m_page_context.
... and changing the render_to-string method call in my iterator's render_cell_start to this ...
html = inputfield->if_bsp_bee~render_to_string(
my_model->page_context ).
... corrected all of my previous mistakes in using just any page-context.
Final answer to my thread-naming question:
No, the name for model instance and page attribute is sure not required to be the same.
As I use render_to_string quite a few times it was just a matter of time until I had to come across this issue, where data-binding of such elements would relentlessly uncover my sloppy page-context retrieval
Yes, be very careful with that page context, especially with storing it on model classes. If you really require somewhere, why not "push" to where you want as one of the method parameters. This way, you always have the correct one in hand to use. Instead of storing this as an attribute on a class. The active page_context is a very volatile piece of pointer.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.