Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Error while creating UI dynamically

Hi all,

Look at the following code

  public static void wdDoModifyView(IPrivateDataScreen wdThis, IPrivateDataScreen.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
  {
    //@@begin wdDoModifyView
    try {
	    if (firstTime) {
			IPrivateDataScreen.ITemplateColumnNode sourceColNode = wdContext.nodeTemplateColumn();			
			IWDGroup viewCont = (IWDGroup) view.getElement("grpView");
			
			for (int i = 0; i < sourceColNode.size(); i++) {
				IPrivateDataScreen.ITemplateColumnElement sourceColElement = (IPrivateDataScreen.ITemplateColumnElement) sourceColNode.getElementAt(i);
				
				<b>IWDLabel label = (IWDLabel) view.createElement(IWDLabel.class, "Label" + i);</b>
				if (sourceColElement.getFieldDesc() == null)
					label.setText(sourceColElement.getFieldCode());
				else
					label.setText(sourceColElement.getFieldDesc());
				viewCont.addChild(label);
				
				switch (Integer.parseInt(sourceColElement.getControlType())) {
					case 0:	// Text Field
						sourceColNode.getNodeInfo().addAttribute("CurrentValue", "com.sap.dictionary.string");
						IWDInputField inputField = (IWDInputField) view.createElement(IWDInputField.class, "Element" + sourceColElement.getFieldDesc());
						sourceColElement.setAttributeValue("CurrentValue", sourceColElement.getDefaultValue());
						inputField.bindValue("TemplateColumn.CurrentValue");
						viewCont.addChild(inputField);
						break;				
					case 1: // Check Box
						sourceColNode.getNodeInfo().addAttribute("CurrentValue", "com.sap.dictionary.boolean");
						IWDCheckBox checkBox = (IWDCheckBox) view.createElement(IWDCheckBox.class, "Element" + sourceColElement.getFieldDesc());
						sourceColElement.setAttributeValue("CurrentValue", Boolean.valueOf(sourceColElement.getDefaultValue()));
						checkBox.bindChecked("TemplateColumn.CurrentValue");
						viewCont.addChild(checkBox);
						break;
					case 2: // Drop Down List Box
						sourceColNode.getNodeInfo().addAttribute("CurrentValue", "com.sap.dictionary.string");
						IWDDropDownByKey ddbk = (IWDDropDownByKey) view.createElement(IWDDropDownByKey.class, "Element" + sourceColElement.getFieldDesc());
						sourceColElement.setAttributeValue("CurrentValue", sourceColElement.getDefaultValue());
						ddbk.bindSelectedKey("TemplateColumn.CurrentValue");
						viewCont.addChild(ddbk);
						break;
					case 3: // Text Area
						sourceColNode.getNodeInfo().addAttribute("CurrentValue", "com.sap.dictionary.string");
						IWDTextEdit textEdit = (IWDTextEdit) view.createElement(IWDTextEdit.class, "Element" + sourceColElement.getFieldDesc());
						sourceColElement.setAttributeValue("CurrentValue", sourceColElement.getDefaultValue());
						textEdit.bindValue("TemplateColumn.CurrentValue");
						viewCont.addChild(textEdit);
						break;
				}
			}
	    }
    }
    catch (WDRuntimeException e) {
		e.printStackTrace();
	}
    catch (NullPointerException e) {
		e.printStackTrace();
	}
    catch (Exception e) {
		e.printStackTrace();
	}	
    //@@end
  }

What I'm trying to create is a dynamic screen in which a user can insert his own data.

The error occurs while itterating the context from which I create the UI in the <b>second time</b>. which means that the first label and UI element are created but when I try to create the second label i get <i>"com.sap.tc.webdynpro.services.exceptions.WDCreationFailedException: Cannot create view element implementation com.sap.tc.webdynpro.clientserver.uielib.standard.impl.Label"</i>(The bold line in the code is where I crash the second time).

What am I doing wrong?

Former Member
Not what you were looking for? View more on this topic or Ask a question