cancel
Showing results for 
Search instead for 
Did you mean: 

How to define a public variable in webDynpro ?

Former Member
0 Kudos

Dear All,

I want use a variable between 2 methods.but don't know how to do , There are my part Error code ,

public class TestHtml 
{ 
  public String mystr1 = ""; 

  public void wdDoInit() 
  { 
    mystr1 = "0123"; 
  } 
  public void onActionExportIE(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent ) 
  { 
    String mystr2 = mystr1 + "b"; 
  } 

}

when I click save button ,

"public String mystr1 = ""; disappear .

can you help me ?

thanks!

Accepted Solutions (1)

Accepted Solutions (1)

former_member192434
Active Contributor
0 Kudos

Hi Doke,

The best way to declare public/private variable is to declare it on global area

Declare it at the end of view where you can see this begin and end part

Inside (As shown below) it will treated as golobal variable, which can reuseable

Anywhere within your iview.

//@@begin others

public String mystr1 = "";

//@@end

It will solve your problem.

Thanks

Anup

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Create a context attribute lets say of type String named "Mystr"

int the wdDoinit method populate this context attribute with the default value.

wdContext.currentContextElement().setMystr("0123");

access this attribute from your methods.

String val = wdContext.currentContextElement().getMystr();

Regards

Ayyapparaj

Former Member
0 Kudos

Thanks a lot eveyone!

Former Member
0 Kudos

Hi,

You can achieve this by declaring the line code -


String mystr1 = ""; in global section.

check out for the below mentioned section in your code and insert the declaration in it.

//@@begin others

//@@end

regards,

amit bagati

Former Member
0 Kudos

Hi

If you want to declare variable declared it in global area

Regards

Ruturaj