on 11-29-2006 5:14 PM
Hi,
I have some problems in understanding how to access "Value Attributes" from a context.
I like to read some data manually within a method in the custom controller class.
my context looks like this:
Context:
|- Request_xyz (=Model node)
..|- Response (=Model node)
....|- Result (=Model node)
.......- city (=Value Attribute)
.......- country (=Value Attribute)
(... are used as spaces, only for formatting the context for the forum)
But how can I now read/access the string data/values from "city" and "country"? They are filled with data from a webservice.
Thanks a lot for your help.
Best regards
IResultElement result = wdContext.currentResultElement();
if (result != null)
{
result.getCity(); /* get value of attribute */
result.setCity("St. Ingbert"); /* set value of attribute */
}
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Before accessing any value for Result Node Check whether it has some elements or not.
Since it contains single element as u mentioned u can access that element using wdContext.current<node>element().get<attribute>()
if(wdContext.nodeResult()!=null&&wdContext.nodeResult().size()>0)
{
wdComponentAPI.getMessageManager.
reportSuccess(wdContext.currentResultElement().getCity());
}
Hope it helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just tried some ways to receive the value:
This works fine for me:
String city = wdContext.nodeResult().getElementAt(0).getAttributeValue("cITY").toString();
ok, the "0" is hardcoded what is not the best way.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
As you said, because the 0 is hardcoded in your code, it works fine as long as the wsdl returns atleast one element in the result node. This code will throw a nullPointerException if the result node is empty..So, you would have to consider that situation to be sure that your code works ok in all conditions,
Regards
LM
Hi,
Try this,
IWDMessageManager msg = wdComponentAPI.getMessageManager();
for(int i = 0; i<wdContext.nodeResult().size(); i++){
msg.reportSuccess("City: "+wdcontext.nodeResult().getResultElementAt(i).getCity());
msg.reportSuccess("Country: "+wdcontext.nodeResult().getResultElementAt(i).getCountry());
}
Regards,
Aparna .P
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
good
go through these links, i hope these ll help you to solve your probelm.
http://help.sap.com/saphelp_nw04/helpdata/en/1a/ff773f12f14a18e10000000a114084/content.htm
thanks
mrutyun^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there,
I assume the actual context if you are executing a web service would look like this
RootContext
|.|WebserviceRootNode
..|- Request_xyz (=Model node)
..|- Response (=Model node)
....|- Result (=Model node)
.......- city (=Value Attribute)
.......- country (=Value Attribute)
Now after executing the webservice, you need to invalidate the output nodes to get the data to the nodes-like this
wdContext.nodeResponse().invalidate();
wdContext.nodeResult().invalidate();
Then you can access context nodes like this
for(int i=0;i<wdContext.nodeResult().size();i++){
wdContext.nodeResult().setLeadSelection(i);
wdComponentAPI.getMessageManager().reportSuccess(wdContext.currentResultElement().getCity());
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
thanks for your tips. I will try it tomorrow when I have access to my SAP system.
>
> Then you can access context nodes like this
> for(int
> i=0;i<wdContext.nodeResult().size();i++){
> wdContext.nodeResult().setLeadSelection(i);
> wdComponentAPI.getMessageManager().reportSuccess(wdCon
> text.currentResultElement().getCity());
>
ok, sounds good. But this loop doesn't assign the "city"-value attribute-string to a single string-variable, or does it? How can I archieve this?
The webservice only sends back single string-results, no table with several entries.
Thx.
Henning
Henning,
you can do the following.
Considering only one record in result node
String city = wdContext.currentResultElement().getCity();
String country = wdContext.currentResultElement().getCountry();
if you have more than one rows of result then you need to loop through the Result node.
Note: Use this code to access the data only after the web service is executed otherwise you will get NullPointer exception.
I hope this will help you.
Regards,
Anand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
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.