cancel
Showing results for 
Search instead for 
Did you mean: 

Call a method in view B from view A

Former Member
0 Kudos

Hello all,

does anybody know how to call a method in view B from view A?

Thank you for your answers!

Kind regards, Patrick.

Accepted Solutions (1)

Accepted Solutions (1)

former_member189631
Active Contributor
0 Kudos

Hi,

View is a separate Entity/Object( ie Private One).We cant access the Data/method Directly From One View to another View.So u can Declare the Method In a COMPONENT/CUSTOM contolor and Tranfer The data (it May b an Input Field Data )to That Corresponding Controller From Thr Only u can access the Method By,

wdcontext.GetComponentController.methodCall(Parameters if required);

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Vijith,

I already solved the problem. To commit the code in view B, view B has to be visible at all...

Nice weekend, Patrick.

Former Member
0 Kudos

Hi Karthikeyan!

This might be possible, but that is not, what I want to have. The logic should be placed in view B and not in the help controller...

Kind regards, Patrick.

Former Member
0 Kudos

Hi Pravesh!

I just did what you had suggested. Create Method in View A, which is calling a method in a help controller. The help controller fires an event, which should call an event handler method in view B.

And that's the problem. I have found out, that the method in the help controller is called, but the event handler method in view B isn't!

Does anybody know what the problem might be? I already registered the help controller to view A and B!

Thank you, Patrick.

Former Member
0 Kudos

Hi patrick,

You can create a method in controller for what you have done in the EventHandler of view B.

Now you can access that method from both Views. that is call the controller's method from the method in ViewA and from the Event handler method of ViewB.

regards

karthik

Former Member
0 Kudos

Hi Patrick,

Are u sure that the event handler u have created in view B is subscribing to the event in the help controller.

Just check this when crreating the event handler that the event source is the help controller and the name of the event has been selected.

Regards,

Vijith

pravesh_verma
Active Contributor
0 Kudos

Hi Patrick,

For creating and getting the values from one window to other you can use the Events. Follow these steps:

1) Go to the Component controller. Create a new <i>EVENT</i> there, say <b>setValue</b> and a Method say <b>setFinalValue().</b>

2) Create a attribute of type string in controller context, say <b>text</b>.

3) In the 1st window from which you want to pass the value, create a METHOD, say <b>SettingValue();</b>

4) In this method (ie:<i>SettingValue()</i> ), write a code to set the value of text and call the event of the controller.

To the the value of text:

wdThis.wdGet<Controller_Name>().wdGetContext().currentContextElement().setText("Any Value");

To call the event:

wdThis.wdGet<Controller_Name>().setFinalValue();

5) In the controller code write this code in the setFinalValue method.


public void setFinalValue( )  {
    //@@begin setFinalValue()
  	wdThis.wdFireEventSetValue();
    //@@end
  }

6) In the next window where you want to access this value create a Event Handler in the View of it.

<i>Methods-> New - >Event Handler-> Next -> Give name (say <b>setTextForCell</b>). Select the Event Source (ie: <i>Name of the controller</i>) and set the subscribed Event (ie: <b>setValue</b>).</i>

7) In the implementation write this code to get the set value

public void setTextForCell(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin setTextForCell(ServerEvent)
  	String text = wdThis.wdGet<Controller_Name>().wdGetContext().currentContextElement().getText();

	.....

	Use this value anywhere you want

	.....
    //@@end
  }

Also look to this link for further clarification.

<a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a137c339-0b01-0010-a688-a87b88706845">How to Navigate Inside Web Dynpro Component Interface Views</a>

I hope this will help you to solve your problem.

Regards

Pravesh

Ps: Please consider rewarding points if helpful and solved.