cancel
Showing results for 
Search instead for 
Did you mean: 

bindSelectedKey Question

Former Member
0 Kudos

I have the below context structure and am trying to create DropDown UI objects and lists dynmically. Further below is the code I have

thus far; most of it taken from the example. I think I understand what is happening up to this point however I don't undstand

what to pass to the bindSelectedKey to get the "response_text" shown in the picklist but have the "response_value" stored as the

selected option.

Any help would be much appreciated.

/Greg

C_Quest_Resp (0..n, s=true)
 - question_text
 - ...
 - ...
 + Responses (0..n, s=true)
    - response_text
    - response_value	
    - ...

// Multiple questions each having an element (Responses) which contains list of applicable responses.



 if (firstTime) {
    	
		IC_quest_respElement qNode;
		int noQuestions = wdContext.nodeC_quest_resp().size();
		
		for ( int i = 0; i < noQuestions; i++ ) {
			
			qNode = wdContext.nodeC_quest_resp().getC_quest_respElementAt(i);
			
			IWDDropDownByKey dropDown = (IWDDropDownByKey)view.createElement(IWDDropDownByKey.class,
			                                                                 "inp" + i );

			/** Trying to understand how I will handling binding. **/											 
			// dropDown.bindSelectedKey()
			
			
		}
    	
    }

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

1. Map the context attribute "response_text" to the bindSelectedKey property of DDBK.

if(firstTime)

{

IWDAttributeInfo attributeInfo = wdContext.nodeResponses().getNodeInfo().getAttribute(IPrivate<view>.IResponsesElement.RESPONSE_TEXT);

IWDDropDownByKey DDBK = (IWDDropDownByKey)view.createElement(IWDDropDownByKey.class,"DDBKsample");

DDBK.bindSelectedKey(attributeInfo);

IWDTransparentContainer container = (IWDTransparentContainer)view.getRootElement();

container.addChild(DDBK);

// now call the method of component controller to populate the data inside the DDBK

wdThis.getComponentController.populateDDBK();

}

//create a method in component controller say "populateDDBK"

// use simple value set to populate the values in the DDBk with 'response_text' as the list value and

// 'response_value' as the key of the selected 'response_text'

public void populateDDBK()

{

IWDAttributeInfo atrInfo = wdContext.nodeResponses().getNodeInfo().getAttribute(IPrivateTest_DDBK_View.IResponsesElement.RESPONSE_TEXT);

IModifiableSimpleValueSet ValueSet = atrInfo.getModifiableSimpleType().getSVServices().getModifiableSimpleValueSet();

for(int i = 0; i < wdContext.nodeResponses().size();i++)

{

ValueSet.put(wdContext.nodeResponses().getResponsesElementAt(i).getresponse_value(), wdContext.nodeResponses().getResponsesElementAt(i).getresponse_text());

}

}

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you both those were very helpful and exactly what I was looking for. I've awarded points to both.

Thanks again!!!!!

/Greg

Former Member
0 Kudos

But if you already have a context structure where you can bind a DropDownByIndex, why then copy all the node element data into a value set and use DropDownByKey? Makes no sense to me.

Armin

Former Member
0 Kudos

I think you are on the wrong track.

You want to display the list of possible responses for a question in a dropdown list, right?

Change your context structure into something like this:

Questions (node, card=0:N)
- Text (attribute, string)
- Responses (node, card=0:N, singleton=false)
-- Text (attribute, string)

Now, to create questions and responses, you can use code like:

IQuestionsElement q1 = wdContext.createAndAddQuestionsElement();
q1.setText("First question");
IResponsesElement r11 = q1.nodeResponses().createAndAddResponsesElement();
r11.setText("First response to first question");
IResponsesElement r12 = q1.nodeResponses().createAndAddResponsesElement();
r12.setText("Second response to first question");

Now you can use a dropdown list for selecting a question and a second dropdown list for selecting a response by code like this (or better, create them in the IDE):

IWDDropDownByIndex questionSelector = (IWDDropDownByIndex) view.createElement(IWDDropDownByIndex.class, "QuestionSelector");
questionSelector.bindTexts("Questions.Text");
IWDDropDownByIndex responseSelector = (IWDDropDownByIndex) view.createElement(IWDDropDownByIndex.class, "ResponseSelector");
responseSelector.bindTexts("Questions.Responses.Text"); 

Additionally, assign an action to the "onSelect" event of the question selector to trigger a server roundtrip when the selection changes. This leads to a change of the lead selection in node "Questions" which in turn leads to filling the second dropdown list with the responses for the selected question.

Armin