cancel
Showing results for 
Search instead for 
Did you mean: 

Component Usage (Urgent)

Former Member
0 Kudos

Hi All,

Can a view ui container contain more than one component instance. If so at runtime can i choose any one of the instance and create the component and display it.

Mahesh

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

Hi Mahesh,

Regarding your question:

> Hi Maksim,

> Thanks for that project. I need some clarification

> regarding the Webdynpro Component Interface which u

> have created in the project ---> ViewContainerChild.

> What is it and the uses of it. If ther is any other

> examples or tutorials, please send in.

> Mahesh

Unfortunately I don`t know any tutorials or examples about how to use Web Dynpro Component Interfaces but I will try to explain the main idea behind: Web Dynpro Component Interface is very similar to plain Java interface - you describe some methods and after in your you class you must implement them.

So, you can create Web Dynpro Component Interface, describe context structure, methods, events for component interface controller, create one or more Interface View Definitions and used models. Afterwards in your Web Dynpro Component you declare new created Web Dynpro Component Interface as Implemented Interface and all metadata is copied (Interface Views, Used Models, etc.) and you have to implement methods, event handlers and so on.

In my example I use Web Dynpro Component Interface in Main component as Used Web Dynpro Component and embedd Interface View Definition to ViewContainerUIElement. But exact implementation you will specify on run-time using code:


final String componentName = "com.sap.sdn.child.child1.Child1";//full name of component including package

final IWDComponentUsage usage = wdThis.wdGetViewChildComponentUsage(); 

if (usage.hasActiveComponent() && !componentName.equals( usage.getComponentUsageInfo().getName()) ) {
	usage.deleteComponent();
}

if (!usage.hasActiveComponent()) { 
	try{   
		usage.createComponent(componentName);
	} catch(WDRuntimeException e) {
		wdComponentAPI.getMessageManager().reportException(new WDNonFatalException(e), false);
	}
} 

I hope now it is clear.

Best regards, Maksim Rashchynski.

Answers (2)

Answers (2)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You didn't say if you were working in Web Dynpro Java or Web Dynpro ABAP. However if you are working Web Dynpro ABAP there is a very nice dynamic Navigation API that also allows you to choose a targert embedding position. This allows you to do dynamic component instances like you are describing. I don't know if a similar API is available in Java Web Dynpro or not. Here is the API call in ABAP:

l_api_main = wd_this->wd_get_api( ).
try.
  l_api_main->do_dynamic_navigation(
     source_window_name  = 'MAIN'
     source_vusage_name  = 'MAIN_VIEW_USAGE_1'
     source_plug_name    = source_plug_name
     target_component_name = target_component_name
     target_view_name      = target_view_name
     target_plug_name      = 'DEFAULT'
     target_embedding_position = 'MAIN_VIEW/VIEW_CONTAINER'.
  catch cx_wd_runtime_repository.
endtry.

Although the API method needs the name of source plug, this doesn't have to be defined at designtime. It just needs you to provide a unique name.

Former Member
0 Kudos

Hi Thomas,

I am attempting to use the method DO_DYNAMIC_NAVIGATION but I get the following error message when I syntax check my application:

Method is unknown, protected or private.

I have also noticed that the interface status is set to 'Not Supported (Set by Developer)'. Is this the issue?

Your help is greatly appreciated.

Kind regards

Matt.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

What Support Package Level are you? I am calling this code from my View, so the WD_THIS is my view interface. The get_api call returns a reference that uses interface if_wd_view_controller. What interface do you have that is set to Not Supported?

Former Member
0 Kudos

Hi Thomas,

Thanks for the quick response:

I am following your eClass on Dynamic Navigation and have corrected this error. Currently your code will noy syntax check. The error is:

Names like "NAME()" or "NAME+", as in "WD_THIS->WD_GET_API()", are identical to "NAME". These are no longer allowed in Release 4.0.

If I select the package SWDP_RUNTIME_REPOSITORY of The Interface IF_WD_NAVIGATION_SERVICES, and select the Package Interface SWDP_RUNTIME_REPOSITORY; selecting visible elements 'IF_WD_NAVIGATION_SERVICES' shows the release status of 'Not Supported'.

method ONACTIONNAVIGATION .

data:

Elem_Context type ref to

If_Wd_Context_Element,

Stru_Context type

If_V_Main=>Element_Context ,

Item_FUNCTION like

Stru_Context-FUNCTION.

  • get element via lead selection

Elem_Context = wd_Context->get_Element( ).

  • get single attribute

Elem_Context->get_Attribute(

exporting

Name = `FUNCTION`

importing

Value = Item_Function ).

case Item_Function.

when '1'.

when '2'.

when '3'.

when others.

endcase.

data: l_api_main type ref to if_wd_view_controller.

l_api_main = wd_this->wd_get_api().

*

DATA SOURCE_VUSAGE_NAME TYPE STRING.

DATA SOURCE_PLUG_NAME TYPE STRING.

DATA TARGET_VIEW_NAME TYPE STRING.

DATA TARGET_PLUG_NAME TYPE STRING.

DATA COMPONENT_USAGE type ref to cl_wdr_component_usage.

*TRY.

CALL METHOD l_api_main->DO_DYNAMIC_NAVIGATION

EXPORTING

SOURCE_WINDOW_NAME = 'V_EMPTY1'

SOURCE_VUSAGE_NAME = SOURCE_VUSAGE_NAME

SOURCE_PLUG_NAME = SOURCE_PLUG_NAME

  • PLUG_PARAMETERS =

  • TARGET_COMPONENT_NAME =

  • TARGET_COMPONENT_USAGE =

TARGET_VIEW_NAME = TARGET_VIEW_NAME

TARGET_PLUG_NAME = TARGET_PLUG_NAME

  • TARGET_EMBEDDING_POSITION =

RECEIVING

COMPONENT_USAGE = COMPONENT_USAGE.

.

  • CATCH CX_WD_RUNTIME_REPOSITORY .

*ENDTRY.

endmethod.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

The not Support is coming from the status of the package interface. This has to do with the use of the interface outside the package. This means that you can't use this interface within your own class. It has nothing to do with its use as part of the view_controller or the syntax error you are getting.

I believe your syntax error is do to the method call WD_GET_API

You have:

WD_THIS->WD_GET_API()

It should be:

WD_THIS->WD_GET_API( )

The space in the ( ) is very important.

Former Member
0 Kudos

Thanks Thomas,

All is fixed now.

former_member182372
Active Contributor
0 Kudos

Hi Mahesh,

Send my mail to rastchinskym At mail DOT ru and I will reply with example which is doing exactly what you need because it is too long to describe step by step what you need to do.

Best regards, Maksim Rashchynski.