cancel
Showing results for 
Search instead for 
Did you mean: 

Different actions based on different drop down selection

Former Member
0 Kudos

Hi,

I am new to WebDynpro so still getting to used to the differences with what I am used to. My question is this:

Is it possible to create a drop down list (by key) in a top view that allows the user to display one of three views in the bottom view? I know it is possible if I add a button, but I want it to look like one form so that the user is unaware of the difference. The "logical" way to me would be to have an action created for each option in the drop down list, but this does not seem possible. Any suggestions on how I could do this?

Thanks,

Helen

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

As already explained by other posters, this is possible:

Define an action with a parameter "selectedKey" of type string.

Bind the DropDownByKey.onSelect event to this action.

Map the event parameter "key" to the action parameter "selectedKey" by writing this line of code inside method wdDoModifyView():

if (firstTime)
{
  IWDDropDownByKey dd = (IWDDropDownByKey) view.getElement("<ID of your drop-down>");
  dd.mappingOfOnSelect().addSourceMapping
  (
    "key", /* event parameter name, see JavaDoc */
    "selectedKey" /* action parameter name */
  );
}

The effect of this mapping is that at runtime, the action handler parameter "selectedKey" contains the key that has been selected from the drop-down list.

In the action handler, you can navigate to the view that corresponds to the selected key by calling the outbound-plug to this view. These firePlug* methods will be generated by the framework, if you have defined the corresponding navigation links in the view modeller.

But: I would not use at all a drop-down list to switch views because this will not match most user's expectation. Links are more appropriate to indicate navigation to other views.

Armin

Former Member
0 Kudos

Hi Armin

Please excuse my non-Web Dynpro language in advance.

I have decided to use the drop down value in the bottom view to set the visibility of the various views. I have added code to try to set this, and it works to a point - it shows one view at a time as required. However, the problem I am having is that the selected value is not being assigned to my variable and because the value is null, it is dropping through to the last else statement. I am still learning Java (converting from C) so some concepts are still strange.

My code is this:

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

{

//@@begin onPlugFromTop(ServerEvent)

String VowelSelect = wdContext.currentContextElement ().getHoldVowels();

if (VowelSelect == "A"){

>code<

}else if (VowelSelect == "E"){

>code<

}else {

>code<

}

//@@end

}

Any help would be appreciated.

Also with regards to the choice of drop down vs links or buttons, the form will contain the drop down and based on the user selection, will then bring up the "rest" of the form. The use of links or buttons will make it obvious that it is seperate forms, which is not what I want. I have seen this format used in a few corporate webpages, but not sure how to do it myself using web dynpro.

Regards, Helen

Former Member
0 Kudos

In Java, you must compare strings (in general) using equals() not with the "==" operator. The first argument has to be non-NULL else you get a NullPointerException.

Variable names usually are written in lower(Camel)Case in Java.

So change your code to

 
String selectedVowel = wdContext.currentContextElement ().getHoldVowels();
if ("A".equals(selectedVowel))
{
>code<
}
else if ("E".equals(selectedVowel))
{
>code<
}
else
{
>code<
}

Armin

Former Member
0 Kudos

Thanks very much - this has solved my problem.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Helen,

Its not possible to assign different event handlers for a select option in drop down.. What we can do is.. we can pass parameter which stores the value of the selected key in the drop down and then by checking what the selected value is you can decide your action.. or firing a plug or changing the visibilty of elements.. etc.,

To pass a value you on action you can use

<dropdownobj>.mappingofonAction().addParameter("selected",get the selected value and put it here);

Create a parameter in the event handler with the name selected of type string and check it value..

Regards

Bharathwaj

Former Member
0 Kudos

Hi Helen,

For displaying in the bottom view,u can use the

onselect() option in the onAction property of the drop

down UI element.Inside the onselect() u have to fireplug

to the next view that u want in the bottom.

onselect()

{

wdThis.wdFirePlugTobottomView();

}

u should create a viewset with two rows having ur

dropdown box view in the top and the result display in

the bottom view.

create an outbound plug for the top view and an

inboundplug in the bottom view and give datalink to it.

I hope this solves ur query.

Regards,

Nagarajan.

Former Member
0 Kudos

You create an Action to be called with "onSelect" of dropdown.

You can write your logic to add the values required for second dropdown in this Action method.

You are not required to do anything else.

Former Member
0 Kudos

hi helen,

what you can do is bind the onSelect property of the drop down to some method, inside this method write the code which helps you to check which element is selected,

if you are using dropdownbyindex , then you should add a parameter(of type the String ) inside your onSelect method while you create you method.

now in the doModify do the appropriate mapping .so after the selection you'll get the selected value in the parameter that you added in the method.

regards,

rahul