cancel
Showing results for 
Search instead for 
Did you mean: 

binding business methods to model

Former Member
0 Kudos

hi there,

how does it work to be able to bind several business methods to a model? i know how it works for one method, but up to now i found it impossible to use more than one method through the model of a web dynpro project.

how can i address two or more request_ ... nodes of a model (i.e. methods of a webservice) in the component controller?

Accepted Solutions (0)

Answers (1)

Answers (1)

htammen
Active Contributor
0 Kudos

Hi Ilse,

if you have more than one mehtod in your Web Service the model generator will create one Request_... and one Response_... class for each method of the Web Service.

Regards

Helmut

Former Member
0 Kudos

hi helmut,

thanks for your prompt answer. what you wrote to me is not new to me. maybe i didn't`t formulate my question exactly enough.

starting from the front end: as far as i know i can bind a property of a control element in the view (value of input field, value of text view, ..) only to one 'modeltype' (= Request_ ..., Response_ ... how do you call this?). now there may arise situations in which i wish to bind a control property to more than just one 'modeltype', for example if i want to use the value of an input field for more than one method. how can i manage this?

htammen
Active Contributor
0 Kudos

Hi Ilse,

know I understand what you mean.

The way I solved this was by copying the data from one context node that is bound to web service method A to another context node that is bound to web service method B manually.

If anybody does have a declarative solution this is highly welcome.

Regards

Helmut

Former Member
0 Kudos

Hi Ilse,

Helmut is right. There's no declarative solution, since there's no possibility to map nodes and/or attributes to more than one target. Otherwise you could build a "superior" controller C with context attributes bound to the common attributes of controllers A and B.

But there's help from the framework for the copying, look at WDCopyService:


  /**
   * Copies all elements from <code>source</code> to <code>target</code>. 
   * Afterwards <code>source</code> contains as much elements as <code>target</code>,
   * each one either copied via {@link #copyCorresponding(Object, Object)} (if
   * <code>target</code> is a value node) or holding the same model instance (if
   * <code>source</code> and <code>target</code> both are model nodes holding
   * the same class). The lead selection will be copied, too.
   * <p>
   * Note: If you copy a model node to another model node, only the reference to
   * the model instance is copied, but not additional value attributes. Copying
   * a model node to a value node works fine. 
   * @param source The source node
   * @param target The target node
   * @throws WDRuntimeException if <code>target</code> is a model node and 
   *    <code>source</code> is <b>not</b> a model node holding the same class.
   */
  public static void copyElements(IWDNode source, IWDNode target) {
    instance.copyElements(source, target);
  }

  /**
   * Copies all elements from to complete subtree of <code>source</code> to
   * <code>target</code>. This is done by applying {@link #copyElements(IWDNode, IWDNode)}
   * to the nodes and then searching for equally named subnodes and recursively
   * applying <code>copySubtree</code> to them. 
   * @param source The source node
   * @param target The target node
   * @throws WDRuntimeException if {@link #copyElements(IWDNode, IWDNode)}
   *    fails for a node in the subtree.
   */
  public static void copySubtree(IWDNode source, IWDNode target) {
    instance.copySubtree(source, target);
  }

Hope that helps.

Regards

Stefan

Former Member
0 Kudos

hi helmut,

your answer helped me, but raised an other question.

i understand the solution you suggested. unfortunately i dont quite know how to realize it.

do you use the copyElements() method (see reply stefan klensch) or did you code even this functionality manually?

i don`t understand how two different web service methods (and ergo two different model nodes and -as i understood your reply - two different context nodes) can interchange data via a call to copyElements(), as it only makes sense for two equal model nodes. but copyElements() only accepts two equal model nodes as parameters.

would you bind only one method to the model node and structure the other as matching value node?

maybe you can help me once more!

Former Member
0 Kudos

Hi Ilse,

i didn't recognize the restriction in case of model nodes, i used this for value nodes so far. There's a more generic approach using the method inserted below.

This method copies all attributes of node A into the attributes with the same name of node B, regardless if A and B are different model classes, if they are compatible. But it does not create elements like copyElements() and does not recurse into child nodes like copySubtree(), you would have to do this by yourself if necessary.


  /**
   * The Web Dynpro equivalent for the well know abap feature
   * "MOVE_CORRESPONDING". It intentionally has been renamed because the term
   * "move", although always being used in Cobol and ABAP, is not quite correct
   * and unusual in Java.
   * <p>
   * The method inspects all attributes of <code>source</code>, searches a
   * compatible attribute in <code>target</code> and copies the value if it 
   * finds one. Values are considered compatible if their Java class matches:
   * <ul>
   *   <li> All numeric classes (Byte, Short, Integer, Long, Float, Double,
   *        BigInteger and BigDecimal) and primitives (byte, short, int, long,
   *        float, double) are compatible.
   *   <li> Boolean class and primitive are compatible.
   *   <li> Character (class) and char (primitive) are compatible.
   *   <li> Otherwise source and target attribute must be based on the same class.
   * </ul>
   * <p>
   * Currently, both <code>source</code> and <code>target</code> may be either
   * an {@link IWDNodeElement} or an {@link com.sap.tc.cmi.model.ICMIGenericModelClass}.
   * If any object is of another class, it is simply ignored. These both classes
   * have been chosen, because they can tell about their structure at run time
   * without the need of Java reflection.
   * <p>
   * @param source The source object
   * @param target The target object
   */
  public static void copyCorresponding(Object source, Object target) {
    instance.copyCorresponding(source, target);
  }

Hope that helps anyway.

Regards

Stefan