on 10-24-2007 1:00 PM
I've created a method in a controller as explained on and I want to call this method in a view.
The problem is the formal parameter and return type are of the type IPublic<controllername>.I<nodename>Element (from the context of the controller) and the parameter I want to pass in the view, is of IPrivate<viewname>.I<nodename>Element (from the context of the view, which is mapped from the controller context)
The purpose of the method is to calculate/find a value for the given parameter. I need to recalculate it in the view, and to avoid having duplicate code, I would like to use the same method.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
If its just to calculate the value of a particular input then pass the input as integer or string to the type of your context attribute instead of passing the attribute itself and in that parameter you can pass the value
Assume value is the name of your atttribute in view and controller of type int.
eg. calculate(int arg);
this is the method in controller.
you can pass the value from view as:
wdThis.wdget<component controller>controller().<methodname>(wdContext.currentContextElement().getValue());
in your calculate method if you are changing then this value will automatically be reflected in view too as it is mapped.
Regards,
Murtuza
In both controller and view, I loop over all elements of the node, to do some different stuff with them. The only duplicate code I would need is to calculate for every element, the previous (based on those Dates) element. To calculate this, I again loop over all the elements, comparing them with the element currently used in the outer loop.
Perhaps I'm making things too difficult, but I'm a Web Dynpro rookie.
See, if you have mapped your view and controller context then even if you perform some operation either in view or in controller, the value of the context would be changed at both the places.
The method that you are creating in controller will update the context will even affect the context of the view.
It seems that you are confused somewhere or may be I am not getting your problem.
Regards,
Murtuza
I realize both places are changed. But the method I'm trying to call does not set any values, it just returns another element. Based on the values of this returned element I will do some stuff.
Does this mean I have to move all the code that uses the returned element to my controller implementation?
Message was edited by:
Lieven De Keyzer
Is the problem in the return type of the method. You are performing some operation and after that want to return some elements to your view that you have already mapped.
I guess if this is the scenario then there would be problem in the context mismatch for both view and controller.
If its feasible then you can return the index number of the element within the node and in the view taking that index number operate on the node.
Regards,
Murtuza
Hi Lieven,
If your problem is with the parameter and the return type
Use the generic approach.
Use : <b>IWDNodeElement</b> instead of
IPublic<controllername>.I<nodename>Element (from the context of the controller) and the parameter I want to pass in the view, is of IPrivate<viewname>.I<nodename>Element (from
and use the generic methods to access the attributes.
<b> getAttributeValue(attributeName)</b>
<b>setAttributeValue(attributeName, value)</b>
Ex:
public com.sap.tc.webdynpro.progmodel.api.IWDNodeElement testMethod( com.sap.tc.webdynpro.progmodel.api.IWDNodeElement nodeElement ) {
//@@begin element()
// accessing attributes
Object obj = nodeElement.getAttributeValue("attributeName");//Your attribute Name
nodeElement.setAttributeValue("attributeName", obj); // your attribute Name and the value for the attribute
return nodeElement; //Example
//@@end
}
Regards
Ayyapparaj
Hi! Liven,
if you have mapped the context of view and controller then why r u passing that parameter? you will get the same value in controller context and view context.so i will suggest you to take the parameter value from the controller context only.
regards,
Mithieshwar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.