cancel
Showing results for 
Search instead for 
Did you mean: 

Pre-select dropdown by key.

Former Member
0 Kudos

I am using this code to pre-select dropdown by key...


// Pre-select the selected competency
	for(int i = 0; i < wdContext.nodeCoreCompetency().size(); i++){
		if(wdContext.nodeCoreCompetency().getElementAt(i).toString().equals(wdContext.currentCourseDetailsElement()
					.getCoreCompetency())){
						wdComponentAPI.getMessageManager().reportSuccess("Match found: "+i);
						  wdContext.nodeCoreCompetency().setLeadSelection(i);
						  break;
		}
	}

What is wrong with above code.

Thanks

Srinivas

Accepted Solutions (1)

Accepted Solutions (1)

shabeer_skhan
Explorer
0 Kudos

Hi Srinivas,

You can achieve this by using a drop down by index ( i haven't used drop down by key for a while so i may not be able to give exact procedure for that)

If you are ready to use drop down by index this is what you have to do.

I presume you have a node 'CoreCompetency' with attribute 'Competency' of string type.

you can populate this node as follows



String competencies[]={"Comp1","Comp2","Comp3","Comp4","Comp5","Comp6"};

IPrivate<ViewName>.ICoreCompetencyElement competencyElement=null; // Instance to store each element of the node 'Core Competency'

for(int index=0;index<competencies.length();index++){
      competencyElement=wdContext.nodeCoreCompetency().createCoreCompetencyElement();
      competencyElement.setCompetency(competencies[index]);
      wdContext.nodeCoreCompetency().addElement(competencyElement);
}


1. Bind the 'texts' property of the Drop Down by Index to 'Competency' attribute of the above mentioned node.

2. To select a particular value in the drop down, say, based on the value of another attribute 'Competency' under the node 'CourseDetails' use this code


  
   for(int index=0;index<wdContext.nodeCoreCompetency().size();index++){
        if(wdContext.nodeCoreCompetency().getCoreCompetencyElement(index).getCompetency().
                  equalsIgnoreCase(wdContext.currentCourseDetailsElement().getCompetency()){
                  wdContext.nodeCoreCompetency().setLeadSelection(index);
                  break;
        } //end if     
  } // end for
    

Hope this will help you.

Regards,

Shabeer.

Answers (8)

Answers (8)

Former Member
0 Kudos

I used dropdown by index and its working fine. Now I have an empty selection in the list at the top. I tried to remove it using this code...


IWDNodeElement first = wdContext.nodeDataSource().getElementAt(0);
wdContext.nodeDataSource().removeElement(first);

This is removing one of the entries in the list, but not removing the empty selection.

Any ideas on how to remove the empty selection from drop down by index.

Former Member
0 Kudos

Hi,

Set the selection property of the node which you have binded to the dropdown by index to 1..n instead of 0..1.

Set this property and check.

Hope this helps you.

Regards,

Saleem

Former Member
0 Kudos

Let me see if I get your problem.

To use a DropDownByKey element you need a context element (not a set of elements)

make a node with a cardinalitiy of 1..1 to avoid confusion ....or use one of 1..n, but you have to understand that the DDBK its pointing to a single context element. A context element with a list of values.

how do you set a context element with a value (if you set it to a value then you pre-select it)

wdContext.nodeCoreCompetency().setCoreCompetencies("1");

when you do this the "1" its gonna be set but the "comp1" its gonna be showed

(asuming filterVal.put("1", "comp1");)

What I do its that right after I fill the DDBK I set a default value

wdContext.nodeCoreCompetency().setCoreCompetencies("1");

Former Member
0 Kudos

Hello Srinivas,

If you want to use a dropdown by key UI element you cannot bind a node to the dropdown of this type. You have to bind a context attribute of simple type to the selected key property of the dropdown by key UI element.

As I have seen the above code provided by you. You are using a simple type named 'CoreCompetencies' and filling the key and values for this using the code mentioned above. Now just create a context attribute and set the context attribute type to this simple type. You can find this using simpletype radio button in the Type selection screen which creating the attribute. You will find the simpletype in the package mentioned by you.

Now bind this context attribute to the selectedkey property of this UI element. Now when you load the view all the values present in simple type will be visible in the dropdown.

Now to preselect value in the dropwn just set the context attribute with the value part of the simple type like:

wdContext.currentContextElement().setConfigurationType("comp1" or "1");
        //depending which is your value for simple type

You can use this code anywhere where ever you need. for e.g. in wdDoinit() to preselect any value in dropdown.

If you want to set any other value in the dropdown just set this context attribute with the specified value and the same will appear to be selected in dropdown. If the specified value is not present in the simpletype no value will be selected in dropdown.

Regards,

Ardhendu Sarkar

Former Member
0 Kudos

Read the Javadoc for DDByKey and DDByIndex. You are mixing things up.

Armin

Former Member
0 Kudos

Hi,

Try using "equalsIgnoreCase" instead of "equals" in the below statement.

if(wdContext.nodeCoreCompetency().getElementAt(i).toString().equalsIgnoreCase(wdContext.currentCourseDetailsElement().getCoreCompetency()))

Hope it works.

Regards

Shruti

Former Member
0 Kudos

Hi,

If you are using drop down key with this code , you will get no output.

You have to use drop down by index for this as you are binding node to the value of drpdown.

AM

Former Member
0 Kudos

After populating the dropdown, I need to compare the values in the dropdown to a string, and then pre-select the dropdown with that value.

Here is the code I am using...


//	fill the dropdowns search filter
	  ISimpleTypeModifiable filterType=wdThis.wdGetAPI().getContext().getModifiableTypeOf("CoreCompetency.CoreCompetencies");
	  IModifiableSimpleValueSet filterVal=filterType.getSVServices().getModifiableSimpleValueSet();
	  filterVal.put("1", "comp1");
	  filterVal.put("2", "comp2"); 
	  filterVal.put("3", "comp3");
	  filterVal.put("4", "comp4"); 
   	  filterVal.put("5", "comp5");
	  filterVal.put("6", "comp6"); 
	  wdComponentAPI.getMessageManager().reportSuccess("Size of dropdown node: " +wdContext.nodeCoreCompetency().size());

This prints the size as 1, even though there are 6 values...

Here is the code am using to compare the string with all the drop down values



	// Pre-select the selected competency
	for(int i = 0; i < wdContext.nodeCoreCompetency().size(); i++){
		
		wdComponentAPI.getMessageManager().reportSuccess("Dropdown value: "+
					wdContext.nodeCoreCompetency().getCoreCompetencyElementAt(i).getCoreCompetencies().toString());  
		if(wdContext.nodeCoreCompetency().getElementAt(i).toString().equals(wdContext.currentCourseDetailsElement()
					.getCoreCompetency())){
						wdComponentAPI.getMessageManager().reportSuccess("Match found: "+i);
						  wdContext.nodeCoreCompetency().setLeadSelection(i);
						  break;
		}
	}

I get null pointer exception at


wdComponentAPI.getMessageManager().reportSuccess("Dropdown value: "+
					wdContext.nodeCoreCompetency().getCoreCompetencyElementAt(i).getCoreCompetencies().toString()); 

What is the correct way to do it.

Should I even be using a drop down by key ?

Thanks

Srinivas

gill367
Active Contributor
0 Kudos

Hello Sri,

You need to fill the dropdown by using the following method instead of using the SImple type

fill the node CoreCompetency by using the following method

before writing this code add an attribute code to the corecompetency

   IPrivateTEST_appView.ICoreCompetencyElement cc_el = wdContext.nodeCoreCompetency().createCoreCompetencyElement();
    cc_el.setCode("1");
    cc_el.setCoreCompetency("comp1");
    wdContext.nodeCoreCompetency().addElement(cc_el);
	IPrivateTEST_appView.ICoreCompetencyElement cc_el2 = wdContext.nodeCoreCompetency().createCoreCompetencyElement();
    cc_el2.setCode("2");
    cc_el2.setCoreCompetency("comp2");
	wdContext.nodeCoreCompetency().addElement(cc_el2);

then you can use your method to preselect a value

thanks

Sarbjeet singh

Former Member
0 Kudos

Hi,

Your requirement as follows.

1. You have a drop down (competencies drop down) with set of competencies.

2. You have a competency value at wdContext.currentCourseDetailsElement().getCoreCompetency().

3. You want to courseDetail -> corecompetency value to be highlighted in the competencies drop down.

First fill up your competencies node with the set of values.


IPrivate<View name>.ICoreCompetencyElement competency1 = wdContext.nodeCoreCompetency().createCoreCompetencyElement();
    competency1.setCode("1");
    competency1.setCoreCompetency("comp1");
// Add comp1 to CoreCompetency node
wdContext.nodeCoreCompetency().addElement(cc_el);
IPrivate<view name>.ICoreCompetencyElement competency2 = wdContext.nodeCoreCompetency().createCoreCompetencyElement();
    competency2.setCode("2");
    competency2.setCoreCompetency("comp2");
// Add comp2 to CoreCompetency node
wdContext.nodeCoreCompetency().addElement(cc_el2);

Now write your condition to compare courseDetail -> corecompetency value with each drop down value and highligh the necessary competency.


// Pre-select the selected competency
for(int i = 0; i < wdContext.nodeCoreCompetency().size(); i++){
  String selectableCompetency = wdContext.currentCourseDetailsElement().getCoreCompetency();
  String currentDropDownElement = wdContext.nodeCoreCompetency().getCoreCompetencyElementAt(i).getCoreCompetencies();  

 if(selectableCompetency != null && selectableCompetency.equalsIgnoreCase(currentDropDownElement)) {
  wdComponentAPI.getMessageManager().reportSuccess("Match found: "+i);
  wdContext.nodeCoreCompetency().setLeadSelection(i);
  break;
 }
}

Hope this clarifies your doubt!

Regards,

Jaya.

shabeer_skhan
Explorer
0 Kudos

Hi Srinivas,

The line


wdContext.nodeCoreCompetency().getElementAt(i).toString()

should be something like this


wdContext.nodeCoreCompetency().getCoreCompetencyElementAt(i).getCoreCompetency().toString()

if you want to compare the value of attribute 'CoreCompetency' in each element of the node with the value attribute 'CoreCompetency'

Regards,

Shabeer.

Former Member
0 Kudos

Check to see if the lines


wdContext.nodeCoreCompetency().getElementAt(i).toString()

the above line returns something like "NodeElement([nameofcompcontroller].CoreCompetency(i))"

and


wdContext.currentCourseDetailsElement().getCoreCompetency()

ever match up.

Print them to the screen.