cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with WebDynpro Application

Former Member
0 Kudos

Hello experts,

I have a big problem with my WebDynprot application.

I want to create a tree which shoul hold a company-structure like

CompanyName->Department->Area-Employee.

I have created a medthod called createTestdaten() which shall generate some testdata.

Here the source code:

public void createTestdaten( )

{

//@@begin createTestdaten()

wdContext.nodeOrg_Struktur().getElementAt(0);

IOrg_StrukturNode myOrgNode = wdContext.nodeOrg_Struktur();

IOrg_StrukturElement myRootElement = myOrgNode.createOrg_StrukturElement();

myRootElement.setAbteilung("Companyname");

myRootElement.setParentId("0000");

myRootElement.setObjId("1000");

myRootElement.setHasChildren(true);

myRootElement.setIgnoreAction(false);

myRootElement.setIsExpanded(true);

myOrgNode.addElement(myRootElement);

IOrg_StrukturElement myOrgElement2 = myOrgNode.createOrg_StrukturElement();

myOrgElement2.setAbteilung("TIS");

myOrgElement2.setParentId("1000");

myOrgElement2.setObjId("1100");

myOrgElement2.setHasChildren(true);

myOrgElement2.setIgnoreAction(false);

myOrgElement2.setIsExpanded(false);

myOrgNode.addElement(myOrgElement2);

IOrg_StrukturElement myOrgElement3 = myOrgNode.createOrg_StrukturElement();

myOrgElement3.setAbteilung("PCS");

myOrgElement3.setParentId("1100");

myOrgElement3.setObjId("1120");

myOrgElement3.setHasChildren(true);

myOrgElement3.setIgnoreAction(false);

myOrgElement3.setIsExpanded(false);

myOrgNode.addElement(myOrgElement3);

IOrg_StrukturElement myOrgElement4 = myOrgNode.createOrg_StrukturElement();

myOrgElement4.setAbteilung("Employee 1");

myOrgElement4.setParentId("1120");

myOrgElement4.setObjId("1121");

myOrgElement4.setHasChildren(false);

myOrgElement4.setIgnoreAction(true);

myOrgElement4.setIsExpanded(false);

myOrgNode.addElement(myOrgElement4);

//@@end

}

After the creation of the Testdata I call a method SetRootId:

private void setRootID(){

//rootID setzen

if(wdContext.nodeOrg_Struktur().size()>0)

{

IOrg_StrukturElement myRootElem = (IOrg_StrukturElement) wdContext.nodeOrg_Struktur().getOrg_StrukturElementAt(0);

wdContext.nodeSingle_Node().currentSingle_NodeElement().setRootId(myRootElem.getObjId());

wdContext.nodeSingle_Node().currentSingle_NodeElement().setAbteilung(myRootElem.getAbteilung());

..........

Both Methods are called from the WdDoInit() of the Controller.

The Layout of my View Contains Treestructure element:

The Problem is that it seems that someting is wrong with my addChildren Method.

Here the Code:

public void addChildren( mhp.de.tutorials.wd.mhp_org.wdp.IPrivateOrgView.IOrg_TreeElement element )

{

//@@begin addChildren()

String parentId = element.getParentId();

wdContext.nodeOrg_Tree().invalidate();

IOrg_TreeNode myOrgNode = wdContext.nodeOrg_Tree();

int size = wdThis.wdGetOrgcompController().wdGetContext().nodeOrg_Struktur().size();

for(int i=0; i<size;i++){

IOrg_StrukturElement myTableElem = (IOrg_StrukturElement)wdContext.nodeOrg_Struktur().getElementAt(i);

if(myTableElem.getParentId().equalsIgnoreCase(parentId)){

IOrg_TreeElement myOrgElement = myOrgNode.createOrg_TreeElement();

myOrgElement.setAbteilung(myTableElem.getAbteilung());

myOrgElement.setObjId(myTableElem.getObjId());

myOrgElement.setParentId(parentId);

myOrgElement.setHasChildren(myTableElem.getHasChildren());

myOrgElement.setIgnoreAction(myTableElem.getIgnoreAction());

myOrgElement.setIsExpanded(myTableElem.getIsExpanded());

myOrgNode.addElement(myOrgElement);

}

}

//@@end

}

It seems that something is wrong with my if clause. At Runtime appears a nullPointerException.

Could someone please help me with that project.

Many thanks!!!

Regards Marco

Edited by: Marco Gennari on Oct 2, 2008 12:39 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Looks like u are using a recursive node

for ur child node

in this case make sure that u have binded the repeated node property of the recursive node(child node) to the parent.

Regards,

Satya.

Answers (2)

Answers (2)

Former Member
0 Kudos

Where exactly does the NPE occur?

Maybe you should use supply-functions in your implementation according to the following scheme:

Context:


Companies (node, c=0:n, sf=supplyCompanies)
-- companyName (string)
-- Departments (node, c=0:n, singleton=false, sf=supplyDepartments)
---- departmentName (string)
---- Areas (node, c=0:n, singleton=false, sf=supplyAreas)
------ areaName (string)
------ Employees (node, c=0:n, singleton=false, sf=supplyEmployees)
-------- name (string)

The implementation of the supply functions should be clear. For example


supplyDepartments(IDepartmentsNode node, ICompaniesElement parentElement)
{
  List/*<DepartmentData>*/ result = queryDepartmentsForCompany(parentElement.getCompanyName());
  for (Iterator it = result.iterator(); result.hasNext(); )
  {
    DepartmentData d = (DepartmentData) result.next();
    IDepartmentsElement treeNode = node.createDepartmentsElement();
    node.addElement(treeNode);
    treeNode.setDepartmentName(d.getName());
    /* set other attributes */
  }
}

Armin

Former Member
0 Kudos

The NullPointerException appears at following code statement:

if(myTableElem.getParentId().equalsIgnoreCase(parentId))

Is it because my mytableElem is Empty?

But mytableElem shouldn't be empty because I add the first Node to my Tree in the wdDoInit() like:

IOrg_TreeNode rootNode = wdContext.nodeOrg_Tree();

IOrg_TreeElement rootElement;

rootElement = rootNode.createOrg_TreeElement();

rootElement.setObjId(wdContext.nodeSingleNode().currentSingleNodeElement().getRootId());

rootElement.setParentId(wdContext.nodeSingleNode().currentSingleNodeElement().getRootId());

rootElement.setAbteilung(wdContext.nodeOrg_Struktur().currentOrg_StrukturElement().getAbteilung());

rootElement.setHasChildren(true);

rootElement.setIgnoreAction(false);

rootElement.setIsExpanded(true);

wdContext.nodeOrg_Tree().addElement(rootElement);

addChildren(rootElement);

Any Ideas???

Former Member
0 Kudos

Hi.

Your code not right fo build tree structure. You must use recursive context node. sdn have too many help files for this.

-


public void createTestdaten( )

{

//@@begin createTestdaten()

wdContext.nodeOrg_Struktur().getElementAt(0); <--- if node Org_Struktur have cardinatky 0..n or 0..1 you hava NullPointer exception in this line, becouse node is empty

Former Member
0 Kudos

Apart from the fact that your code is unclear to me I would say that the "parentId" attribute value is NULL. The node element itself cannot be NULL because your are iterating over all node elements in a node and a node never has NULL entries.

Armin

former_member187439
Active Participant
0 Kudos

At which line number is the null pointer exception?. Check your error description, and see the line number and method.