Ecma Error: TypeError: Cannot call property - ibm-mobilefirst

I have written some java code in an adapter in worklight project. when i m trying to call the java method, i am getting an error saying
"responseID":"6","errors": {Ecma Error: TypeError: Cannot call property downloadFile in object
JavaPackage java.classes.FileIOPlugin]. It is not a function, it is
\"object\".}
I have followed the procedure exactly stated in the following link.
Using Java in Adapters
this is my project structure. Is there something wrong with this structure or should i add anything more to this?
This is how i am trying to call the java non-static method in adapter-impl.js
function downloadFile() {
var fileInstance = new com.worklight.JavaCode.FileIOPlugin();
return
{ result: fileInstance.downloadFile(); };
}

We have identified another possible solution to this.
Change Java compiler level to 1.6 as well as default JRE to 1.6:

Make sure your package starts with com, e.g. rename it to "com.classes".

Try adding the parenthesis when you instantiate your object:
var fileInstance = new com.worklight.JavaCode.FileIOPlugin()

Check your .project file and make sure it has the right buildCommand tags in it.
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.worklight.studio.plugin.WorklightProjectBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
Read more at: ECMA TypeError calling Java class from Worklight adapter

Related

JavaFX + Kotlin coroutine without android OS, is it possible?

I have a runnable jar that has a UI made with javafx fxml and the class code in kotlin with some database operations done with spring jpa.
Everything works great, except that I would like to not block the main thread while doing the work. Coming from C# I saw that in kotlin you can use coroutine like async await.
import javafx.fxml.FXML
import javafx.scene.control.Button
import kotlinx.coroutines.*
class appGui{
#FXML
private var buttonExecute: Button? = null
#FXML
fun buttonExecuteClick() {
buttonExecute!!.isDisable = true
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO){
work()
}
buttonExecute!!.isDisable = false
}
}
private suspend fun work() {
println("corotine starting...")
delay(5000);
//springMain.applyChanges()
println("corotine finished...")
}
}
So I have added the coroutine call, but I got an exception Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher
Looking at this exception, I found that you have to import the coroutines-android instead of the core, so I change my pom to it
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-android</artifactId>
<version>1.4.2</version>
</dependency>
which cause other exception ClassNotFoundException: android.os.Looper
Now I'm confused, is the coroutine intended to be used in android app? I'm running a jar on windows. Or do I need to go back to runnable task and do things like it was done in swing?
Thank to mipa (comment) for the tip.
just change the pom to import the javafx instead android.
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-javafx</artifactId>
<version>1.4.2</version>
</dependency>
simple and easy.
There is 3 main imports in the doc right now https://github.com/Kotlin/kotlinx.coroutines/blob/master/ui/coroutines-guide-ui.md
kotlinx-coroutines-android -- Dispatchers.Main context for Android applications.
kotlinx-coroutines-javafx -- Dispatchers.JavaFx context for JavaFX UI
applications.
kotlinx-coroutines-swing -- Dispatchers.Swing context for Swing UI applications.
I just need to use the right one

Global function works in preview but fails when code is run

I have a global function named 'finalPrice' which is defined in my configuration.xml file.
The function takes in a value - does stuff to it - and returns the final value. I reference the function from within DataWeave. When I click 'preview' I can see the correct output in the preview window. However when I run it I get the error:
Message : Exception while executing:
There is no variable named 'finalPrice'.
I have run the code on my local machine and in CloudHub and I get the same result
XML Code:
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
<!-- This function is called by the 'Validate and Transform' dataweave component in the 'main' flow-->
def finalPrice(incoming_value)
{
import java.lang.String;
import java.math.RoundingMode;
// Do Stuff
return strFinalNumber;
}
</global-functions>
</expression-language>
</configuration>
DataWeave Code:
//Refer to "finalPrice" Global Function in the main.xml configuration file
DB_FINL_PRCE: "field_missing" when payload01.DB_FINL_PRCE == "" otherwise finalPrice(payload01.DB_FINL_PRCE)
Any help appreciated
It's an issue with the comments in the global-functions. So remove or modify the line:
<!-- This function is called by the 'Validate and Transform' dataweave component in the 'main' flow-->
and just have:
<configuration doc:name="Configuration">
<expression-language>
<global-functions>
def finalPrice(incoming_value)
{
import java.lang.String;
import java.math.RoundingMode;
// Do Stuff
return strFinalNumber;
}
</global-functions>
</expression-language>
</configuration>
Or modify your comments to //
<configuration doc:name="Configuration">
<expression-language autoResolveVariables="true">
<global-functions>
//This function is called by the 'Validate and Transform' dataweave component in the 'main' flow
def finalPrice(incoming_value)
{
// Do Stuff
return "somethingelse";
}
</global-functions>
</expression-language>
</configuration>

Cucumber, Java8: find usage of step defined by lambda expression

Currently in our project's tests we switched from using annotated step definitions, e.g.:
public class Steps {
#Given("^Step name$")
void methodName() {
// do sth
}
}
to lambda expressions:
public class Steps implements En {
public Steps() {
Given("^Step name$", () ->
// do sth
);
}
}
When using Intellij Cucumber Java plugin it was easy to find the usage of some step, since it looked for usages of the annotated method (I presume).
Now however, we have to manually search for the regex passed as the argument.
My first question is: is there a neat way to do this with lambda expressions?
Moreover: when using Intellij's tool for version control and commiting files containing definitions of big numbers of steps, the code analysis tool goes on forever (I guess it is because of the constructor having to crank a lot of code).
So the second question is: since there is no possibility of the step library shrinking and step usage search is used very often wouldn't it be a good idea to switch back to Ye Olde Way i.e. using annotated methods?
Find usages for java-8 style step definitions do not yet work. One can vote and follow this request: IDEA-144648.
It is working here while using
IntelliJ IDEA 2018.1.5
'Cucumber for Java' plugin 181.5281.24
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<version.cucumber>3.0.2</version.cucumber>
<!-- following versions were also checked -->
<!--<version.cucumber>2.4.0</version.cucumber>-->
<!--<version.cucumber>2.3.1</version.cucumber>-->
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>${version.cucumber}</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${version.cucumber}</version>
<scope>test</scope>
</dependency>
</dependencies>
userdata.feature
Feature: demo for java8 glue classes
Scenario: user login on home page
Given user is on home page
When user navigate to login page
And user enters credentials to login
Then message displayed login successfully
glue/StepPojo.java
package glue;
import cucumber.api.PendingException;
import cucumber.api.java8.En;
public class StepPojo implements En {
public StepPojo() {
Given("^User is on Home Page$", () -> {
throw new PendingException();
});
When("^User Navigate to LogIn Page$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
And("^User enters Credentials to LogIn$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
Then("^Message displayed Login Successfully$", () -> {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
});
}
}
The class StepPojo.java was created by the Cucumber plugin by pressing ALT+ENTER while selecting a step in the feature file.
The feature file was shown before as
after the steps are defined as
[
when you hover with the mouse over a step while pressing down the CTRL key it looks as
when you click on a step while pressing down the CTRL key you jump to the respective method, e.g.
Given("^User is on Home Page$", () -> {
throw new PendingException();
});

EPiServer 7: Trouble adding dojo module to user interface

I have some trouble adding my dojo module to the user interface.It tries to access in the episerver/shell.
I have added a module.conifg;
<module>
<assemblies>
<add assembly="Mobile.Web" />
</assemblies>
<dojoModules>
<add name="MobileWeb" path="Scripts" />
</dojoModules>
</module>
Added my dojo module at ~/ClientResources/js/KeyValueEditor.js,
named the module declare('MobileWeb.js.KeyValueEditor', [widget, templatedMixin] and in my block type:
[ClientEditor(ClientEditingClass = "MobileWeb.js.KeyValueEditor")]
public virtual string KeyValueCategoryData { get; set; }
It works sometimes, but when I changed the dojoModules -> add name attribute to MobileWeb, it wont work anymore.
Anyone knows what this can be?
It looks like the system don’t know where to find client resources.
The name in the dojoModules node is kind of your namespace and the path should point to the folder where Dojo can find resources/scripts for that namespace. This path is relative to your module root directory.
As I understand you probably want to put your JavaScript files in ClientResources/js subfolder and your styles in ClientResources/css subfolder inside your module directory. In this case you can define Dojo module like this:
<dojoModules>
<add name="MobileWeb" path="ClientResources/js" />
</dojoModules>
It means that system will try to find resources in ClientResources/js subfolder in your module directory. When declaring widgets you should follow your namespace and folder structure. You can declare your widget in ClientResources/js/KeyValueEditor.js file like this:
define([
// your imports
],
function (/* imports */) {
return declare("MobileWeb.KeyValueEditor", [_Widget, /* … */ ], {
// implementation
});
});
And then you can use MobileWeb.KeyValueEditor name when you reference your widget in the back-end C# code.
You can find some examples and source code in sample add-on for EPiServer 7.

Migrating code from OpenLaszlo 3.3 to 5.0: TypeError #1007 Instantiation attempted on a non-constructor.

I ported some parts of the code from OL 3.3 to OL 5.0 recently. I thought that everything will work but when i try to run it using the ant script i have I am getting this error.
[echo] C:\Program Files\OpenLaszlo Server 5.0.x\Server\lps-5.0.x/WEB-INF/lps/server/bin/lzc.bat
[exec] Compiling: C:\Workspace\application\client\src\TestClient.lzx to TestClient.swf10.swf
[exec] compiler output is Loading configuration file C:\Program Files\OpenLaszlo Server 5.0.x\Server\lps-5.0.x\WEB-INF\frameworks\flex-config.xml
[exec] C:\Documents and Settings\310773\Local Settings\Temp\lzswf9\Workspace\application\client\src\build\TestClient\app.swf (289808 bytes)
So, I took the folder and i compiled it directly in Laszlo. It's not showing any error but when the swf is about to load the main page I am getting this error. Any idea why?
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at $lzc$class__mvz/$mvx()
at LzNode/__LZresolveReferences()
at LzNode/__LZcallInit()
at LzCanvas/__LZcallInit()
at LzCanvas/__LZinstantiationDone()
at LzInstantiatorService/makeSomeViews()
at LzInstantiatorService/checkQ()
at Function/http://adobe.com/AS3/2006/builtin::call()
at LzEvent/sendEvent()
at LzIdleKernel$/__update()
That's the error message you get when you try to instantiate a class which is not defined. Here is an example:
<canvas>
<class name="myclass">
<handler name="oninit">
// Instantiate a class which is not defined
var x = new lz.missingclass();
</handler>
</class>
<myclass />
</canvas>
Check for missing <includes> of classes which are being instantiated through scripts. You can always check the list of Adoboe Flash Run-Time Errors as well, sometimes there is useful information contained here.
Edit: Solution to problem added
This commment pointed to the problem:
I found that this line is causing the problem. <attribute name="dp"
value="$once{new lz.Datapointer()}" />. Any idea why?
If you check the OpenLaszlo reference for 5.0, you will see that the class names (on the left side in the class browser) use different case; some classes use camel case (lz.Browser, lz.DataElement), others use all lowercase (lz.view, lz.datapointer). In your case, you should have used lz.datapointer instead of lz.Datapointer.
Therefore this code will compile and run without any problems:
<canvas>
<class name="my_class" extends="node">
<attribute name="dp" value="$once{new lz.datapointer()}" />
</class>
<my_class oninit="Debug.inspect(this.dp)" />
</canvas>
A good way to test for the correct name of a class is to use the JavaScript in console in DHTML runtime, where you have auto-completion for lz.??? classnames:
Debugging SWF #1007 errors in OpenLaszlo
If you run into a #1007 error in the SWF runtime, I would compile the application for DHTML with the debugger disabled and the JavaScript error console open. Try this:
Change the line of with the $once{} constraint to
<attribute name="dp" value="$once{new lz.Datapointer()}" />
Compile the app in Chrome using DHTML runtime and debug=false. You should see the following error in the JavaScript console:
Click on the right side on error-1007.lzx:3, and you'll see the generated JavaScript code with the line causing the error
This line fails:
this.setAttribute("dp",new (lz.Datapointer)())
and you can even reproduce the error by typing new (lz.Datapointer) into the console.
Just as a point of info: The case of class names was "regularized" in 4.0 so that the case of a class that implements a tag is the same as that tag. See Mapping Class and Tag Names.
Here is an example of the problem and a workaround:
1) PROBLEM:
Here is the code of a short OpenLaszlo application demonstrating the problem:
<canvas width="1000" height="584">
<view name="myContainer" width="500" height="500">
<handler name="oninit">
var objCB = new lz.combobox(this);
</handler>
</view>
</canvas>
In this example there is no <combobox> tag in the application so the compiler does not think it needs to include the OpenLaszlo <combobox> class code in the application. Hence, when we try to instantiate a combobox with the line "var objCB = new lz.combobox(this);" the compiler throws the following error:
ERROR #test1007error.lzx≈5: TypeError: Error #1007: Instantiation
attempted on a non-constructor.
2) WORKAROUND:
The solution for the problem is to add an include in your application for <combobox>:
<canvas width="1000" height="584">
<include href="lz/combobox.lzx" />
<view name="myContainer" width="500" height="500">
<handler name="oninit">
var objCB = new lz.combobox(this);
</handler>
</view>
</canvas>
This time the error is not thrown and we see the combobox appear at the top left of the application when we run it.