on 07-01-2008 1:27 PM
Hi,
My current requirement is to create dynamically context attributes. I used the followings :
DATA: ls_attribute TYPE wdr_context_attribute_info.
ls_attribute-name = 'ATTR_1' .
ls_attribute-default_value = ''.
ls_attribute-type_name = 'STRING'.
node_info->add_attribute( EXPORTING attribute_info = ls_attribute ).
And it works fine. But I also need to create a Ref To type dynamic attribute as reference to a class object and nothing seems to work. Any suggestions ?
Thank you in advance,
Horea.
Hello,
Please see these: [https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/web%2bdynpro%2bfor%2babap%2b-%2bcustomize%2bmandatory%2batttributes%2bmessages], and .
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>
> Hi,
>
> My current requirement is to create dynamically context attributes. I used the followings :
>
> And it works fine. But I also need to create a Ref To type dynamic attribute as reference to a class object and nothing seems to work. Any suggestions ?
>
> Thank you in advance,
> Horea.
I don't believe that this possible. You can't be object references into the context. Normally you would store object references as attributes of the Controller.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>
> Hi Thomas,
>
> Previously I have declared several context node attributes as Type Ref to CL_* during design time and it works fine.
>
> Regards,
> Horea.
I stand corrected. Pretty sure in older SPs you couldn't do that, but my bad for not checking before posting.
Still not sure that this works with the ADD_ATTRIBUTE method. I tried the following:
DATA: ls_attribute TYPE wdr_context_attribute_info.
ls_attribute-name = 'ATTR_1' .
ls_attribute-default_value = ''.
ls_attribute-type_name = ''.
data o_test type ref to ZCL_SFLIGHT_MODEL.
create object o_test.
ls_attribute-rtti ?= cl_abap_typedescr=>DESCRIBE_BY_OBJECT_REF( o_test ).
node_info->add_attribute( EXPORTING attribute_info = ls_attribute ).
The problem is that you end up with an invalid type cast. It appears that the ADD_ATTRIBUTE RTTI is actually looking for a CL_ABAP_DATADESCR (see DDic definition of WDR_CONTEXT_ATTRIBUTE_INFO) and what you end up with when you pass in an object reference is CL_ABAP_CLASSDESCR.
Hi,
I couldn't agree more, I tried this also . In the WDR_CONTEXT_ATTRIBUTE_INFO DDic definition the RTTI component type is CL_ABAP_DATADESCR, even though in the DESCRIBE_BY_OBJECT_REF method of the CL_ABAP_TYPEDESCR class the returning parameter type is CL_ABAP_TYPEDESCR not CL_ABAP_CLASSDESCR.
Regards.
>
> Hi,
>
> I couldn't agree more, I tried this also . In the WDR_CONTEXT_ATTRIBUTE_INFO DDic definition the RTTI component type is CL_ABAP_DATADESCR, even though in the DESCRIBE_BY_OBJECT_REF method of the CL_ABAP_TYPEDESCR class the returning parameter type is CL_ABAP_TYPEDESCR not CL_ABAP_CLASSDESCR.
>
>
> Regards.
DESCRIBE_BY_OBJECT_REF does declare the exporting parameter as CL_ABAP_TYPEDESCR but that is slightly misleading. Look up CL_ABAP_TYPEDESCR in the class builder. It is Abstract. That means that at runtime one of the Instance Subclasses will actually be returned. This way the method can be designed generically but at runtime supply the specific object. The two subclasses are CL_ABAP_DATADESCR and CL_ABAP_CLASSDESCR. A TYPEDESCR must actually be one or the other of these more specific class types. If you have a class based object reference it will always generate an RITT of CL_ABAP_CLASSDESCR yet the description of
WDR_CONTEXT_ATTRIBUTE_INFO clearly wants an CL_ABAP_DATADESCR .
Now in theory if the method ADD_ATTRIBUTE supported both data objects and class objects, the RTTI field in WDR_CONTEXT_ATTRIBUTE_INFO should have been declared as CL_ABAP_TYPEDESCR . That way it would have accepted either subclass at runtime. However looking at the coding of ADD_ATTRIBUTE it doesn't seem to have a logic path to handle RTTIs based upon CL_ABAP_CLASSDESCR.
Hi,
The original requirements were that I create dynamically context node with its attributes, and one if its attributes must be of Type Ref To ZCL_CLASS where I always store an object. So for each element of the context node there should be a different object stored in that attribute.
Regards,
Horea.
Yes but what purpose does ZCL_CLASS serve and why put it in the context? You could just as easily keep an internal table full of object references in the controller attributes. Was there some data in the attributes of ZCL_CLASS that you were going to access? Is this what you were going to bind UI elements to? Why not just loop through your object references and add the actual data object of the class attributes to the context instead?
Hi,
I think I was too cheap in words. I have a table and the user adds dynamically columns to the table depending on another table selection. And for each column I also create dynamically a context node and the needed attributes according to the needed table cell editor, also for each column I need an attribute that stores an object ( its configuration object ). I will try to build a component table of objects and see if it works.
Thanks,
Horea.
Hi David,
Thanks for the hints. I don't think that using data descriptors would help me because I don't want to create the attributes from internal tables or DDIC. The only thing I want to do is change the type assignment for the attribute to Ref To. Is RTTI the only way?
Regards,
Horea.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
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.