cancel
Showing results for 
Search instead for 
Did you mean: 

Problem validating a drop down list element

Former Member
0 Kudos

Hello all!!

I have a doubt because when i create a drop down list there is always a blank spot added by default in every list I made. The problem is when the option in the drop down is optional and the user assumes that must be as blank, then a null pointer exception error appears. Is there a way to validate or eliminate this blank spot??.

Regards IA

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Armando Miranda,

You can remove the blank entry from drop down by changing the selection property of a node from 0..1 to 1..1.

If you want to handle the null pointer exception when the user selects blank entry from the drop down you have to do the null check in your custom action method.

Before accessing the current element you have to perform null check. Let us suppose you have binded CitiesNode to drop down with selection 0..1. And user selects the blank entry from the drop down and clicked on button on the screen. In the code, we have to access like

if(wdContext.currentCitiesNodeElement() ! = null)

{

wdContext.currentCitiesNodeElement().getCityName() //City Name is value attribute in CitiesNode

}

The above check is necessary because, when the user selects blank entry as null then the currentCitiesNodeElement is null. If we don't do the null check and try to access the city name of currentCitiesNodeElement it will throw NullPointer Exception.

Regards,

Jaya.

Edited by: VJR on Apr 15, 2009 5:35 PM

Answers (5)

Answers (5)

Former Member
0 Kudos

Thans to all, problem solved!!!

Regards

Former Member
0 Kudos

Hi,

give selection as 1..n for the context node which u r binding to the drop down .

regards,

ramani.

pravesh_verma
Active Contributor
0 Kudos

Hi Armando,

You can handle it using a check. Just try and implement this:

1) Get the current value of the dropdown in the onSelect Action of dropdown. let say like this:


String value = wdContext.current<Node_Name>Element().get<Attribute_Name>();
	  
	  if(name == null || name.equalsIgnoreCase("")){
		  // put your required message OR store the blank value in backend.
	  }

No you can handle the null values of the dropdown in this if loop.

I hope this resolves your issue. Please revert back in case you need any further information.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hi,

If you want to remove the null pointer exception when you select the empty value then follow the validation code given below.

   if(wdContext.nodeDDBK().currentDDBKElement().getKey()==null){
		  wdComponentAPI.getMessageManager().reportException("Please select a value in the dropdown");
		
	  }
	  else {
		  <<Your logic >>
	    } 

Or if you do not need that empty feild, then set the lead selection of the node which you have bind to the drop down as 0.

 wdContext.nodeFirst().setLeadSelection(0);

Hope this helps..

Jithin

Former Member
0 Kudos

Hi,

You can set the Value of the Mapped Attribute (which is in your View Context) to whatever is the First Value in the dropdown list.

Example, you have a dropdown being mapped to NodeTest > TestAttribute;

You can use something like nodeTestElement.setTestAttribute(value);

This way the "Initial" selectedIndex would be whatever you say in the Value of the Attribute.

Regards,

Daniel