cancel
Showing results for 
Search instead for 
Did you mean: 

WebDynpro Global Data

adnanmaqbool
Contributor
0 Kudos

Dear All I have written following code to add data in table behind an action button.



 public void onActionInsert(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionInsert(ServerEvent)  
    

	String PassYear = wdThis.wdGetContext().currentContextElement().getPassYear();
	String GPA = wdThis.wdGetContext().currentContextElement().getGPA();
	String Major = wdThis.wdGetContext().currentContextElement().getMajor();
	String Institute = wdThis.wdGetContext().currentContextElement().getInstitute();
    
    Zrfc_Online_Edu_Input input2 = new Zrfc_Online_Edu_Input(); 
	wdContext.nodeZRFC_ONLINE_EDU().bind(input2);    
	Zonline_Edu tab = new Zonline_Edu();
		  
		 
	   tab.setGpa(GPA);
	   tab.setMajor(Major);
	   tab.setPassyear(PassYear);
	   tab.setInstitute(Institute);
	   tab.setDegree("Masters");
	   input2.addEducation_Tab(tab);	   
	 
   
   
  
    //@@end
  }

But following code is overwriting the previous records every time I click Action button. How can I write the below code outside action button.



   
    Zrfc_Online_Edu_Input input2 = new Zrfc_Online_Edu_Input(); 
    wdContext.nodeZRFC_ONLINE_EDU().bind(input2);    
    Zonline_Edu tab = new Zonline_Edu();

Accepted Solutions (0)

Answers (7)

Answers (7)

adnanmaqbool
Contributor
0 Kudos

Following Code resolved the problem.



 public void onActioninsertMaster(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActioninsertMaster(ServerEvent)
    
	    String PassYear = wdThis.wdGetContext().currentContextElement().getPassYear();
		String GPA = wdThis.wdGetContext().currentContextElement().getGPA();
		String Major = wdThis.wdGetContext().currentContextElement().getMajor();
		String Institute = wdThis.wdGetContext().currentContextElement().getInstitute();
    
		  wdContext.nodeZRFC_ONLINE_EDU().bind(input2); 		
		   tab = new  Zonline_Edu(); 
			 
		   tab.setGpa(GPA);
		   tab.setMajor(Major);
		   tab.setPassyear(PassYear);
		   tab.setInstitute(Institute);
		   tab.setDegree("Masters");
		   input2.addEducation_Tab(tab);	   
		 
    //@@end
  }

  //@@begin others

  Zrfc_Online_Edu_Input input2 = new Zrfc_Online_Edu_Input();
  Zonline_Edu tab;
  
  //@@end

Former Member
0 Kudos

Hi,

Try this.

Put the following code under wdInit()

Zrfc_Online_Edu_Input input2 = new Zrfc_Online_Edu_Input();

Zonline_Edu tab = new Zonline_Edu();

input2.addEducation_Tab(tab);

wdContext.nodeZRFC_ONLINE_EDU().bind(input2);

and put the remaining code under Action Handler

currentZonline_EduElement().setGpa(GPA);

currentZonline_EduElement().setMajor(Major);

currentZonline_EduElement().setPassyear(PassYear);

currentZonline_EduElement().setInstitute(Institute);

currentZonline_EduElement().setDegree("Masters");

and use reset method to flush your data accordingly for tab data.

Kiran

former_member201361
Active Contributor
0 Kudos

hi,

move the code to the doInit Method , as this is the hook method called only once so the model classes can be instantiated only once and in the Button Action U execute the model and feed the data to the Table .

Thanks and Regards

Fistae

0 Kudos

you can write in wdDoModifyView mothod

if(fristTime){

Zrfc_Online_Edu_Input input2 = new Zrfc_Online_Edu_Input();

wdContext.nodeZRFC_ONLINE_EDU().bind(input2);

Zonline_Edu tab = new Zonline_Edu();

}

Thanks

linghj

adnanmaqbool
Contributor
0 Kudos

Dear linghj

Writing this code in wdDoModifyView() or wdInit method makes the

input2

tab

non accessable in action behind button.

former_member201361
Active Contributor
0 Kudos

Hi,

Ya u r right . then while creating the action for the button add a parameter to the method OnAction of type Boolean(firstTime).

Finally in the Action method use the below procedure :

if(firstTime){

put the code

}

and here insert the data to the table.

Thanks and Regards

Fistae

Former Member
0 Kudos

Hi,

You havn't posted all your code.

But I guess that, every time onActionInsert, a new Zonline_Edu Object should be created.

So, just move the following two statements:

Zrfc_Online_Edu_Input input2 = new Zrfc_Online_Edu_Input(); 
    wdContext.nodeZRFC_ONLINE_EDU().bind(input2);

The 3rd statement stays in the current place:

Zonline_Edu tab = new Zonline_Edu();

Former Member
0 Kudos

Hi,

move that code from the button action handler to wdDoinit.

Regards

Ayyapparaj

Former Member
0 Kudos

HI Adnan,

you can write that code in the at the bottom of ur implementation page between

//@@begin others

Zrfc_Online_Edu_Input input2 = new Zrfc_Online_Edu_Input();

wdContext.nodeZRFC_ONLINE_EDU().bind(input2);

Zonline_Edu tab = new Zonline_Edu();

//@@end

Thanks

Jeet