on 06-25-2008 10:41 AM
Hi all,
I've a problem that is troubling me.
I'm developing a dynamic form which mainly uses radiobuttongroupsbykey, initially I recover with a RFC the options of every question and I store it into a node ("DynamicNode.str.xxx") that I use later.
This part works correctly, the radiobuttons are displayed correctly, the problem comes when I try to set a selected option. If the question has a selected answer c.getRating_text has a length superior to 1, but nothing happens. c.getRating_text contains the selected option, it's a string which is exactly one the radiobutton options.
Can you help me? I can provide you more code if you need it.
wdDoInit
=======
.....
wdContext.currentZhr_Bapi_Appraisal_Getdetail_InputElement().setAppraisal_Id(codeBapi2);
wdContext.currentZhr_Bapi_Appraisal_Getdetail_InputElement().setPernr(pernBapi2);
String planVersion = "01";
wdContext.currentZhr_Bapi_Appraisal_Getdetail_InputElement().setPlan_Version(planVersion);
// execute RFC
wdThis.wdGetBapiEvaluacionesCust0Controller().executeZhr_Bapi_Appraisal_Getdetail_Input();
IAppraisal_DataDetailsOutNode dataSalidaNode =
wdContext.nodeOutputDetailsOut().nodeAppraisal_DataDetailsOut();
// I use a hashmap to create the dynamic nodes that contain the posible answers
HashMap map = new HashMap();
IWDNodeInfo node = wdContext.getNodeInfo().addChild("DynamicNode", null,
true,true,false,false,false,true,null,null,null);
for (int i=0; i<dataSalidaNode.size(); i++){
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());
}
Node n;
// I have two type of elements parents (Grup) and childs (Criteri--->VC)
if(element.getElement_Type().equals("VC")){
n = new Criteri(element);
} else{
n = new Grup(element);
}
IAppraisal_DataDetailsOutElement dataSalidaElement =
wdContext.nodeOutputDetailsOut().nodeAppraisal_DataDetailsOut().
getAppraisal_DataDetailsOutElementAt(i);
String counter = dataSalidaElement.getCounter();
String parent = dataSalidaElement.getParent();
// the first element I read from the output of the RFC has 0000 in its counter
if(parent.equals("0000")) {
root = n;
}else if (!parent.equals("0000")){
Node nodeParent = (Node) map.get(parent);
nodeParent.addChild(n);
}
map.put(counter,n);
}
....
wdModifyView
===========
private static void pintarForm(Node n, IPrivateDetalleView.IContextNode wdContext,
com.sap.tc.webdynpro.progmodel.api.IWDView view, IPrivateDetalleView wdThis,
IWDUIElementContainer containerParent) {
if(n instanceof Grup) {
Grup g = (Grup) n;
for(int i=0; i< g.getChilds().size(); i++) {
pintarForm((Node)g.getChilds().get(i), wdContext, view, wdThis, theGroup);
}
} else {
Criteri c = (Criteri) n;
// I create radiobutton
IWDRadioButtonGroupByKey theRadioGroup =(IWDRadioButtonGroupByKey) view.
createElement(IWDRadioButtonGroupByKey.class, "rbg" + c.getCounter());
// I populate radiobutton with options
theRadioGroup.bindSelectedKey("DynamicNode."+"str"+c.getCounter());
if (c.getRating_text().length()>1){
// I select predifined answer?
theRadioGroup.setSelectedKey(c.getRating_text());
}
}
}
Edited by: Joan Roda on Jun 25, 2008 2:14 PM
Edited by: Joan Roda on Jun 25, 2008 2:16 PM
Edited by: Joan Roda on Jun 25, 2008 2:31 PM
Hi Joan,
The solution is pretty simple. When you have RadioButtonGroupBy Key you should use setSelected Key(index). Just change the code like this:
wdDoModifyView
============
...
if (c.getRating_text().length()>1){
// I select predifined answer?
theRadioGroup.setSelectedKey(<indexOfAppropriateText>);
}
...
<indexOfAppropriateText> should be the value of j from the following piece of code
wdDoInit
========
...
IModifiableSimpleValueSet svs=stm.getSVServices().getModifiableSimpleValueSet();
svs.put(""+j, wdContext.nodeOutputScaleOut().nodeProficiencies_QualityScaleOut().
getProficiencies_QualityScaleOutElementAt(j).getRating_Text());
...
To achieve this you need to store the mapping between c.getRatingText value and j value.
Good luck
Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Ivan. I'm trying to get that value with the following code, but it returns me a NullPointer exception in the second line (attributeInfo.getModifiableSimpleType()), anyway I'll continue revising my code. Thanks again, I was stuck for days.
PS: c.getRating() returns the key position of the selected option.
attributeInfo = wdContext.getNodeInfo().getAttribute("DynamicNode."+"str"+c.getCounter());
ISimpleTypeModifiable stm=attributeInfo.getModifiableSimpleType();
IModifiableSimpleValueSet svs=stm.getSVServices().getModifiableSimpleValueSet();
theRadioGroup.setSelectedKey(svs.getText(""+c.getRating().intValue()));
Hi Joan,
If you got the NullPointerException at the second line it means that the attribute with the name "DynamicNode.""str"c.getCounter() doesn't exists. So I would suggest to check for null value before doing the second line:
attributeInfo = wdContext.getNodeInfo().getAttribute("DynamicNode."+"str"+c.getCounter());
if (null != attributeInfo){
ISimpleTypeModifiable stm=attributeInfo.getModifiableSimpleType();
IModifiableSimpleValueSet svs=stm.getSVServices().getModifiableSimpleValueSet();
theRadioGroup.setSelectedKey(svs.getText(""+c.getRating().intValue()));
}
... and again the code on the forth line is not correct, it should be like this (assuming c.getRating().intValue() is equals to j😞
theRadioGroup.setSelectedKey(""+c.getRating().intValue());
because svs.getText() will return you the text and not the key. To get the key use svs.getKey(c.getRating()). The point is that the value stored in the appropriate context attribute is the key, but the value displayed on view is the text.
Good luck
Ivan
That was it. I really thank you!
attributeInfo = wdContext.getNodeInfo().getChild("DynamicNode").getAttribute("str"+c.getCounter());
if (null != attributeInfo){
ISimpleTypeModifiable stm=attributeInfo.getModifiableSimpleType();
IModifiableSimpleValueSet svs=stm.getSVServices().getModifiableSimpleValueSet();
theRadioGroup.setSelectedKey(svs.getKey(c.getRating_text()).toString());
}
User | Count |
---|---|
83 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.