on 10-02-2008 11:39 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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???
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
At which line number is the null pointer exception?. Check your error description, and see the line number and method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.