cancel
Showing results for 
Search instead for 
Did you mean: 

Tutorial TutWD_Popup_Init (2)

Former Member
0 Kudos

I try to complete the sample base on the Tutorial TutWD_Popup_Init. I deployed the application and it looks well. But as I click the button "To" I got exception as follow:


java.lang.NullPointerException 

    at com.sap.tc.webdynpro.tutorial.popup.EmailView.onActionShowAddressbookPopup(EmailView.java:197)
    at com.sap.tc.webdynpro.tutorial.popup.wdp.InternalEmailView.wdInvokeEventHandler(InternalEmailView.java:197)
    at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
    at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
    at com.sap.tc.webdynpro.clientserver.window.WindowPhaseModel.doHandleActionEvent(WindowPhaseModel.java:420)
    ... 26 more

The code at line EmailView.java:197 is as follow:


              //	 Save WindowInstance in Context
		wdContext.currentPopupElement().setWindowInstance(window);

By debug I find wdContext.currentPopupElement() = null.

Has someone the same problem?

Accepted Solutions (1)

Accepted Solutions (1)

Hullen
Advisor
Advisor
0 Kudos

Hi Thomas,

as your coding looks fine, you should check your context node "Popup" - maybe the mistake is in there. Especially check the collection cardinality (1..1), which seems like the most likely cause for the NullPointerException to me.

Regards,

Ulrich

.

Answers (1)

Answers (1)

Former Member
0 Kudos

Add the element to the node as follows

IPrivate<viewname>.IPopupElement ele = wdContext.nodePopup().createPopupElement();

ele.setWindowInstance(window);

wdContext.nodePopup().addElement(ele);

Regards,

Murtuza

Former Member
0 Kudos

1.

Can you explain me why should I do that? Does it mean the tutorial has mistake?

2.

What do you mean "Add the element to the node as follows"? What element and where is the node?

former_member751941
Active Contributor
0 Kudos

Hi Thomas,

Check the type of attribute "WindowInstance"

whether it is <b>com.sap.tc.webdynpro.services.session.api.IWDWindow</b> or not?

Regards,

Mithu

Former Member
0 Kudos

1.

the type of attribute "WindowInstance" is com.sap.tc.webdynpro.services.session.api.IWDWindow.

2.

Your link seems do not help.

Here is my code:


...
import com.sap.tc.webdynpro.services.session.api.IWDWindow;
...
		IWDWindowInfo windowInfo =
			(IWDWindowInfo) wdComponentAPI.getComponentInfo().findInWindows(
				"AddressbookWindow");
		//	  create the “AddressbookWindow”
		IWDWindow window =
			wdComponentAPI.getWindowManager().createWindow(windowInfo, true);
		//	  set the WindowPosition on the screen
		window.setWindowPosition(300, 150);
		//	  and show the window
		window.open();
		//	   Save WindowInstance in Context
		wdContext.currentPopupElement().setWindowInstance(window);

If I use the downloaded ready_to_use code, it runs. I try< to find the differences but it seems impossible. There are too many files.

Message was edited by:

Thomas Roland

Former Member
0 Kudos

Hi Thomas,

What is the cardinality of the node PopupElement. I think its 0..1(n)

if its 0..1(n) then you need to create an element before accessing the current Element.

or else the simple option is to make the cardinality of the node PopUpElement as 1..1(n).

Other than that the code looks fine.

Regards

Ayyapparaj

Former Member
0 Kudos

Hi Thomas,

1.

You need to have an element of the node to set its attribute and if there is no element instantiated for the node and still you try to access its current<node>Element then you may turn up with nullpointer Exception.

Check the cardinality of the node. If its 0:1 or 0:n then you need to instantiate an object as I mentioned in the previous reply or the other alternative is you can change its cardinality to 1:1 or 1:n.

2.

Node is the popup node that you have defined in the context. If you want to add elements to your node programatically at runtime then the above mentioned code will do that for you.

Warm Regards,

Murtuza