on 10-31-2006 5:47 AM
Hi,
In Web Dynpro, is there a way to get the Parent node of the Current Child node selected???(in both recursive and non-recursive trees)
Thx in adv.
Regards,
harshada.
harshada,
Try
final IWDNodeElement el = <...>;
final IWDNodeElement parent = el.node().parentElement();
Valery Silaev
SaM Solutions
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi valery,
just had a doubt in ur solution...
e1 is the Node Element that you are <u>creating</u> using
<b>final</b> IWDNodeElement el = <...>;
but i want to get the parent node of the <u>current</u> child node that is selected (the current child node that the user has clicked ...'lead selection').
Solution expected from all!!!...
thx
regards,
harshada
harshada,
1. I'm not creating element, this could be wdContext.node<YourNodeName>().getCurrentElement()
2. In general, there is no such thing as <i>current child node</i>. Could you explain what do you mean? Better with example...
Valery Silaev
SaM Solutions
thnks valery!!
ur solution wrked ..but a small glitch.....
its not giving the immediate parent node.
i.e.
the main node is gettin displayed for any child nodes.
Example--
Suppose ther are two main nodes Node0 and Node1.
Node0 contains subnodes Subnode0.0 and this subnode again further contains subnodes Subnode0.0.0,Subnode0.0.1
..and so on ....Similar for Node1...
Now when i click on Subnode0.0.0, I shud get its parent node as Subnode0.0 but instead I get Node0 ..everytime and for all the children of Node0...similarly for Node1...
How can I get the immediate parent node (i.e I should get Subnode0.0 as parent node for child node Subnode0.0.0,Subnode0.0.1 .....and so on..)...
Any solutin???...
Regards,
harshada.
hi valery,
ths is the code dt i have written in the OnAction event
Context
TreeNode
Child
text
prnt
public void onActionGetParentNode(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String selectedElement )
{
//@@begin onActionGetParentNode(ServerEvent)
IWDNodeElement e = wdContext.nodeTreeNode().nodeChild().getCurrentElement();
IWDNodeElement p = e.node().getParentElement();
String s = p.toString();
wdContext.currentContextElement().setPrnt(s);
//@@end
}
harshada,
Your code is broken. Expression wdContext.nodeTreeNode().nodeChild().getCurrentElement() returns current element for second level node that corresponds always to currently selected element in first level node. Hence you may observe the behavior mentioned.
Try for example
wdContext.nodeTreeNode().getElementAt(1).nodeChild().getCurrentElement(); -- this will return child of second element in parent.
To correctly get element on which event occurs, make selectedElement parameter to be of IWDNodeElement type, add necessary mapping in wdDoModifyView and then use
selectedElement.node().getParentElement();
Valery Silaev
SaM Solutions
i did the parameter mapping in wdDoModifyView().......
for onAction() event...
public static void wdDoModifyView(IPrivateTreeExample1View wdThis, IPrivateTreeExample1View.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
try
{
if ( firstTime)
{
IWDTreeNodeType nodeType = (IWDTreeNodeType )view.getElement("TreeNode");
nodeType.mappingOfOnAction().addSourceMapping("path","selectedElement");
}
}
catch(Exception e)
{
e.getMessage();
}
//@@end
}
I have defined the parameter 'selecteElement'in the action for onAction()...its of type IWDTreeNodeElement...
(No need of defining parameter 'path' newer na??...
its inbuilt rite ....related to the UI Element .....)
Then i did .........
selectedElement.node().getParentElement();
in the onAction() event.......
Its giving Null Pointer Exception error!!
What to dO???
regargds,
harshada
harshada,
Your post contains a lot of errors
With all this bagage you even hardly can build project.
<i>I have defined the parameter 'selecteElement'...</i>
<b>selectedElement</b> actually, check that you didn't mistype parameter name in action.
<i>...in the action for onAction()...its of type IWDTreeNodeElement...</i>
What is IWDTreeNodeElement??? It should be either <b>IWDNodeElement</b> or type of element in your context: pckg.IPrivate<ViewControllerName>.I<NodeName>Element. Do you in fact use correct class?
<i>(No need of defining parameter 'path' newer na??...
its inbuilt rite ....related to the UI Element .....) </i>
Yes, you do not need to add "path" parameter.
Valery Silaev
SaM Solutions
P.S. I'm sure you've read this before, but anyway: <a href="http://help.sap.com/saphelp_nw04/helpdata/en/d4/69ea3d5506fb34e10000000a114084/frameset.htm">Web Dynpro TreeNodeType API - IWDTreeNodeType</a>
valery,
Sorry for the numerous typos!!....
I made the type of 'selectedElement' parameter as 'ITreeNodeElement' (com.sap.trees1.wdp.IPrivateTreeExample1View.ITreeNodeElement)
(TreeNode is the node defined in the context under which I have defined the recursive child node.)
and then in the action event I write
<b>public void onActionGetParentNode</b>(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.sap.trees1.wdp.IPrivateTreeExample1View.ITreeNodeElement selectedElement )
{
//@@begin onActionGetParentNode(ServerEvent)
IWDNodeElement e = selectedElement.node
().getParentElement();
String s = e.toString();
wdContext.currentContextElement().setPrnt(s);
//@@end
}
writing ths code is givin Null Pointer Exception error!!!!!.......
so instead of IWDNodeElement i tried using used ITreeNodeElement....
IPrivateTreeExample1View.ITreeNodeElement pnode = selectedElement.node().getParentElement();
String s = pnode.toString();
the above code is showing errors
<i>(cannot convert IWDNodeElementy to IPrivateTreeExample1View.ITreeNodeElement....error is in the first of the above two lines. )</i>
and this...............
<i>(No need of defining parameter 'path' newer na??...
its inbuilt rite ....related to the UI Element .....)</i>
newer--->anywhere!!
regards,
harshada.
detailed error....
The initial exception that caused the request to fail, was:
java.lang.NullPointerException
at com.sap.trees1.TreeExample1View.onActionGetParentNode(TreeExample1View.java:217)
at com.sap.trees1.wdp.InternalTreeExample1View.wdInvokeEventHandler
(InternalTreeExample1View.java:167)
at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)
... 23 more
Detailed Exception Chain
java.lang.NullPointerException
at com.sap.trees1.TreeExample1View.onActionGetParentNode(TreeExample1View.java:217)
at com.sap.trees1.wdp.InternalTreeExample1View.wdInvokeEventHandler(InternalTreeExample1View.java:167)
at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)
at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)
at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)
at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)
at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)
at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)
at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:248)
at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)
at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)
at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)
at
javax.servlet.http.HttpServlet.service HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at
com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at
java.security.AccessController.doPrivileged(Native Method)
at
com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:95)
at
com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:160)
do these errors make any sense......???!!!!!
regards,
harshada.
hi valery,
Under the Tree UI element there is just one TreeNodeType
child (control).
Both the Tree UI Element and the TreeNodeType are bound to 'TreeNode' ('TreeNode' is the node under context which has the the Recursive child 'Child') by the dataSource property in the Layout.
i.e against the dataSource property the context variable 'TreeNode' is selected.
Is the code for initializing the Tree written in wdDoINit()proper???
public void wdDoInit()
{
//@@begin wdDoInit()
IPrivateTreeExample1View.ITreeNodeElement l1ele;
//wdContext.nodeTreeNode().setLeadSelection(-1);
//wdContext.nodeTreeNode().nodeChild().setLeadSelection(-1);
for (int i = 0; i < 2; i++)
{
l1ele = wdContext.createTreeNodeElement();
l1ele.setText("Node" + i);
wdContext.nodeTreeNode().addElement(l1ele);
for (int j = 0; j < 4; j++)
{
IPrivateTreeExample1View.ITreeNodeElement l2ele = l1ele.nodeChild().createTreeNodeElement();
l2ele.setText("SubNode" + i + "." + j);
l1ele.nodeChild().addElement(l2ele);
for ( int k = 0; k < 6; k++)
{
IPrivateTreeExample1View.ITreeNodeElement l3ele = l2ele.nodeChild().createTreeNodeElement();
l3ele.setText("Subnode" + i + "." + j + "." + k);
l2ele.nodeChild().addElement(l3ele);
for ( int l = 0; l < 8; l++)
{
IPrivateTreeExample1View.ITreeNodeElement l4ele = l3ele.nodeChild().createTreeNodeElement();
l4ele.setText("Subnode" + i + "." + j + "." + k + "." + l);
l3ele.nodeChild().addElement(l4ele);
}
}
}
}
//@@end
}
........and in the Event property of TreeNodeType, have set the GetParentNode() action against onAction.
harshada
User | Count |
---|---|
81 | |
25 | |
12 | |
9 | |
7 | |
6 | |
5 | |
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.