cancel
Showing results for 
Search instead for 
Did you mean: 

Null comparison

Former Member
0 Kudos

Hi All,

I have one filed(say Name) and Save button in my iview. If Name has no value need to display mesg. In wdInit i have intialize the Name as (""), and i have declared simple type and done related code everything, so if Name has no value it is giving error when i click on Save...

If i provide value to Name and press Save, then error is coming,,,,,now my problem is if i remove entered text in Name and if i press Save it is not showing error mesg(becoz now it have null not ("") ). So to handle this i have done code, but it is not going to that Null condidtion.

IWDMessageManager messageMgr = wdComponentAPI.getMessageManager();

Object attributeValue = wdContext.currentContextElement().getAttributeValue(fieldName);

IWDAttributeInfo attributeInfo = this.wdContext.getNodeInfo().getAttribute(fieldName);

if (attributeValue instanceof String) {

if (((String) attributeValue).length() == 0) {

String fieldLabel = wdContext.getNodeInfo().getAttribute(fieldName).getSimpleType().getFieldLabel();

messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,

IMessageMSAReclassApp.MESG,new Object[] { fieldLabel },true);

wdContext.currentContextElement().setSelTab(tabName);

}

else if (this.wdContext.currentContextElement().getAttributeValue(fieldName) == null ){

{ String fieldLabel = wdContext.getNodeInfo().getAttribute(fieldName).getSimpleType().getFieldLabel();

messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,

IMessageMSAReclassApp.MESG,new Object[] { fieldLabel },true);

Could anybody tell me how to compare null NWDS..i triend dirrecnt ways but it is not working for me...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

Replace your code by the following :


if (this.wdContext.currentContextElement().getAttributeValue(fieldName) == null ){ 
{ String fieldLabel = wdContext.getNodeInfo().getAttribute(fieldName).getSimpleType().getFieldLabel();
messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,IMessageMSAReclassApp.MESG,new Object[] { fieldLabel },true);
}
elseif (attributeValue instanceof String) {
if (((String) attributeValue).length() == 0) {
String fieldLabel = wdContext.getNodeInfo().getAttribute(fieldName).getSimpleType().getFieldLabel();
messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,
IMessageMSAReclassApp.MESG,new Object[] { fieldLabel },true);
wdContext.currentContextElement().setSelTab(tabName);
} 

why I am asking this of you because in the attribute value that you've entered is null then the first condition that you are checking itself will throw a null pointer exception.

So now onwards remember to check for the null before check for an empty string condition.

Regards

Amit

Message was edited by:

Amit Kesari

Answers (4)

Answers (4)

Former Member
0 Kudos

I tried all replies, still not working

Former Member
0 Kudos

Hi

Can you print this below line

this.wdContext.currentContextElement().getAttributeValue(fieldName)

Accroding to that you go ahead.

Rgds

-SS

Former Member
0 Kudos

Hi,

You can try this:

IWDMessageManager messageMgr = wdComponentAPI.getMessageManager();
Object attributeValue = wdContext.currentContextElement().getAttributeValue(fieldName);
IWDAttributeInfo attributeInfo = this.wdContext.getNodeInfo().getAttribute(fieldName);
if (attributeValue instanceof String) {
if ((String)attributeValue == null ){ 
String fieldLabel = wdContext.getNodeInfo().getAttribute(fieldName).getSimpleType().getFieldLabel();
messageMgr.reportContextAttributeMessage(wdContext.currentContextElement(),attributeInfo,
IMessageMSAReclassApp.MESG,new Object[] { fieldLabel },true);
}
}

Regards,

Satyajit.

Former Member
0 Kudos

hi ,

The only reason that the code wont go to the block could be that

"this.wdContext.currentContextElement().getAttributeValue(fieldName) == null "

condition is not getting satisfied can you check it.Because as per you have written

the String has been initialized by the framework at runtime once you are getting the an enabled input field in your case.Just change the first block if condition

from if (((String) attributeValue).length() == 0) to attributeValue.equals("");

and it will work.

Regards

Amit

Former Member
0 Kudos

null==this.wdContext.currentContextElement().getAttributeValue(fieldName)||){0==this.wdContext.currentContextElement().getAttributeValue(fieldName).lenght())

{

display error message

}

AM

Message was edited by:

Anoop Mathew

Former Member
0 Kudos

Hi NR,

else if (this.wdContext.currentContextElement().getAttributeValue(fieldName) == null )

change to

<b>else if (null == this.wdContext.currentContextElement().getAttributeValue(fieldName) )</b>

Rgds

-SS