cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Null values in context

Former Member
0 Kudos

Hi,

I have a context node and 3 context attributes. I am binding this context attributes to 3 input fields.

I also have a search functionality which takes the 3 input field parameters as inputs and the input fields are not mandatory. But when i have no value in any of the input fields, it is giving me null pointer exception as i am passing one of the attribute as null to search functionality. How can i avoid this.

Please suggest.

Thanks.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Jyothi,

Adding to what Pravesh has written, I feel executing the search functionality makes sense only when atleast one of the imput parameters are provided & you get the error when nothing is provided. So you can add one more check here as below:

// Execute your search functionality when atleast one parameter is provided

if (wdContext.nodeXYZ().getAttr1()!=null || wdContext.nodeXYZ().getAttr2()!=null || wdContext.nodeXYZ().getAttr3()!=null)

{

Call your search function with the provided input parameters

}

else

{

You can use WD Message Manager API to show message to user to provide atleast one input

}

Hope I have been clear.

Kind Regards,

Nitin

Former Member
0 Kudos

Hi..

you have to create one Value node in Component context and mapped into your requirement View..

Value Node cardinality should be 1:1.....

then binding into your ui Element...one by one..

now it should be work now

thanks

sudhir

Former Member
0 Kudos

Hi there,

I have slight confusion between null and blank.

Lets say you have instantiated a model node.. will its element be null or be blank?

Lets say for example:

I instantiated the node Ball.

Then I try to use the method, eg: getColor to get the color of the ball,

Will it be null or blank?

Thank you!

former_member185086
Active Contributor
0 Kudos

Hi Jackson , Jyoti

1.Null

is the reserved constant used in Java to represent a void reference i.e a pointer to nothing. Internally it is just a binary 0, quite distinct from zero, that internally could have any representation.

2. empty

A zero-length String. i.e. x.length() == 0, e.g. "". If the empty String is interned.

If instantiated it means it not null(Pointer to nothing ) but value are not there so its blank(length 0).

Hope it help you

Best Regards

Satish Kumar

former_member185086
Active Contributor
0 Kudos

Edited

Edited by: satish jhariya on Mar 23, 2009 11:03 AM

pravesh_verma
Active Contributor
0 Kudos

Hi Jyothi,

The reason of the NULL Pointer exception is very obvious. And I am sure you would have guessed it as well. Since you have binded the Node attributes with the input fields and you are not passing any value you have to handle such a case in code. Please follow these steps:

1) First of all ensure that the node collection cardinality is 1:1. The reason is since you just have simple input fields and there can be only 1 value in each input field so setting the cardinality to 1:1 will be the best option. There are 2 advantages:

i) You need not have to create the element of this node explictly in the code.

ii) You are ensuring one more thing that atleast there is one node element always present in the

node. Therefore you will not get the NULL Pointer exception atleast due to no elements in the

node. There will be always 1 element present in the node.

2) Put the null pointer checks for all teh inputfield values:

Let say you have node XYZ and attributes attr, attr2, attr3 each binded to the input field then use this code to get the value of the input fields :



String valAttr1 = null;
String valAttr2 = null;
String valAttr3 = null;

if(wdContext.nodeXYZ().getAttr1()!=null){
valAttr1 = wdContext.nodeXYZ().getAttr1();
}

if(wdContext.nodeXYZ().getAttr2()!=null){
valAttr2 = wdContext.nodeXYZ().getAttr2();
}

if(wdContext.nodeXYZ().getAttr3()!=null){
valAttr3 = wdContext.nodeXYZ().getAttr3();
}

Using this code for NULL value check you will avoid all the situations of NULL values. Also if there are no values in the input fields, you know that value of valAttr1, valAttr2, valAttr3 are null. If you want that instead of null it should be a empty string you can do that as well by declaring it to " "... check this code:


String valAttr1 = "";
String valAttr2 = "";
String valAttr3 = "";
...
...
//Rest of the code is same as above code
...

Using this code you will get the value of the inputfields as empty string even if there are no values. I hope this should solve you problem of NULL pointer exception.

I hope this helps. If you have any further issues please revert back.

Thanks and Regards,

Pravesh