cancel
Showing results for 
Search instead for 
Did you mean: 

Add values to DropDown a runtime

Former Member
0 Kudos
141

Hello,

I am on EP7.0 ERP05 and NW04s and trying to modify ESS applications ,I have a requirement wherein I want to add a dropdown on a screen and add values onto it at runtime like years 2003....2007 and the last value should always be the current year .....how can I do this inside the wdDoModifyView() method ...?

Any help would ne highly appreciated.

Accepted Solutions (0)

Answers (8)

Answers (8)

Former Member
0 Kudos

Hello Sriram,

I am getting values 2002....2007 from a context attribute of type -- in Dictionaries -->Simple Types and defined values in the enumeration like 2000....2006

what I actually want is to create a list of years with last value being the Current Year -1 (eg for 2007 last value should be 2006) and when 2008 starts last value should change to 2007.

Please help.

Message was edited by:

SubhashTripathi

Former Member
0 Kudos

Hi,

If you get the value from simple type will it not be kind of hardcoded.

In future if you want to add next year you have to add that year in the enumeration and re-deploy the application.

Instead you can get the data from backend or some other means where in you dont need to touch the application.

In any case it should not matter as long as data is populated in the context attribute mapped to the dropdown.

Create a context attribute of type <your simple type> and map it to the texts property of the DropDownByIndex.

Just try the code and let me know.

And also for setting the dropdown to previous year code as below

wdContext.currentYearValuesElement.setyear(CurrYear-1);

Former Member
0 Kudos

Hello Arun,

Thanks for the reply. I tried your code but when I try to bind it with the the attribute val4 it says "val4" cannot be resolved...

Looking forward to your reply.

arun_srinivasan
Contributor
0 Kudos

hi

I need some clarifications are you creating val4 dynamically or using the existing on create in context during design time

Check whether you are any other val4 before by either dynamically or during design time

Previous post code work for me

if for face the error still please post your init and domodify code and also let me know what are value attribute you created indesign time in context

Thanks and Regards,

Arun

arun_srinivasan
Contributor
0 Kudos

Hi

Code for filling the values for dropdown

public void wdDoInit()

{

//@@begin wdDoInit()

// Creation of Value attribute and Simple data type(Dynamic Metadata) and populating values

IWDAttributeInfo info11=wdContext.getNodeInfo().addAttribute("val4","ddic:com.sap.dictionary.string");

IWDAttributeInfo inf0111=wdContext.getNodeInfo().getAttribute("val4");

ISimpleTypeModifiable modifiable11=inf0111.getModifiableSimpleType();

IModifiableSimpleValueSet valueset11=modifiable11.getSVServices().getModifiableSimpleValueSet();

valueset11.put("2007","2007");

valueset11.put("2006","2006");

valueset11.put("2005","2005");

// Filling the existing value attribute v of the type string

IWDAttributeInfo inf022=wdContext.getNodeInfo().getAttribute("v");

ISimpleTypeModifiable modifiable22=inf022.getModifiableSimpleType();

IModifiableSimpleValueSet valueset22=modifiable22.getSVServices().getModifiableSimpleValueSet();

valueset22.put("2004","2004");

valueset22.put("2003","2003");

valueset22.put("2002","2002");

//@@end

}

public static void wdDoModifyView(IPrivateDynamicProgrammingView wdThis, IPrivateDynamicProgrammingView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

if(firstTime){

IWDTransparentContainer con=(IWDTransparentContainer)view.getElement("RootUIElementContainer");

//creation of dropdownBykey and binding it to dynamically created metadata

IWDDropDownByKey Dropdownkey1=(IWDDropDownByKey)view.createElement(IWDDropDownByKey.class,"dropdownbykey11");

Dropdownkey1.bindSelectedKey("val4");

con.addChild(Dropdownkey1);

//creation of dropdownBykey and binding it to dynamically created metadata

IWDDropDownByKey Dropdownkey2=(IWDDropDownByKey)view.createElement(IWDDropDownByKey.class,"dropdownbykey11");

Dropdownkey2.bindSelectedKey("v");

con.addChild(Dropdownkey2);

}

//@@end

}

Hope this helps,

Regards,

Arun

Former Member
0 Kudos

Ashwani,

I had gone through he tutorial and i explains to create a Dropdown dynamically bu does not tell how to add values onto it ...Please bear with me..

Please help.,

Former Member
0 Kudos

Hi,

Create a context For example

Node ---> Filter

Atrr --> FilterValue

with cardinality 1..n or 0..n

IFilterElement filterElement = null;

filterElement = wdContext.nodeFilter().createAndAddFilterElement();

filterElement.setFilterValue("AAA");

filterElement = wdContext.nodeFilter().createAndAddFilterElement();

filterElement.setFilterValue("BBB");

above code will create two elements, you can add this code in wdDoInit.

bind the context to texts of drop down

Regards

Ayyapparaj

Former Member
0 Kudos

Hello Sriram,

Thanks for the reply. But what I want to do is to create a list of year values like 2002....2007 and populate onto the DropDown box at runtime in the wdDoModifyView() method .... the method which you are saying ,won't it overwrite the context values each time rather than creating a list..

Looking forward to your reply.

former_member186016
Active Contributor
0 Kudos

Hi Subhas,

In the tutorial i mentioned earlier you have the drop down created exactly as you want.

Please check it.

Regards,

Ashwani Kr Sharma

Former Member
0 Kudos

Hi,

The method does not over write the context values as the boolean parameter firstTime allows execeution of the code inside

if(firstTime){} only once in the lifetime of the view for that particular session.

By the way, from where are you getting the values(2002......2007) ?

Are you generating a list in your code at runtime or getting the values from backend ?

Former Member
0 Kudos

Hi,

Assume context structure and you want to display Name in the DropDown. Since the dropdown will be created dynamically we will map the context attribute to the dropdown during runtime.

Context

+YearValues (node)

--year (attribute of type Integer)

public static void wdDoModifyView(IPrivateTable_Sample_CompView wdThis, IPrivateTable_Sample_CompView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

if(firstTime)

{

// create a DropDown

IWDDropDownByIndex downByIndex = (IWDDropDownByIndex)view.createElement(IWDDropDownByIndex.class,"DD_Year");

// Get the info of the context attribute to be binded to DropDown

IWDAttributeInfo attributeInfo = wdContext.nodeEmpDetails().getNodeInfo().getAttribute(I<your view>View.IYeraValuesElement.YEAR);

// binding the DropDown to context attribute

downByIndex.bindTexts(attributeInfo);

// adding the DropDown to the root container

IWDTransparentContainer container = (IWDTransparentContainer)view.getRootElement();

container.addChild(downByIndex);

// setting the dropdown value to current year.

int CurrYear = Calendar.getInstance().get(Calendar.YEAR);

wdContext.currentYearValuesElement.setyear(CurrYear);

}

}

former_member186016
Active Contributor
0 Kudos

Please follow ths turorial for dynamic creation of UI element in Web Dynpro.

You can explore dynamic creation of UI elements,dynamic creation of context element, and dynamically binding UI element to context element.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94a...

It contains example for dropDownByKey UI element.

You can download the sample application from there.

Regards,

Ashwani Kr Sharma

dhawal_joshi
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Subhash,

If you need to add the UI element dynamically , you could look at the tutorial of dynamic programming .

https://www.sdn.sap.com/irj/sdn/webdynpro?rid=/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d#34

regards

Dhawal