Hello

I'm using Apache BSF + Rhino to execute some scripts that the user enters to
validate some objets,
but I'm having trouble with simple operations and Integer fields in the
classes (I need to keep the Integers because I need to keep the null
values).

Is it possible to access the values(number) of Integer fields in an object?

here es an example:

I have a Class ObjectX like

    public class ObjectX {
        private Integer age;
        ......
        public ObjectX(Integer age) {
            this.age = age;
        }
        public void setAge(Integer age) {
            this.age = age;
        }
        public Integer getAge() {
            return age;
        }
        .......
    }

The main code is:

    public static void main(String[] args) {

        // with New Number()
        String script1 = "function test(){ java.lang.System.out.println( new
Number(a.age) + new Number(b.age)  ); }";
        // wirh intValue()
        String script2 = "function test(){ java.lang.System.out.println(
a.age.intValue() + b.age.intValue()  ); }";
        // alone
        String script3 = "function test(){ java.lang.System.out.println(
a.age + b.age  ); }";

        BSFManager bsf = new BSFManager();
        try {
            bsf.declareBean("a",new ObjectX(40),ObjectX.class);
            bsf.declareBean("b",new ObjectX(35),ObjectX.class);
            bsf.eval("javascript","test",0,0,script1 + "\ntest();");
            bsf.eval("javascript","test",0,0,script2 + "\ntest();");
            bsf.eval("javascript","test",0,0,script3 + "\ntest();");
        } catch (BSFException e) {
            // TODO
        }
    }


script1 outputs 75 (the sum of 40 and 35), so does script2, but the way I
need this to work for the user is script1,
but in this case, script1 outputs 4035 (The concatenation of 40 and 35)

How can i get the 75 with the script3? is this possible?

Thank you...
Daniel.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to