cancel
Showing results for 
Search instead for 
Did you mean: 

Event to populate DropDownByKey

Former Member
0 Kudos

Hi,

I have two Views with one DropDownByKey(DDK) in each one (all in one window).

The idea is that the second DDK (in the second View) is populated depending of the seleccton of first DDK.

How to know in the second View when the first DDK(in the first View) is selected, in order to populate the second DDK?

I have proven populate de second DDK in method wdDoInit of the second View and it does not work.

Regards,

Accepted Solutions (1)

Accepted Solutions (1)

abhijeet_mukkawar
Active Contributor
0 Kudos

hi Alvaro,

Lets say your DDK in view1 is DDK1 and DDK2 is DDK from view2,

Now there are two ways to get what you want,

1: if the context attribute, which you have mapped to DDK2 is in component then map that to view1 too, here, in OnSelect action of DDK1 define an action. In that so that action gets called when you select something in DDK1, write code here to populate the context attribute coming from component to whcih your DDK2 is mapped.

here for populating you will have to use code like as,

IWDNodeInfo nodeInfo = wdContext.node<node name>().getNodeInfo();

IWDAttributeInfo attrInfo = nodeInfo.getAttribute(<context attribute >);

ISimpleTypeModifiable simpType = attrInfo.getModifiableSimpleType();

IModifiableSimpleValueSet valueSet = simpType.getSVServices().getModifiableSimpleValueSet();

valueSet.put(<key of the values to be populated >,<its description> );

.

.

in this way here you can populate the DDK2 in view1 itself,

2:

a)define a method in component controller,

b)declare an event too , in component controller

c)goto View1, in properties tab , under Required controller , define use of component controller(if it is not there) where you have defined a method and an event.

d)goto view2, define an event handler here, in its Event Source give name of your component controller and in Subscribe event give the name of event defined in component contr.(define use of controller here too, in properties tab)

e)in OnSelect action of DDK1(defien one action for this and assign it to OnSelect property), call the method defined in component contr as,

wdThis.wd<component>Controller().<method name>();

in this method of component contr write code,

wdThis.wdFireEvent<event defined in component contr>();

Since this event is subscribed in view2, this event handler will get called, in that event handler write your code of populating DDK2(as mentioned above. e.g. ISimpleTypeModifiable ..etc)

hope it helps

let me know if you face any problem in this

regards

Former Member
0 Kudos

Hi Abhijeet,

Thanks.. now is workinkg!!!!

Best Regards,

Alvaro Vergara

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Assume node of first view DDBK as Node1 and node seocnd view DDBK as Node2

1. create a method in the component controller say, populateDDBKSecond(selectedkey) with string parameter say selectedkey;

2. Write the following code in the method

// first you write the code to get the values for second view DDBK node

// the below code is used the node values in the second view DDBk In general this can be ussed to populate data in DDBK

IWDAttributeInfo atrInfo = wdContext.nodeNode2().getNodeInfo().getAttribute("<attribute to be displayed in the drop down>");

IModifiableSimpleValueSet ValueSet = atrInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

int Nodesize = wdContext.nodeNode2().size();

for(int i = 0; i < wdContext.nodeNode2().size();i++)

{

ValueSet.put(wdContext.nodeNode2().getNode2ElementAt(i).get<key attribute>(), wdContext.nodeNode2().getNode2ElementAt(i).get<value attribute>());

}

3. For both view add component controller as required controller.

4. Create a navigation link between both the views.

5. In the first view define a action say "selected" and associate this with onSelect event of the first view DDBK.

6. In the action selected

// First get the key of the selected value

// Then call the populateDDBKSecond(key) (assuming that this key is required to get values for DDBK of second view)

// fire the outbound plug to second view which you had created using the navigation modeler

// eg wdThis.wdFirePlugToSecondView();

Hope it solves your problem

Former Member
0 Kudos

Hai ,

you have to create context attribute for two ddks in comp comtroller, map the attributes into two views.

in second view method

onPlugFromFirstView(){

firstddkVal=wdContext.currentContextElement.getFirstDDK();

if(firstDDk//check){

//calculate someValue

wdContext.currentContextElement.setSecondDDK(someValue);

}

}

regards,

Naga

luciano_leitedasilva
Contributor
0 Kudos

Hi Alvaro Vergara,

This case is ease to solve. The DDK in the first iview have to send a event to the second iview when the DDK is selected.

At the first DDK, create a action to handle the selection event. This action will fire an event with a selected value as parameter.

WDPortalEventing.fire("urn:com.ddk.event", "EventSelected", value);

The second iview will create a method to handle the event fired at the first view an populate the DDK using the parameter received.

Put this code in the second iview:

method Init:

WDPortalEventing.subscribe("urn:com.ddk.event", "EventSelected", wdThis.wdGetReceiveEventAction());

method ReceiveEventAction:

String valueSelected = event.get("value");

// fill the DDK with this value

Hope this help you!

Regards,

Luciano

Former Member
0 Kudos

Hi Luciano,

Thanks for your answer.. bur where I must create the method ReceiveEventAction? in the view or in Custom Controller?

And what parameters must receive?

Do you have code sample of the method?

Regards

former_member182372
Active Contributor
0 Kudos

Hi Alvaro,

Are views within one WD component?

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Hi Maksim,

Yes, they are in one WD component.

Regards,

former_member182372
Active Contributor
0 Kudos

Hi Alvaro,

1) In component controller of WD component

a) define method selectionChanged with parameter newValue

b) define event selectionChanged with parameter newValue

c) in method selectionChanged fire event and pass method parameter as event parameter

2) In View1 (source):

a) define component controller as Required Controller (tab Properties)

b) create action handler for DDbK for onSelect event

c) in action handler call selectionChanged method from component controller and pass context value bound to DDbK (wdContext.current<NODE_NAME>().get<ATTRIBUTE_NAME>):


wdThis.wdGet<Component>Controller().selectionChanged(wdContext.current<NODE_NAME>().get<ATTRIBUTE_NAME>));

3) In View2 (destination):

a) define component controller as Required Controller (tab Properties)

b) In Methods tab create event handler for event selectionChanged from component controller. Don`t uncheck checkbox for parameters.

c) In action handler for event define logic to relaod value set for second DDbK.

Bes tregards, Maksim Rashchysnki.

Former Member
0 Kudos

Hi Alvaro,

You can create and Action and assign it to the first DDK's 'onSelect' event. So in tht action you can write the code to fill the second DDK.

I hope you would need to assign the second DDKs context to controller and tht one to first iview context so that in the aciton of DDKs event u can fill that context which eventually fill the second DDK in the other view.

Thanks,

Raags

saraswathi_d
Participant
0 Kudos

Hi,

Use the view set

public void onActionSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

wdThis.wdFirePlugToSecondView();

}

Regards,

Saraswathi