cancel
Showing results for 
Search instead for 
Did you mean: 

Reg: Radio Button Group by Index

Former Member
0 Kudos

Hi,

I am using radio button group ny index. I had put the property of node initialisedLeadSelection to false to make none of them as selected by default.

The selected value from the radio button is being inserted into MDM table. The problem is that even if i keep the condition for insert as to insert only if one of the radio button is selected, If i do not select any radio buttons, it is giving me null pointer exception. It is working fine if i select any of the radio button from the group.

Kindly suggest.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

I had tried using the above code by siva and it is still giving me null pointer exception.

Former Member
0 Kudos

I am getting the radio buttons as none of them selected. No problem with that. I have 2 radio buttons YES and NO. I am inserting the selected value in the backend table. If i select either yes or no, it is working fine. If nothing is selected, it is giving me null pointer exception.

if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("yes")==true||wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("no")==true)

{

if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("yes")==true)

{

newRec.setFieldValue(fields[5], new BooleanValue(true));

}

if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("no")==true)

{

newRec.setFieldValue(fields[5], new BooleanValue(false));

}

Former Member
0 Kudos

Hi Prasanthi,

Is it giving you null pointer exception on this line:

if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("yes")==true||wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("no")==true) ?

OR

Is it giving you exception from the backend while trying to insert a null value to that field?

Regards,

Murtuza

former_member197348
Active Contributor
0 Kudos

Hi,

Try like this:

if(wdContext.currentIndian_personalElement().getIndian_personal()!=null)
{
if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("yes")==true||wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("no")==true)
{
if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("yes")==true)
{
newRec.setFieldValue(fields[5], new BooleanValue(true));
}
if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("no")==true)
{
newRec.setFieldValue(fields[5], new BooleanValue(false)); 
}

}

if you want ot select any value by default,

then in wdDoInit()

// set the value
wdContext.currentIndian_personalElement().setIndian_personal("yes");

Regards,

Siva

Former Member
0 Kudos

If your context is like


Indian_personal (node, cardinality=0:n)
+ Indian_personal (string)

and there are two context elements representing "yes" (index=0) and "no" (index=1), then use code like


int selection = wdContext.nodeIndian_personal().getLeadSelection();
switch (selection)
{
case -1:
   /* code for no selection... */  
break;
case 0:
  /* code for yes-case... */
break;
case 1:
  /* code for no-case... */
break;
default:
  /* cannot happen */
}

Armin

Former Member
0 Kudos

Hi

can you share code to me.i could not get where is the problem of your code..if set initialise lead selection as false.but make sure actual node has been set or not.

thanks

jati

Former Member
0 Kudos

Hi

Please try to this code..i have wrrotten some modified.one thing if you not selected then what you want to set in your back end iethr blank or " ";

if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("yes")==true)

{

newRec.setFieldValue(fields[5], new BooleanValue(true));

}

else if(wdContext.currentIndian_personalElement().getIndian_personal().equalsIgnoreCase("no")==true)

{

newRec.setFieldValue(fields[5], new BooleanValue(false));

}

//set blank in your back end node...

}

thanks

jati

Former Member
0 Kudos

Hi,

You are getting the NullPointer at "wdContext.currentIndian_personalElement()"

You can only set initialiseLeadSelection on "Nodes" Elements. That means, it will be Null until you initialize it.

You can fix it if you do something like:


if (wdContext.currentIndian_personalElement() != null) {\
  ... your code here..
}
else {
 ... your code in case you have null there..
}

Hope it helps.

Cheers,

Daniel