cancel
Showing results for 
Search instead for 
Did you mean: 

Check for blank input field returns NullPointerException

Former Member
0 Kudos

Hi

I have used

if(wdContext.currentContextElement().getName()==null){}

this for checking blank input , but it is giving NullPointerException ; any clue.

I am using in it SAP floor plan manager architecture.

Thanks in advance

Ananda

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I doubt that. Can you post the complete stacktrace?

Armin

Former Member
0 Kudos

Hi Armin. I am using SAP Floor Plan Manager infastructure for this.Is there is any special way to handle this ( Screen Validation) in FPM.Stack trace is

java.lang.NullPointerException
	at com.companyname.xss.hr.edumm.vac.overview.OverviewView.verify(OverviewView.java:145)
	at com.companyname.xss.hr.edumm.vac.overview.OverviewView.onActionsave(OverviewView.java:181)
	at com.companyname.xss.hr.edumm.vac.overview.wdp.InternalOverviewView.wdInvokeEventHandler(InternalOverviewView.java:144)
	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.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)
	at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)
	at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)
	at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)
	at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:248)
	at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)
	at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)
	at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)
	at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)
	at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)
	at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)
	at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)
	at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)
	at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
	at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
	at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
	at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
	at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)
	at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:159)

Thanks

Ananda

Former Member
0 Kudos

Is OverviewView.java your code or framework code?

Armin

Former Member
0 Kudos

Hello

OverviewView.java is my View

Please help

Thanks

Ananda

Former Member
0 Kudos

Please post the code including the line where the exception is thrown.

Armin

Former Member
0 Kudos

Hi Armin

If I give some input it's navigating to the next view as expected.

Here is the code from view implementation

[code]// -


// This file has been generated partially by the Web Dynpro Code Generator.

// MODIFY CODE ONLY IN SECTIONS ENCLOSED BY @@begin AND @@end.

// ALL OTHER CHANGES WILL BE LOST IF THE FILE IS REGENERATED.

// -


package com.companyname.xss.hr.edumm.vac.overview;

//

// IMPORTANT NOTE:

// ALL IMPORT STATEMENTS MUST BE PLACED IN THE FOLLOWING SECTION ENCLOSED

// BY @@begin imports AND @@end. FURTHERMORE, THIS SECTION MUST ALWAYS CONTAIN

// AT LEAST ONE IMPORT STATEMENT (E.G. THAT FOR IPrivateOverviewView).

// OTHERWISE, USING THE ECLIPSE FUNCTION "Organize Imports" FOLLOWED BY

// A WEB DYNPRO CODE GENERATION (E.G. PROJECT BUILD) WILL RESULT IN THE LOSS

// OF IMPORT STATEMENTS.

//

//@@begin imports

import java.sql.Date;

import com.companyname.xss.hr.edumm.vac.overview.wdp.IPrivateOverviewView;

import com.sap.pcuigp.xssfpm.java.IFPM;

import com.sap.tc.webdynpro.services.message.WDMessageType;

//@@end

//@@begin documentation

//@@end

public class OverviewView

{

/**

  • Logging location.

*/

private static final com.sap.tc.logging.Location logger =

com.sap.tc.logging.Location.getLocation(OverviewView.class);

static

{

//@@begin id

String id = "$Id$";

//@@end

com.sap.tc.logging.Location.getLocation("ID.com.sap.tc.webdynpro").infoT(id);

}

/**

  • Private access to the generated Web Dynpro counterpart

  • for this controller class. </p>

*

  • Use <code>wdThis</code> to gain typed access to the context,

  • to trigger navigation via outbound plugs, to get and enable/disable

  • actions, fire declared events, and access used controllers and/or

  • component usages.

*

  • @see com.companyname.xss.hr.edumm.vac.overview.wdp.IPrivateOverviewView for more details

*/

private final IPrivateOverviewView wdThis;

/**

  • Root node of this controller's context. </p>

*

  • Provides typed access not only to the elements of the root node

  • but also to all nodes in the context (methods node<i>XYZ</i>())

  • and their currently selected element (methods current<i>XYZ</i>Element()).

  • It also facilitates the creation of new elements for all nodes

  • (methods create<i>XYZ</i>Element()). </p>

*

  • @see com.companyname.xss.hr.edumm.vac.overview.wdp.IPrivateOverviewView.IContextNode for more details.

*/

private final IPrivateOverviewView.IContextNode wdContext;

/**

  • A shortcut for <code>wdThis.wdGetAPI()</code>. </p>

  • Represents the generic API of the generic Web Dynpro counterpart

  • for this controller. </p>

*/

private final com.sap.tc.webdynpro.progmodel.api.IWDViewController wdControllerAPI;

/**

  • A shortcut for <code>wdThis.wdGetAPI().getComponent()</code>. </p>

  • Represents the generic API of the Web Dynpro component this controller

  • belongs to. Can be used to access the message manager, the window manager,

  • to add/remove event handlers and so on. </p>

*/

private final com.sap.tc.webdynpro.progmodel.api.IWDComponent wdComponentAPI;

public OverviewView(IPrivateOverviewView wdThis)

{

this.wdThis = wdThis;

this.wdContext = wdThis.wdGetContext();

this.wdControllerAPI = wdThis.wdGetAPI();

this.wdComponentAPI = wdThis.wdGetAPI().getComponent();

}

//@@begin javadoc:wdDoInit()

/** Hook method called to initialize controller. */

//@@end

public void wdDoInit()

{

//@@begin wdDoInit()

//@@end

}

//@@begin javadoc:wdDoExit()

/** Hook method called to clean up controller. */

//@@end

public void wdDoExit()

{

//@@begin wdDoExit()

//@@end

}

//@@begin javadoc:wdDoModifyView

/**

  • Hook method called to modify a view just before rendering.

  • This method conceptually belongs to the view itself, not to the

  • controller (cf. MVC pattern).

  • It is made static to discourage a way of programming that

  • routinely stores references to UI elements in instance fields

  • for access by the view controller's event handlers, and so on.

  • The Web Dynpro programming model recommends that UI elements can

  • only be accessed by code executed within the call to this hook method.

*

  • @param wdThis Generated private interface of the view's controller, as

  • provided by Web Dynpro. Provides access to the view controller's

  • outgoing controller usages, etc.

  • @param wdContext Generated interface of the view's context, as provided

  • by Web Dynpro. Provides access to the view's data.

  • @param view The view's generic API, as provided by Web Dynpro.

  • Provides access to UI elements.

  • @param firstTime Indicates whether the hook is called for the first time

  • during the lifetime of the view.

*/

//@@end

public static void wdDoModifyView(IPrivateOverviewView wdThis, IPrivateOverviewView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

{

//@@begin wdDoModifyView

//@@end

}

//@@begin javadoc:verify()

/** Declared method. */

//@@end

public void verify( )

{

//@@begin verify()

if(wdContext.currentContextElement().getName()==null){

fpm.getMessageManager().reportMessage(wdThis.wdGetAPI().getComponent(),

"MandatoryInput",

WDMessageType.STANDARD,

"Missing Input");

allok = false;

}

else{

allok=true;

}

//@@end

}

//@@begin javadoc:onActionsave(ServerEvent)

/** Declared validating event handler. */

//@@end

public void onActionsave(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionsave(ServerEvent)

verify();

if(allok==true)

{

wdThis.wdGetVcOverviewController().save();

}

//@@end

}

/*

  • The following code section can be used for any Java code that is

  • not to be visible to other controllers/views or that contains constructs

  • currently not supported directly by Web Dynpro (such as inner classes or

  • member variables etc.). </p>

*

  • Note: The content of this section is in no way managed/controlled

  • by the Web Dynpro Designtime or the Web Dynpro Runtime.

*/

//@@begin others

IFPM fpm=null;

boolean allok;

//@@end

}

[/code]

Thanks

Ananda

Former Member
0 Kudos

Hi

Check these lines in ur code.

//@@begin others

<b> IFPM fpm=null;</b>

boolean allok;

//@@end

public void verify( )

{

//@@begin verify()

if(wdContext.currentContextElement().getName()==null){

<b> fpm.getMessageManager().reportMessage</b>(wdThis.wdGetAPI().getComponent(),

"MandatoryInput",

WDMessageType.STANDARD,

"Missing Input");

.....

}

u have given a null value to fpm and u havnt given any value to it anywhere. I think this must be the problem. If not give the lines 145 and 181 of ur code.

Hope this helps.

Regards,

Rathna.

Former Member
0 Kudos

I agree. wdContext.currentContextElement() can never be NULL.

Armin

Former Member
0 Kudos

Thanks Armin & Rathna

The cause of error is the IFPM=null;

I have put the verify() in Component Controller instead of view where FPM is automatically invoked by the framework thru Interface controller thereby eliminating the exception.

Regards

Ananda

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ananda,

In your scenario, can you tell me if you are using "name" as model attribute or value attribute in ur context. If it is a simple value attribute, better place a condition before that if statement to check if the (wdContext.currentContextElement() == null).

Also you can debug on the context element and inspect which attributes exist.

If possible please reply in details about that attribute if it is a model attribute which is mapped or binded etc..

Regards

Praveen