Vinod Kumar Marupu
Vinod Kumar Marupu

Reputation: 547

IBM Mobilefirst 7.0 -Java Adapter Invocation Client Side

The following is an addition program to add two numbers.

my Server-side coding and Client-side coding as follows.
it throws error like

ReferenceError: com is not defined at (compiled_code):24

To work with Java Adapter Http Adapter is mandatory.

Server.js and client.js as follows

package com.mss;
public class Calculator {
public int addTwoIntegers(String first, String second){
    int c=Integer.parseInt(first)+Integer.parseInt(second);
   return Integer.toString(c);
}

}

function addTwoIntegers(){
alert("hi");
var calcInstance = new com.mss.Calculator();   
  return {
    result : calcInstance.addTwoIntegers("1","2")
  };

}

Upvotes: 0

Views: 394

Answers (1)

Idan Adar
Idan Adar

Reputation: 44526

To work with Java Adapter Http Adapter is mandatory

The above sentence in false. In MFP 7.0 you have both JavaScript adapters and Java adapters. To use a Java adapter you are not required to use HTTP adapter. That doesn't make sense. They are two different types of adapters.

Read the following tutorials: Server-side development

Have you taken a look at the UsingJavaInAdapter adapter in the Adapters sample? It demonstrates exactly what you're trying to do.


Did you actually create such a com.mss Java class and placed it in the server\java folder of your MFP project?

The question is just missing information.
Read the Java in JavaScript adapters tutorials.


Java class

package com.sample.customcode;

public class Calculator {

    // Add two integers.
    public static int addTwoIntegers(int first, int second){
        return first + second;
    }

    // Subtract two integers.
    public int subtractTwoIntegers(int first, int second){
        return first - second;
    }
}

Adapter implementation

function addTwoIntegers(a,b){
    return {
        result: com.sample.customcode.Calculator.addTwoIntegers(a,b)
    };
}

function subtractTwoIntegers(a,b){
    var calcInstance = new com.sample.customcode.Calculator();  
    return {
        result : calcInstance.subtractTwoIntegers(a,b)
    };
}

Upvotes: 1

Related Questions