cancel
Showing results for 
Search instead for 
Did you mean: 

Java Web dynpro - Value node Issue.

Former Member
0 Kudos

We have this simple custom webdynpro application that was working fine till application of support stack 11. After the support stack application, it throws error message.

Background of the issue:

This webdynpro application, just fetches the Employee master data through RFC and displays them in a screen for editing.

Code is failing in the code line:  wdContext.currentDataTableElement().getSmoker().equals("X").

When we tried debugging it is found that wdContext.currentDataTableElement()=null; just returing null. We are really not to be find, when this Value node is showing error and when wdContext.currentDataTableElement() cannot be used anywhere in the code.

Please give your thoughts, how we shoul approach this issue.


private void initializeDisplay() {
    boolean result = wdThis.wdGetReadDataController().executeRFC();
    if (restarted) {
     wdContext.nodeDataTable().invalidate();
     wdContext.nodeSubmit_In().invalidate();
     wdContext.nodeSubmit_Out().invalidate();
    }
    handleReturn(infoType, wdContext.nodeE_Return(), false);
    mc.moveCorresponding(
     wdContext.nodeE_Data(),
     wdContext.nodeDataTable(),
     true);
    

//      Set Check Box According to string passed from Smoker field
  wdContext.currentEnableElement().setSmokeree_ind(false);
  wdContext.currentEnableElement().setSmoker_ind(false);
         if (wdContext.currentData_OutElement().getSmokeree().equals("X"))    
        { wdContext.currentEnableElement().setSmokeree_ind(true); }

   if (wdContext.currentDataTableElement().getSmoker().equals("X"))    
     { wdContext.currentEnableElement().setSmoker_ind(true); }

Accepted Solutions (0)

Answers (2)

Answers (2)

monalisa_biswal
Contributor
0 Kudos

hi Harish,

Can you check size for nodes E_Data and DataTable after move corresponding?

Also check if Initialize Lead Selection for DataTable is set to true.

Thanks,

Mona

junwu
Active Contributor
0 Kudos

check if this call is still working

  mc.moveCorresponding(

     wdContext.nodeE_Data(),

     wdContext.nodeDataTable(),

     true);

Former Member
0 Kudos

Hi Jun, Thanks for your reply.

We have checked it and this move corresponding is working fine. But we are nt sure why the wdContext.currentDataTableElement()=null is returing null, instead it should refer to the "DataTable" value node.  Any help or suggestions would be highly helpful.

Thanks,

Harish.

Former Member
0 Kudos

Hi Harish,

what is the cardinality of the "Attributes" node ?

Regards,

ramesh

Former Member
0 Kudos

Hi Ramesh, The cardinality for Attributes is 1:1

And the cardinality for Datatable value node is 0..n, and selection is 0..1

Former Member
0 Kudos

Hi ,

try to use the wdContext.nodeDatatable.getLeadSelection() to access the current selected element of the node.

regards,

ramesh

Former Member
0 Kudos

Thanks Ramesh!

Actually, the code i showed  below is written before the view gets display in the page ( InitializeDisplay() ). So the application fails just before it displays anything in the screen in the lighlighted if condition.

if (wdContext.currentDataTableElement().getSmoker().equals("X"))   

We recently upgraded from 7.00 to 7.02 sp11. I am not sure if this issue realted to that? Anyhelp could be greatly appreciated.

junwu
Active Contributor
0 Kudos

can you show the detail of moveCorresponding

Former Member
0 Kudos

Hi Jun, Please find the move corresponding class code:

Thanks,

Harish.

package com.dcc.services.wd.general.utilities;

import java.lang.reflect.Method;
import java.util.Vector;

import com.sap.tc.webdynpro.progmodel.api.IWDNode;
import com.sap.tc.webdynpro.progmodel.api.IWDNodeElement;

/**
* Class with methods to simulate the MoveCorresponding logic within an ABAP program.
* The moveC method will dynamically map the values that are stored in fields
* under a specified node to the fields of a target node with the same name.
*
*
*/
public class MoveCorresponding {
Vector v1;
/**
  * Method to copy the values from the fields of a source context node
  * to the fields of a target context node with the same name.
  * @param srcObj Originating node for data value transfer.
  * @param trgtObj Target node for data value transfer
  * @param org If true, will reset the internal vector that stores results.
  */
public MoveCorresponding() {
  v1 = null;
}
/**
  * @param srcObj
  * @param trgtObj
  * @param org
  */
public boolean moveCorresponding(
  com.sap.tc.webdynpro.progmodel.api.IWDNodeElement srcEle,
  com.sap.tc.webdynpro.progmodel.api.IWDNodeElement trgtEle) {
  boolean valuesMoved = false;
  String fName = "";
  String mName = "";
  Class srcCl = null;
  Class trgtCl = null;
  srcCl = srcEle.getClass();
  trgtCl = trgtEle.getClass();
  Method[] srcMs = srcCl.getDeclaredMethods();
  for (int smc = 0; smc < srcMs.length; smc++) {
   if (srcMs[smc].getName().startsWith("get")) {
    fName = srcMs[smc].getName().substring(3);
    try {
     boolean skip = false;
     Object result = null;
     try {
      result = srcEle.getAttributeValue(fName);
     } catch (Exception e) {
      // Try again with a lower case
      fName.substring(0, 1).toLowerCase();
      try {
       result = srcEle.getAttributeValue(fName);
      } catch (Exception ex) {
       // Means the source does not have this field
       skip = true;
      }
     }
     if (!skip) {
      trgtEle.setAttributeValue(fName, result);
      valuesMoved = true;
     }
    } catch (Exception e) {
     /// do nothing...
    }
   }
  }
  return valuesMoved;
}
public void moveCorresponding(
  com.sap.tc.webdynpro.progmodel.api.IWDNode srcObj,
  com.sap.tc.webdynpro.progmodel.api.IWDNode trgtObj,
  boolean org,
  boolean targetSafe) {
  String fName = "";
  String mName = "";
  IWDNodeElement srcEle = null;
  IWDNodeElement trgtEle = null;
  IWDNode subSrcNode = null;
  IWDNode subTrgtNode = null;
  Class srcCl = null;
  Class trgtCl = null;
  Method[] mList = null;
  int i = 0;
  String tmp = "";
  String tmp1 = "";
  int pos = 0;
  boolean bAdd = false;
  if (org) {
   if (v1 == null) {
    v1 = new Vector();
   }
   v1.removeAllElements();
  }
  if (!targetSafe) {
   if (trgtObj.getNodeInfo().isMultiple()) {
    while ((!(trgtObj.isEmpty()))) {
     trgtObj.removeElement(trgtObj.getElementAt(0));
    }
   }
  }

  for (int j = 0; j < srcObj.size(); j++) {
   srcEle = srcObj.getElementAt(j);
   if (targetSafe) {
    trgtEle = trgtObj.getElementAt(j);
   } else {
    if (trgtObj.getNodeInfo().isMultiple()
     || ((trgtEle = trgtObj.getCurrentElement()) == null)) {
     try {
      trgtEle = trgtObj.createElement();
     } catch (Exception e) {
      String modelName = trgtObj.getClass().getName();
      try {
       Method[] modelmList =
        trgtObj.getClass().getDeclaredMethods();
       modelName =
        modelName.substring(
         modelName.indexOf("$") + 2,
         modelName.indexOf("Node"));
       modelName = "current" + modelName + "Element";
       for (int mc = 0; mc < modelmList.length; mc++) {
        String typeName = modelmList[mc].getName();
        if (typeName.equalsIgnoreCase(modelName)) {
         Method[] melemList =
          (trgtObj
           .getClass()
           .getDeclaredMethods())[mc]
           .getReturnType()
           .getDeclaredMethods();
         for (int ec = 0;
          ec < melemList.length;
          ec++) {
          String mtypemeth =
           melemList[ec].getName();
          if (mtypemeth
           .equalsIgnoreCase("modelObject")) {
           Class mobj =
            melemList[ec].getReturnType();
           trgtEle =
            trgtObj.createElement(
             mobj.newInstance());
           ec = melemList.length;
           mc = modelmList.length;
          }
         }
        }
       }
      } catch (Exception e1) {
       // do nothing
       String check = e1.getLocalizedMessage();
      }
     }
    }
   }
   bAdd = moveCorresponding(srcEle, trgtEle);
   if (!targetSafe) {
    if ((bAdd && trgtObj.getNodeInfo().isMultiple())
     || (trgtObj.getCurrentElement() == null)) {
     trgtObj.addElement(trgtEle);
    }
   }
  }

  mList = srcObj.getClass().getDeclaredMethods();
  i = 0;
  for (; i < mList.length; i++) {
   mName = mList[i].getName();
   if (mName.startsWith("node")) {
    fName = mList[i].getReturnType().getName();
    fName =
     fName.substring(
      fName.indexOf("$") + 2,
      fName.indexOf("Node"));
    if (!(v1.contains((Object) fName))) {
     if ((subTrgtNode = trgtObj.getChildNode(fName, -1))
      != null) {
      subSrcNode = srcObj.getChildNode(fName, 0);
      moveCorresponding(subSrcNode, subTrgtNode, false);
      v1.add((Object) fName);
     } else {
      String ret =
       getType(mList[i].getReturnType().getName());
      if (!ret.equalsIgnoreCase("")) {
       String nodeName = getNodeName(ret, trgtObj);
       if (!nodeName.equalsIgnoreCase("")) {
        subSrcNode = srcObj.getChildNode(fName, 0);
        subTrgtNode =
         trgtObj.getChildNode(nodeName, -1);
        moveCorresponding(
         subSrcNode,
         subTrgtNode,
         false);
        v1.add((Object) fName);
       }
      }
     }
    }
   }
  }

}
/**
  * @param srcObj
  * @param trgtObj
  * @param org
  */
public void moveCorresponding(
  com.sap.tc.webdynpro.progmodel.api.IWDNode srcObj,
  com.sap.tc.webdynpro.progmodel.api.IWDNode trgtObj,
  boolean org) {
   // Removes the target object elements before trying to fill values
   moveCorresponding(srcObj,trgtObj,org,false);
}
public java.lang.String getNodeName(
  java.lang.String typeName,
  com.sap.tc.webdynpro.progmodel.api.IWDNode trgtObj) {
  //@@begin getNodeName()
  String ret = "";

  try {
   String sType = typeName;
   Method[] mList = trgtObj.getClass().getDeclaredMethods();
   for (int i = 0; i < mList.length; i++) {
    String mName = mList[i].getName();
    if (mName.startsWith("node")) {
     String nName = mList[i].getReturnType().getName();
     String type = getType(nName);
     if (type.equalsIgnoreCase(sType)) {
      nName =
       nName.substring(
        nName.indexOf("$") + 2,
        nName.indexOf("Node"));
      return nName;
     }
    }
   }
  } catch (Exception ee) {
  }
  return ret;
  //@@end
}

public java.lang.String getType(java.lang.String nodeName) {
  //@@begin getType()
  String ret = "";
  try {
   String sType = nodeName;
   Method[] ntypList = Class.forName(sType).getDeclaredMethods();
   sType =
    sType.substring(sType.indexOf("$") + 2, sType.indexOf("Node"));
   sType = "current" + sType + "Element";
   for (int sc = 0; sc < ntypList.length; sc++) {
    String typeName = ntypList[sc].getName();
    if (typeName.equalsIgnoreCase(sType)) {
     Class typeClass = ntypList[sc].getReturnType().getClass();
     Method[] melemList = typeClass.getDeclaredMethods();
     for (int ec = 0; ec < melemList.length; ec++) {
      String mtypemeth = melemList[ec].getName();
      if (mtypemeth.equalsIgnoreCase("modelObject")) {
       String mobjName =
        melemList[ec].getReturnType().getName();
       ret = mobjName;
       ec = melemList.length;
       sc = ntypList.length;
      }
     }
    }
   }
  } catch (Exception e1) {
   // do nothing
  }
  return ret;
  //@@end
}

}