on 10-24-2006 10:54 AM
Hi
I wish to add various elements to a tabstrip at runtime. The elements on tab one are created at design time to show the structure to other developers but since the same structure will be repeated on a further 11 tabs, I wanted to create the remaining elements dynamically.
However, whenever I try to attach any element to another element and not to the ROOTUIELEMENTCONTAINER, I get a runtime error.
Can I only create a pointer to the ROOTUIELEMENTCONTAINER and attach directly to this?
Any help greatly appreciated
Cheers
Ian
Read the Weblogs by Thomas Szuecs about using the UI element API.
See /people/thomas.szcs/blog/2006/01/03/dynamic-programming-in-web-dynpro-abap--part-ii-handling-viewelements
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amin
Thanks for the speedy reply.
I have read all three of Thomas' excellent weblogs. I guess it's just not sinking in at present. All the references/examples I have seen - including in the new WDA SAP Press book create the elements directly from the root element. What Iif I already have elements present and do not want them to be created immediately after but at a specific point in the hierarchy i.e. on my tab strip?
I am thinking of getting a table of the children of the root and then navigating to the point at which I want to create another reference. Do you think this would be possible?
Cheers
Ian
I can only talk for WD Java but WD ABAP should work similarly.
You can access any view element directly by its ID. Say, you have created a tabstrip with ID "TabStrip" at design time, then you can access it from method wdDoModifyView() like
IWDTabStrip tabstrip = (IWDTabStrip) view.getElement("TabStrip");
and then use the UI element API to add tabs, change tab contents etc.
Armin
Hi Armin
Certainly. Thanks for your continued help.
Basically, I have a tabstrip containing 12 tabs. These are to contain data for 12 weeks.
On each tab there are 8 columns - 1 headings column on the left and 7 colums for the seven days in the week.
On each 'day' column, there are 8 fields relating to start time/end time work data.
Suffice to say, there are a lot of fields so I thought it would be a good idea to generate most programmatically because of the high degree of repetition.
My issue is that I am trying to create a transparent container below TAB2 which will then itself contain various elements.
This is bascially what I am trying:
DATA: lr_tab TYPE REF TO cl_wd_tab,
lr_tco_tab TYPE REF TO cl_wd_uielement,
lr_matrix_data TYPE REF TO cl_wd_matrix_data.
lr_tab ?= view->get_element( 'TAB1' ).
lr_tco_tab = cl_wd_transparent_container=>new_transparent_container( id = 'TCO_TAB1' ).
cl_wd_matrix_data=>new_matrix_data( element = lr_tco_tab ).
lr_tab->set_content( lr_tco_tab ).
I'm always getting an error relating to a NULL object reference.
I have tried using the cl_wd_uielement class as the lr_tab type ref but it doesn;t like this, hence the cl_wd_tab ref instead.
Ian
Hi Ian,
1) You need to get familiar with the way tabstrips are build with tabs. In your coding you only use tabs. In that way it won't work.
2) You try to create a transparent-container-ui-element object and add this as TAB to a tab object. This is not going to work either.
Here is my suggestion to the way you want to add tabs dynamically. However, I'm not sure, whether the view-element IDs fit to the ones you use in your app, so please adjust:
DATA: lr_tabstrip TYPE REF TO cl_wd_tabstrip,
lr_tab TYPE REF TO cl_wd_tab,
lr_matrix_data TYPE REF TO cl_wd_matrix_data,
lr_content TYPE REF TO cl_wd_uielement,
lv_container_name TYPE string,
lv_id type string.
lr_tabstrip ?= view->get_element( 'TAB1' ).
lr_tab = cl_wd_tab=>new_tab( id = lv_id
view = view ).
lr_content = cl_wd_view_container_uielement=>new_view_container_uielement(
id = lv_container_name
view = view ).
*---- add your ui elements to the container
lr_tab->set_content( lr_content ).
lr_tabstrip->add_tab( lr_tab ).
I hope this gives you an idea, how it might work.
regards, Ulli
Hi Ulli
I already have a tabstrip 'TBS_WEEKS'. TAB3 is a tab object beneath this. both have been created at design time.
What I wish to do from here is get a reference to TAB3 and then add a transparent container to it (for a start).
I have adapted your code and the lr_content does get added to lr_tab successfully. Why did you not declare lr_content as cl_wd_transparent_container though?
Regards
Ian
Hi Ian,
sorry I missed that part. So, it seems you've got everything right. It doesn't matter whether to use a transparent container or a viewuielementcontainer.
The coding I've provided, should work with a transparent container as well. The cause of the error you get is probably that you try to add it as new_matrix_data, which is not possible inside of a tab.
regards, Ulli
Sorted!
It appears that whenever I create a transparent container, I have to specify the layout type (grid/flow) and if I have a transparent container within another transparent container I also need to specify the layout data.
I guess I missed the importance of these two properties. Also ensure that they are compatible layouts/data.
See the following code for my example:
DATA: lr_container TYPE REF TO cl_wd_transparent_container,
lr_grp_day TYPE REF TO cl_wd_group,
lr_input_field TYPE REF TO cl_wd_input_field,
lr_tab TYPE REF TO cl_wd_tab,
lr_tco_tab TYPE REF TO cl_wd_transparent_container,
lr_tco_headings TYPE REF TO cl_wd_transparent_container,
lr_content TYPE REF TO cl_wd_uielement,
lr_grid_layout TYPE REF TO cl_wd_grid_layout,
lr_caption TYPE REF TO cl_wd_caption,
lr_contract_hrs_label TYPE REF TO cl_wd_label,
lr_contract_hrs_input TYPE REF TO cl_wd_input_field.
DATA: lv_tab TYPE string,
lv_tco_tab TYPE string,
lv_tco_headings TYPE string.
lv_tab = 'TAB1'.
lv_tco_tab = 'TCO_'.
lv_tco_headings = 'TCO_HEADINGS_'.
CONCATENATE lv_tco_tab lv_tab INTO lv_tco_tab.
CONDENSE lv_tco_tab.
CONCATENATE lv_tco_headings lv_tab INTO lv_tco_headings.
CONDENSE lv_tco_headings.
First pointer to TAB object
lr_tab ?= view->get_element( lv_tab ).
Update the tab header
lr_caption = cl_wd_caption=>new_caption( text = 'Week 1' ).
lr_tab->set_header( lr_caption ).
Add a transparent container to the tab
lr_tco_tab = cl_wd_transparent_container=>new_transparent_container( id = lv_tco_tab
view = view ).
cl_wd_grid_layout=>new_grid_layout( container = lr_tco_tab ).
lr_tab->set_content( lr_tco_tab ).
Get a new pointer to the transparent container
lr_container ?= view->get_element( lv_tco_tab ).
Add another transparent container - this time with a flow layour
lr_tco_headings = cl_wd_transparent_container=>new_transparent_container( id = lv_tco_headings
view = view ).
cl_wd_flow_layout=>new_flow_layout( container = lr_tco_headings ).
cl_wd_grid_data=>new_grid_data( element = lr_tco_headings ).
lr_container->add_child( lr_tco_headings ).
Switch the pointer to the new transparent container
lr_container ?= view->get_element( lv_tco_headings ).
Create an input field
lr_contract_hrs_input = cl_wd_input_field=>new_input_field( id = 'INP_CONTRACT_HRS'
length = 8
bind_value = 'PERSON.PERNR' ).
cl_wd_flow_data=>new_flow_data( element = lr_contract_hrs_input ).
Create a label for the input field
lr_contract_hrs_label = cl_wd_label=>new_label( id = 'LBL_CONTRACT_HRS' text = 'Contract Hours:' ).
cl_wd_flow_data=>new_flow_data( element = lr_contract_hrs_label ).
Add the input field and the label to the transparent container
lr_container->add_child( lr_contract_hrs_label ).
lr_container->add_child( lr_contract_hrs_input ).
Set the label for property
lr_contract_hrs_label->set_label_for( 'INP_CONTRACT_HRS' ).
Cheers
Ian
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
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.