cancel
Showing results for 
Search instead for 
Did you mean: 

Problem recovering selected key from a dynamic element

Former Member
0 Kudos

Hi,

I nearly finished with my applicatio but I have problem trying to save the values selected by the user in the form. The form is basically populated with radiobuttons, each radiobutton is binded to a dynamic node.

Creation of dynamic node:


IWDNodeInfo node = wdContext.getNodeInfo().addChild("DynamicNode",null,true,true,false,false,false,true,null,null,null);
for (int i=0; i<dataSalidaNode.size(); i++){
node.addAttribute("str"+dataSalidaNode.getAppraisal_DataDetailsOutElementAt(i).getCounter(), "com.sap.dictionary.string");
wdContext.currentZhr_Bapi_App_Scale_Getdetail_InputElement().setElement_Id(elementId);
wdContext.currentZhr_Bapi_App_Scale_Getdetail_InputElement().setElement_Type(typeId);
wdContext.currentZhr_Bapi_App_Scale_Getdetail_InputElement().setPlan_Version("01");

//Launch a RFC to populate the dynamic node with the selectable radiobutton options
				wdThis.wdGetBapiEvaluacionesCust0Controller().executeZhr_Bapi_Appraisal_Scale_Getdetail_Input();

	for (int j=0; j<wdContext.nodeOutputScaleOut().
nodeProficiencies_QualityScaleOut().size(); j++){
	IWDAttributeInfo info= node.getAttribute("str"+
dataSalidaNode.getAppraisal_DataDetailsOutElementAt(i).getCounter());
	ISimpleTypeModifiable stm=info.getModifiableSimpleType();
	IModifiableSimpleValueSet svs= stm.getSVServices().getModifiableSimpleValueSet();
	svs.put(""+j, wdContext.nodeOutputScaleOut().nodeProficiencies_QualityScaleOut().
getProficiencies_QualityScaleOutElementAt(j).getRating_Text());						
}
}

This way I pre-select a radiobutton option if the it returns previously selected from the RFC.

attributeInfo = wdContext.getNodeInfo().getChild("DynamicNode").getAttribute("str"+c.getCounter());
ISimpleTypeModifiable stm=attributeInfo.getModifiableSimpleType();
IModifiableSimpleValueSet svs=stm.getSVServices().getModifiableSimpleValueSet();
theRadioGroup.setSelectedKey(svs.getKey(c.getRating_text()).toString());

So the problem comes when I try to save my form with an action. I don't know how to recover the selectedkey.


Zhr_Bapi_Set_App_Values_Input input = new Zhr_Bapi_Set_App_Values_Input();
input.setE_Appraisal_Id("01");
input.setE_Pernr("01008355");
input.setE_Appraisal_Id("50085566");
Bapiappdata obj = new Bapiappdata();
for (int i=0; i<count; i++){
	// num is the selected key
	BigDecimal num = new BigDecimal(????);
	obj.setCounter(i);
	obj.setRating(num);
	input.addAppraisal_Data(obj);
	wdContext.nodeZhr_Bapi_Set_App_Values_Input().bind(input);
	wdThis.wdGetBapiEvaluacionesCust0Controller().executeZhr_Bapi_Set_App_Values_Input();
}

Thanks in advance for any hint you can provide me,

Joan

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Instead of just setting the selected key you have to provide a context attribute and bind the selected key property to that attribute. Then you can read the attribute value (of the containing context element) to get the currently selected key.

Armin

Former Member
0 Kudos

Thanks both for your comments. I modified my code like this:


....
ISimpleTypeModifiable stm=attributeInfo.getModifiableSimpleType();
IModifiableSimpleValueSet svs=
stm.getSVServices().getModifiableSimpleValueSet();																
theRadioGroup.setSelectedKey(svs.getKey(c.getRating_text()).toString());

IWDNodeInfo node = wdContext.getNodeInfo().getChild("DynamicNode");
node.addAttribute("sol"+c.getCounter(), "com.sap.dictionary.string");
IWDAttributeInfo info= node.getAttribute("sol"+c.getCounter());
ISimpleTypeModifiable stm2=info.getModifiableSimpleType();
IModifiableSimpleValueSet svs2= stm.getSVServices().getModifiableSimpleValueSet();
svs2.put(""+0, svs.getKey(c.getRating_text()).toString())


....
for (int i=0; i<count; i++){
	// num is the selected key
	attributeInfo = wdContext.getNodeInfo().getChild("DynamicNode").getAttribute("sol"+i);
	ISimpleTypeModifiable stm=info.getModifiableSimpleType();
	IModifiableSimpleValueSet svs= stm.getSVServices().getModifiableSimpleValueSet();
	svs.getKey(c.getRating_text()).toString()
	BigDecimal num = new BigDecimal(svs.getKey(c.getRating_text()).toString());
	obj.setCounter(i);
	obj.setRating(num);
	input.addAppraisal_Data(obj);
	wdContext.nodeZhr_Bapi_Set_App_Values_Input().bind(input);
	wdThis.wdGetBapiEvaluacionesCust0Controller().executeZhr_Bapi_Set_App_Values_Input();
}

I'm still having some problems but with Armin's hint I think I going to solve it.

Answers (1)

Answers (1)

michael_pang4
Active Participant
0 Kudos

Hi Joan,

Perhaps you can try this.

IWDNode dynNode = wdContext.getChildNode("DynamicNode", 0);

IWDNodeElement currentElement = dynNode.getCurrentElement()

String YOUR_KEY = currentElement.getAttributeAsText("str"+

dataSalidaNode.getAppraisal_DataDetailsOutElementAt(i).getCounter());

Cheers

Michael.