cancel
Showing results for 
Search instead for 
Did you mean: 

Same model in different WebDynpro DC's

Former Member
0 Kudos

Hi,

we have imported a function from a legacy application as a model in a WebDynpro DC. This worked fine. Now we decided to split the WebDynpro DC into 4 different DC's (because we want to reuse part of the functionality).

Now we had different options what to do with the model:

-> import the legacy application as a model in every DC. This is no option because the call to the legacy application is very expensive and changes data (possibility of lost update).

-> Creating a fifth DC (which I will call a "model DC") which encapsulated the model. Then we tried to access the data of the model via the Component Interface of the model DC in each of the four other DC's. But there we found out, that for each of the four DC's a model DC instance was created. But we need one model DC instance for all four other DC's.

Is there any possibility to force a DC to be a 'Singleton' or any completley different solution to that problem?

Any help to this topic is appreciated.

Greetings.

Achim

Accepted Solutions (1)

Accepted Solutions (1)

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Achim,

you address a very important issue when developing component-based Web Dynpro applications. I will cover it at SAP TechEd this year (Session ID: CD355 - Web Dynpro Java – Tackling More Advanced Topics - Hands-On Session) more in detail.

It's very important to differentiate between a component usage at designtime and the related component instance at runtime. A component usage can be seen as a variable.

By default the lifecycle property of a component usage is 'createOnDemand' and not 'manual'. When several component usages in separate DCs are referencing the same used model component, the Web Dynpro Runtime will create several different instances of this model component for every component usage. But this is not desired.

Instead you want to create a single instance of this model component in order to inject this single instance to all consuming DCs (consuming Web Dynpro components with a component usage relation to this model component).

<b>Solution:</b>

1.) All consuming Web Dynpro components must declare the lifecycle property of the model component usage as 'manual'

2.) All consuming Web Dynpro components must expose a method setModelComponentInstance(IWDComponentUsage modelComponentUsage) in its component interface controller

3.) Some root component creates the single model component instance (its usage is also defined as 'manual')

4.) The root component injects the created model component instance to all consuming/referencing Web Dynpro components by calling their public setModelComponentInstance(IWDComponentUsage modelComponentUsage) method and passing a reference to its own model component usage.

5.) Enter the model component in referencing mode in all cosuming components: the consuming components must implement the setModelComponentInstance(IWDComponentUsage modelComponentUsage) by adding one single line of code:

wdThis.wdGet<name of model component usage>.enterReferencingMode(modelComponentUsage)

With this pattern you can make sure, that all DCs use/reference the same/singleton model component instance at runtime.

See you next at TechEd in September

Regards, Bertram

Former Member
0 Kudos

Bertram,

1. Why this tricks are necessary? Is there are any noticable overhead of using several instances of model <b>component</b> if there is only one <b>model</b> per application (default settings for Adaptive RFC)?

2. From API docs to

IWDComponentUsage.public void enterReferencingMode(IWDComponentUsage componentUsage)

<i>...Note: Accessing a visual interface via a component usage in referecing mode ist <b>not supported</b>. Reverse context mapping via a component usage in referencing mode is <b>not supported</b>. Nevertheless, the component's visual interface and reverse context mapping can be used by the component usage which refers to the component instnce without being in referencing mode.</i>

First, the latest statement sounds arcane. Second, if referencing mode is soooo limiting, why not to use just regular helper Java class???

VS

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Valery,

<b>Concerning your first question:</b>

only having one model per application at design time (inside your Web Dynpro DC) does not mean, that at runtime only one model instance exists.

As soon as two separate components with a usage to the same model are created at runtime they will operate on two separate model instances. This means when component A executes a model object model A gets populated with a model object graph, whereas the model object graph of component B is still empty. From where should component B should know about model A.

On the one side a model is a disgn time construct on a meta-data level. When two components use the same model this means, that both can "see/use" the contained model classes for declaring their context-to-model-binding relation. At runtime both components will have two separate/individual model object graphs which do not know anything from one another.

<b>Concerning your second question:</b>

I only described the usage of the enterReferencingMode() method in the context of using a singleton model component. This model component is faceless, that means it does not expose a visual interface. I agree with you, that the quoted JavaDoc sentence is not easy to understand.

Regards, Bertram

Answers (3)

Answers (3)

Former Member
0 Kudos

Achim,

What type of model you have created? Is it Adaptive RFC? It is not clear to me after you've provided a stacktrace in your other message -- Adaptive RFC has no such problems.

Now some notes on Adaptive RFC model:

1. Create it in separate DC -- it is a common practice

2. In this dc create public part and add complete model to it

3. Refer this public part from other DCs

<i>But there we found out, that for each of the four DC's a model DC instance was created</i>

What do you mean? Number of model instances does not depends on number of DCs, it depends on model scope: one per application (default), one per task etc.

What behavior are you observing?

VS

Former Member
0 Kudos

Hi Anilkumar,

I tried this but got the following exception:

[code]

com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: failed to create or init instance of model 'net.dsb.zhsgui.model.javabean.ToplevelHilfeDruckerei' in scope APPLICATION_SCOPE with instanceId 'null'

at com.sap.tc.webdynpro.progmodel.model.api.WDModelFactory.getOrCreateModelInstanceFromScopeMaintainer(WDModelFactory.java:340)

at com.sap.tc.webdynpro.progmodel.model.api.WDModelFactory.getModelInstance(WDModelFactory.java:154)

at com.sap.tc.webdynpro.progmodel.model.api.WDModelFactory.getModelInstance(WDModelFactory.java:101)

at net.dsb.zhsgui.prototypes.Testdruck.wdDoInit(Testdruck.java:122)

at net.dsb.zhsgui.prototypes.wdp.InternalTestdruck.wdDoInit(InternalTestdruck.java:244)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent.doInit(DelegatingComponent.java:95)

at com.sap.tc.webdynpro.progmodel.controller.Controller.initController(Controller.java:215)

at com.sap.tc.webdynpro.progmodel.controller.Controller.init(Controller.java:200)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.init(ClientComponent.java:346)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.createComponent(ClientComponent.java:854)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.createComponent(ClientComponent.java:157)

at com.sap.tc.webdynpro.progmodel.components.ComponentUsage.createComponentInternal(ComponentUsage.java:143)

at com.sap.tc.webdynpro.progmodel.components.ComponentUsage.createComponent(ComponentUsage.java:110)

at com.sap.tc.webdynpro.progmodel.components.ComponentUsage.createInstanceIfDemanded(ComponentUsage.java:699)

at com.sap.tc.webdynpro.progmodel.components.ComponentUsage.getImplementingInterfaceViewInfo(ComponentUsage.java:397)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.getViewManagerFor(ClientComponent.java:294)

at com.sap.tc.webdynpro.progmodel.view.ViewManager.createUninitializedView(ViewManager.java:458)

at com.sap.tc.webdynpro.progmodel.view.ViewManager.getView(ViewManager.java:524)

at com.sap.tc.webdynpro.progmodel.view.ViewManager.bindRoot(ViewManager.java:422)

at com.sap.tc.webdynpro.progmodel.view.ViewManager.makeVisible(ViewManager.java:624)

at com.sap.tc.webdynpro.progmodel.view.ViewManager.performNavigation(ViewManager.java:263)

at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.navigate(ClientApplication.java:775)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:359)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:252)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:392)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:266)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:345)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:323)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:865)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:240)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)

at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:159)

Caused by: com.sap.tc.webdynpro.progmodel.model.api.WDModelException: The type of model represented by class 'net.dsb.zhsgui.model.javabean.ToplevelHilfeDruckerei' is not compatible for creation by WDModelFactory!

at com.sap.tc.webdynpro.progmodel.model.api.WDModelFactory.getNewModelInstance(WDModelFactory.java:395)

at com.sap.tc.webdynpro.progmodel.model.api.WDModelFactory.getOrCreateModelInstanceFromScopeMaintainer(WDModelFactory.java:328)

... 44 more

[/code]

The class [code]ToplevelHilfeDruckerei[/code] is known to the component, that can't be the problem.

Do you have any hints for me?

Greetings and thanks for your help!

Achim

Former Member
0 Kudos

Hi Achim,

Please check the following

WDModelFactory.getModelInstance(java.lang.Class modelClazz, WDModelScopeType scope)

" factory method, which returns an instance within the scope of the current thread's application instance representing a specific model type (param modelClazz) If no instance of the Class modelClazz within the given scope exists, a new instance is created and added within the given scope."

Regards, Anilkumar