cancel
Showing results for 
Search instead for 
Did you mean: 

how to map single context value attribute to multiple value attributes?

Former Member
0 Kudos

Hello,

is there any way to map a single value attribute

from view's context into several value attributes

in controller's context?

The business context of what I want to achieve

is the following: I have a view which can be called

in two modes: read only (RO) and read-write (RW).

The input parameters to the view are the same for

both modes, however when in RO mode, the view calls

a different set of web services than when called

in RW mode. Before calling each of the web services

I need to populate their context value attributes

with appropriate input values.

I know I can do it in Java code, but is it possible

to do it without any programming (doing it in the

source code is prone to errors)?

Any help highly appreciated.

Greetings,

Tomek.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello,

Actually <b>you have to code it for yourself</b>, but it is not much coding and it would be not prone to errors, because of the simplicity of the tehnique.

I assume that you have 4 data structures (kept in context in value nodes) that are exactly the same. One for each WS (get, create, update) and one in which you have the data you actually work on. So, you would only have to use the .bind() method of proper context nodes to have the same data in different contexts.

for example:

x = wdContext.currentWebServiceElement();

wdContext.nodeWork.bind(x.modelObject());

and this way, the same data object would be bound to different "root" context nodes without populating. Of course, you have to create the context nodes with structure binding for BAPI/RFC connections, or edit the context with copy/paste for WebService to be sure that .bind() method accepting proper arguments will be created.

I hope my suggestions are useful to you.

Regards,

Marcin

Former Member
0 Kudos

Hi Marcin,

I am new to SAP/Dynpro, so sorry for asking the

very basic questions...

1. Do I understand correctly that the bind() method

allows me to map the whole subtrees (value nodes)

between the view's context and the controller's

context?

2. Does it mean that if the mapped structures are

exactly the same, then with a single call to bind()

I can map multiple value nodes?

If I understood you correctly and the above is true,

this would be a great solution provided that the

mapped data structures are exactly the same.

In my case this is not true (the parameters the

web services need are the same, but they are placed

in slightly different structures). The web services

provider (unfortunately) designed it this way, and

I can't change it. (WS are implemented in .NET)

In this case it seems that all I can do is to map

the value nodes one-by-one (which is a bad technique,

but I don't see any other way).

Just one more question... Am I correct that the

mapping between the view's context and the controller's

context should be done in the view's implementation?

If so, in which method of the view should I place

the mapping?

Many, many thanks for your help.

Greetings,

Tomek.

Former Member
0 Kudos

Hello,

1. No. The bind() method is used to bind a data object (an IWDNodeElement or a typed data object relevant to a Model) to a node. Mapping between View and Controller should be done rather in the graphical editor. The basic idea is you should have all the data in the controller, and only map the parts of the Controller's Context you need to the View.

2. If the Context structures are based on the same data structure or on the same object you can use the .bind() method to bind the same data to different Context nodes.

3. You understood me correctly

4. The Last question :

Mapping of View and Controller's context is done in the components diagram view. Look at some basic WD tutorials to get the idea.

To do some advanced context populating in Java, like the one you will need for your case, the best way is to develop proper methods in the controller and call them when you need from EventHandlers or onPlug... methods in the View or in the Controller.

In your case i would suggest creating one Context structure for the internal data storage and for View mapping, and then using your own Java methods (like populateFromGet, populateIntoCreate, populateIntoUpdate in your case) to transfer data from/to WebServices model nodes.

--

regards

Marcin

Former Member
0 Kudos

Hi Tomasz

If i understand you correctly you want to map a single context attribute to muliple context attributes. You can't do that in Webdynpro.

Coming to your scenario, if you want to toggle your view between read only and read write, then you can create

a value attribute of type boolean and map this value attribute to the read only property of all your UI elements. Now set the value of this property as per your requirement.

Let me know if you require furthur clarifications.

Kishore

Former Member
0 Kudos

Hi Kishore,

than you very much for your kind help.

I have already created a value attribute of type

boolean and mapped it into the read-only property

of the UI elements. This however does not solve all

of the problems... I will describe it with an

example:

Let's say the form I want to implement will be

used to: create (read-write mode), update (read-

write mode) or show (read-only mode) customer's

data. The customer's data is complex (lots of

data, including tree structures).

The problem is that:

- when the form is called in read-only mode,

it should populate its fields with values

provided by the getCustomerData web service,

- when the form is called to create a new

customer (in read-write) mode, it should

not use the getCustomerData web service.

Instead it should map the input values

entered by the user into input parameters

of the createNewCustomer web service,

- when the form is called to update customer's

data, it should first display values returned

by the getCustomerData web service, and then

it should map the modified values entered by

the user into input parameters of the

updateCustomer web service,

In all the above cases I must map my view's

context data to different controller's context

elements. Doing it directly in the source code

is not a nice solution. Is there any other

way to achieve this?

Calling a form in different modes in not an

unusual thing, so I was hoping that maybe

there are any built-in mechanisms that would

solve the obove problem...

Greetings,

Tomek.