cancel
Showing results for 
Search instead for 
Did you mean: 

Different method parameters in Controller and View

Former Member
0 Kudos

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)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Murtuza,

I will need the whole contextElement, as I will send it the node( ) method, loop over the node and compare the element to other elements, and finally return (based on some Date attributes) another contextElement.

Former Member
0 Kudos

Hi,

If you want to access the complete node then that is available in your controller. I can't understand the need to pass it again from view to controller.

Regards,

Murtuza

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Both in return type and parameter, but I guess I could use the index number for both elements.

Former Member
0 Kudos

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

Answers (1)

Answers (1)

Former Member
0 Kudos

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