on 10-03-2008 11:19 AM
Dear Guys,
I have create a dynamic text edit using the following code in abap webdynpro.
I have created a transparent container named PREREPLY set to grid layout and created a context REPLY type string and in WDDOMODIFYVIEW view i have written the following
data : lr_container type ref to cl_wd_uielement_container,
lr_comment type ref to cl_wd_text_edit.
lr_container ?= view->get_element( 'PREREPLY' ).
lr_comment = cl_wd_text_edit=>NEW_TEXT_EDIT( BIND_VALUE = 'REPLY'
COLS = 70
ID = 'PREREPLIES2'
STATE = 01 ).
lr_comment->BIND_VALUE( 'REPLY' ).
cl_wd_grid_data=>new_grid_data( element = lr_comment ).
lr_container->ADD_CHILD( lr_comment ).
i am able to see a new textedit when i run my application.
Now I want to create the context also dynamically, because i will not know how many text edit will be there. Based on the number of lines in the internal table i want the create the context and textedits dynamically.
Give me the code to create context dynamically in abap webdynpro.
Regards,
Shamila
Hi Shamila,
As you said based on number of lines in internal table you have to create context attributes.
To do this first get the internal table data and do in this way...
data:
node_data type ref to if_wd_context_node,
elem_data type ref to if_wd_context_element,
node_info type ref to if_wd_context_node_info,
ls_attr type wdr_context_attribute_info.
navigate from <CONTEXT> to <DATA> via lead selection
node_data = wd_context->get_child_node( 'NODE_NAME' ).
node_info = node_data->get_node_info( ).
loop at it_data into ls_data.
ls_attr-name = ls_data-text.
ls_attr-type_name = STRING.
node_info->add_attribute( attribute_info = ls_attr ).
endloop.
thats all you can see the new attributes attached to the Context node.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shamila,
Please find the below documentation from the web.
Regards,
Uday
Procedure to create context nodes dynamically:
In order to create a new independent context node a reference to the metadata of the context root node has to be obtained first. This reference is obtained by calling the method wd_context->get_node_info( ).
Next, the metadata of the new node has to be defined. To create a new node, the method add_new_child_node( ) from the reference to the context root node can be used. This method hands back the reference to the metadata of the new node. An important parameter of the method add_new_child_node( ) is is_static. Only if this parameter is set to abap_false can the related node can be deleted at runtime.
Procedure for creating context attributes dynamically:
Each attribute of the previously created context node can be defined by calling the method add_attribute( ) from the reference to the metadata of the node.
the method add_attribute( ) has to be called once for each attribute. However, the method add_new_child_node( ) not only allows you to create a context node, but also to create related attributes as follows:
1) An ABAP Dictionary flat structure type (structure, database view or transparent table) can be passed to the method using the parameter static_element_type. All attributes for this structure are created automatically.
2) An RTTI structure descriptor can be passed to the method using the parameter static_element_rtti. The attributes are created accordingly.
3) Finally, a table, with each line containing one attribute description, can be passed to the method using the attribute parameter. Attributes are created accordingly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please check out the WD application for example -
DEMODYNAMIC- For the context node dynamic creation
Also check out this link -
http://help.sap.com/saphelp_nw2004s/helpdata/en/8c/a0fa495f9a480bae29bf43474ccb79/frameset.htm
Regards
Lekha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sharmila,
Just go through this sample code snippet which does the following.
1) It dynamically creates a context node named CHILD and then creates 4 attributes ATTR1, ATTR2,..
2) Creates a GROUP UI element with a caption attached to it
3) Create 4 textEdit UI elements bound to the 4 context attributes created earlier and embed them within the group
METHOD wddomodifyview.
DATA: lr_container TYPE REF TO cl_wd_uielement_container,
lr_group TYPE REF TO cl_wd_group,
lr_caption_group TYPE REF TO cl_wd_caption,
lr_textedit TYPE REF TO cl_wd_text_edit,
lr_node_info TYPE REF TO if_wd_context_node_info,
lr_node TYPE REF TO if_wd_context_node,
lr_element TYPE REF TO if_wd_context_element,
lr_attribute_info TYPE wdr_context_attribute_info,
content TYPE string,
attribute_name TYPE string,
lv_textview_id TYPE string.
CHECK first_time = abap_true.
lr_node_info = wd_context->get_node_info( ).
CALL METHOD lr_node_info->add_new_child_node
EXPORTING
name = 'CHILD'
is_mandatory = abap_false
is_multiple = abap_true
is_multiple_selection = abap_true
is_singleton = abap_false
is_initialize_lead_selection = abap_true
is_static = abap_false
RECEIVING
child_node_info = lr_node_info.
lr_container ?= view->get_root_element( ).
cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).
lr_group = cl_wd_group=>new_group( id = 'GROUP' ).
lr_group->set_width( value = '50%' ).
cl_wd_matrix_layout=>new_matrix_layout( container = lr_group ).
cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_group ).
lr_caption_group = cl_wd_caption=>new_caption( text = 'Group Header' ).
lr_group->set_header( the_header = lr_caption_group ).
DO 4 TIMES.
MOVE sy-index TO attribute_name.
** Preparing the data to be displayed in the textEdit i.e, data for context attribute
CONCATENATE 'This'
'is the'
'data for textEdit number: '
attribute_name INTO content SEPARATED BY cl_abap_char_utilities=>newline.
CONCATENATE 'ATTR'
attribute_name INTO attribute_name.
** Condense the ID to ensure that the format is consistent with SAP standard
CONDENSE attribute_name NO-GAPS.
** Prepare properties of attribute & add to context node CHILD
lr_attribute_info-name = attribute_name.
lr_attribute_info-type_name = 'STRING'.
lr_attribute_info-value_help_mode = '0'.
lr_node_info->add_attribute( EXPORTING attribute_info = lr_attribute_info ).
lr_node = wd_context->get_child_node( name = 'CHILD' ).
lr_element = lr_node->create_element( ).
lr_element->set_attribute( name = attribute_name
value = content ).
lr_node->bind_element( new_item = lr_element
set_initial_elements = abap_false ).
** Compute the attribute path dynamically i.e, like CHILD.ATTR1
CONCATENATE 'CHILD.'
attribute_name INTO attribute_name.
CONDENSE attribute_name NO-GAPS.
lr_textedit = cl_wd_text_edit=>new_text_edit( cols = 10
rows = 5
width = '90%'
bind_value = attribute_name ).
cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_textedit ).
lr_group->add_child( the_child = lr_textedit ).
ENDDO.
lr_container->add_child( the_child = lr_group ).
ENDMETHOD.
Hope that you can manage to go through this & try change it to suit your requirement.
Regards,
Uday
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.