1
votes

I have a simple application with one class and one xPage with one computedField, bound to that class. I want to show result from class getter as a bean. Doesn't work. My class looks like this:

package test.test;

public class Test {
    public Test() {
    }

    public String getTest() {
        return "Test";
    }
}

SSJS in the computedField:

var test = new test.test.Test();
return test.getTest();

an error is like this:

Error while executing JavaScript computed expression
Script interpreter error, line=1, col=17: 'test' is undefined

1: var test = new test.test.Test();

Am I missing any settings or what? Thanks in advance, JiKra

EDIT: If I use a managed bean, the issue is absolutely identical. There must be problem with my Designer/Eclipse IDE. I'll try to reinstall it tomorow.

EDIT2: Today, I tried to do the same thing in my colleges's computer and it's the same error. So, the problem is not with my IDE. I must be missing something. Do I need any external libraries to be installed on the server or in the IDE?

7
It's just for simplicity. I tried it three times berfore with different package and class names. Still the same error.JiKra
Where is your java class stored? Lib/ext jar, java element?Simon O'Doherty
It's just a single package and class in Code/Java.JiKra

7 Answers

2
votes

Ok I did the following.

1) Created a new Java Class.

enter image description here

2) Put in the following code into the class.

package test.test;

public class Test implements java.io.Serializable {

    public Test() {
        super();
    }

    public String getTest() {
        return "Test";
    }

}

3) Created an XPage with the following source:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xp:text escape="true" id="computedField1">
        <xp:this.value><![CDATA[#{javascript:var t:test.test.Test = new     test.test.Test();

return t.getTest();
}]]></xp:this.value>
    </xp:text>
</xp:view>

Opened it in a browser and got the word "Test" appearing.

Changed variable "t" to "test" and then it failed. So it appears the variable name is the issue.

[EDIT]

Based on your comment of using 8.5.2, the code/Java functionality didn't arrive until Notes/Domino 8.5.3. Which is why it is not working for you.

1
votes

Your variable name in SSJS (test) is conflicting with the package name. Use

var test1=new test.test.Test();

It will work...

1
votes

Probably build issue. Make sure you...

1) Built the code, try to clean and build.

2) Have correct build paths - you find it in preferences dialog.

3) Can locate Test.class file, preferably in Navigator view of Java perspective.

1
votes

Make sure the Java and XPage are built after you have changed the package name. For example add a print("new XPage") to SSJS and System.out.println("new Java") to Java.

I can reproduce the problem with your code and 8.5.3FP3 Designer+Server. When I change the package name to test.tes the problem goes away.

EDIT: I used variable name "t" all the time and can confirm that the problem appears also if I change the variable name to "test" as Simon found out below. Maybe Simon has a different Desiger/Domino version because test.test.Test does not work for me with variable name "t".

EDIT2: Sounds like you are using 8.5.3 Designer with 8.5.2 server. As Simon said Code/Java was introduced in 8.5.3. Instructions for writing Java for 8.5.2 can be found for example here: http://xpageswiki.com/web/youatnotes/wiki-xpages.nsf/dx/Work_with_Java

0
votes

While initializing you Java class in SSJS the code should be like this:

var testObj:test.test.Test = new test.test.Test();
0
votes

You forgot to put the new statement.

var test = new test.test.Test();
0
votes

Not sure if this is the issue, but I think you have to define a variable "test" of type String in the Bean in order to retrieve it's value using getTest().