cancel
Showing results for 
Search instead for 
Did you mean: 

Caching in Web Dynpro Java

Former Member
0 Kudos

Hi Experts,

I am trying to develop a web dynpro for java application based on RFC model.

I am using an RFC that brings the Countries and States from the R/3 and will be used as dropdowns in the views controllers.

The question is:

I would like to cache the Countries and States in my web dynpro application. The idea is not to execute the model everytime. The model should be executed only once. I would like to store these countries and states in a local java dictionary or etc. and use them for UI element designing.

Is there any way to do this in Web Dynpro Java? I would like to follow a better approach to avoid performance problems.

I do not want to follow this approach: executing the model in the wdInit method of the controller. Executing this model in this method also causes performance problems. Because the model is brining approx 1540 records from R/3.

Please advice.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

follow the following steps

Step 1: Execute RFC to fetch data preferably use doInt method for it.

Step 2: after executing the RFC, bind the values from your node to dropdown as:

ISimpleTypeModifiable attributeLovSimpleType =((AttributeInfo) wdContext.node<nodename>().getNodeInfo().getAttribute(<attribute name>);

Note Here attribute name is the name of attribute binded to your drop down field.

IModifiableSimpleValueSet attributeLovSimpleTypeValueSet =attributeLovSimpleType.getSVServices()getModifiableSimpleValueSet();

String strState =((String) wdContext.node<Output node name>.current<output node name>Element.getstate();

String strCountry =((String) wdContext.node<Output node name>.current<output node name>Element.getCountry();

attributeLovSimpleTypeValueSet.put(strState, strCountry);

This way u will ge set of country state inside your input field.

Regards,

amit bagati

Former Member
0 Kudos

Hi All,

Thank you for the suggestions.

I am a beginer in wd java. i am starting with amit's suggestion.

Step 1: Execute RFC to fetch data preferably use doInt method for it.

Should I execute the method in wdInit of the view controller/component controller?

I defined a method "executePMPReadBAPI" in component controller.

public void executePMPReadBAPI( )

{

//@@begin executePMPReadBAPI()

try{

wdContext.currentPMPDoctorReadElement().modelObject().execute();

}catch (Exception e){

logger.errorT("Error in executing PMP Read BAPI");

}

wdInit of View controller:

IWDAttributeInfo countryInfo =

wdContext.getNodeInfo().getAttribute(

wdContext.currentContextElement().COUNTRY);

ISimpleTypeModifiable countryType =

countryInfo.getModifiableSimpleType();

IModifiableSimpleValueSet countryValueSet =

countryType.getSVServices().getModifiableSimpleValueSet();

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

IWDNodeElement CountryNode =

wdContext.nodeCountries().getElementAt(i);

String countryKey = (String) CountryNode.getAttributeValue("Land1");

String countryText =

(String) CountryNode.getAttributeValue("Landx");

countryValueSet.put(countryKey, countryText);

}

This coding is working, I am able to populate the dropdowns. The problem is the application is slow.

I am guessing this much coding is not necessary in the view conroller's wdInit method.

Why the binding approach like mentioned below is not working (model>Conroller>View)? How should I execute the RFC in the wdInit of the component controller? Is this possible?

wdInit of Component Controller: Below coding and proper binding is not sufficient to populate dropdowns? Please advice.

Zhr_Ess_Address_Input ReadInput = new Zhr_Ess_Address_Input();

wdContext.nodeZhr_Ess_Address_Input().bind(ReadInput);

try {

wdContext

.currentZhr_Ess_Address_InputElement()

.modelObject()

.execute();

wdContext.nodeOutput().invalidate();

} catch (Exception e) {

logger.errorT("Error Reading the BAPI");

}

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Minisap,

You can use session rather. This is comparatively easy for

implementing your requirment.

Just put the values in a key as given below and fetch it in the required place using the same key. You can put it in init method as it is called only once and fetch it any time you want.

// To put key

IMaintainScope maintainer = Utils.getScopeMaintainer(WDScopeType.CLIENTSESSION_SCOPE);

maintainer.getScope().put("SampleKey", "20045");

// To Get Key

String value = (String)maintainer.getScope().get("SampleKey");

Hope this helps.

Former Member
0 Kudos

My approach would be to create a create a special class for loading and caching, implemented as singleton. As even countries might change from time to time, i would execute the RFC one time a day. A simple solution to check if the RFC was already executed on a day would be to work with the current systemtime, a boolean flag and some synchonization.

Former Member
0 Kudos

Hi if you want to get the List of Countries from SAP then you need to execute the Model, and the

wdDoInit() method will be exected only once in your application

When ever you open the application the wdDoInit() method is executed only once then store all the valued from the BAPI in the context of the component Controlled.

Former Member
0 Kudos

After you execute the BAPI.

Create a context node(parent) and create attributes.

Set those values to a context node elements.

wdthis.currentcontext.setvalue()