cancel
Showing results for 
Search instead for 
Did you mean: 

Space

Former Member
0 Kudos

Hi all,

I am writing small webdynpro java application, in this i am doing validations for inputfields (like should contain value otherwise through an error message). i done this one but if i enter space in this field it is not throughing any error, so would any one help me. and also i want do like througing error if i click enter button or tab button with out filling values in those inputfields.

thanks

anu

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

To validate the input field for space use the following code assuming Va_Input is the context bound to the InputField UI,


String value = wdContext.currentContextElement.getVa_Input();
if(value!=null && value.trim().equals("")){
        //Display error message.
}

Here trim() method is used to remove the blank spaces and after doing this if the string is an "empty string" then it indicates that it holds only blank sapces, hence display the error message.

To do the validation on click of enter key, create an eventhandler and bind it to onEnter action of the InputField and write all the validations in that event handler. Validation on click of tab is not possible.

Hope this will be helpful.

Regards,

Vishweshwara P.K.M

Former Member
0 Kudos

Wrong. Should be


if (value == null || value.trim().length() == 0)
{
  // value is null or empty
}

Former Member
0 Kudos

Hi

Thanks for the reply i used it but i am getting null pointer exception

"java.lang.NullPointerException: while trying to invoke the method java.lang.String.trim() of an object loaded from local variable "

please help me in this

thanks

anu

former_member185879
Active Contributor
0 Kudos

Hello Usha,

Try This....

if(!(value.trim().equalsIgnoreCase("")))

{

//has some value in it and implement code to that.

}

Try this also...

if((value()!=null) && (!value().trim().equalsIgnoreCase("")))

{

///

}

Regards

Nizamudeen SM

Edited by: Nizamudeen SM on Dec 7, 2010 11:05 AM

Former Member
0 Kudos

Hi,

You are getting the error because the value is null and you are trying to trim it.

You can try below code :

supppose 'st' is your string variable.

if( st != null)

{

if( ! st.trim().equalsIgnoreCase("") )

{

-


your code----

}

}

Regards

Deepak

Former Member
0 Kudos

thanks Nizamudeen,

I tried but still i am getting null pointer exception.

the code i used in my app is

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

{

//@@begin onActionCheck(ServerEvent)

if(this.wdContext.currentNamesElement().getFname() == null)

{

this.errorDisplay();

}

else

{

wdThis.wdFirePlugToComp1View();

}

//@@end

}

public boolean errorDisplay( )

{

//@@begin errorDisplay()

IWDMessageManager messageMgr =

wdThis.wdGetAPI().getComponent().getMessageManager();

if (wdContext.currentNamesElement().getFname() instanceof String) {

return true;

}

else {

messageMgr.reportContextAttributeMessage(

this.wdContext.currentNamesElement(),

this.wdContext.nodeNames().getNodeInfo().getAttribute("Fname"),

IMessageErrorComp.DESIRE__FNAME,

null,

true);

return false;

}

//@@end

}

and one more doubt i am using "reportContextAttributeMessage" to display the message .but i think this is depricated one, would u plese suggest me which method i can use instead of this.

thanks

anu

Former Member
0 Kudos

You get a NPE in


if (value == null || value.trim().length() == 0)

I doubt that.

Answers (1)

Answers (1)

Former Member
0 Kudos

thanks its solved