1
votes

I visit this website to learn to use postscript in xpages. I follow the example to run the code and it runs property.

Then I begin to try other way. I use a computed field that use @DbLookup and a button that will use view.postScript to open xpage in a new window. When @DbLookup returns the value, that value will be the parameter in view.postScipt.

When I run the code, it returns error said Java method 'postScript(Array)' on java class 'com.ibm.xsp.component.UIViewRootEx2' not found

I get confuse about the error since it mentions it is java error and I don't have java code in the xpage.

I think the reason I get the error is the computed field returns more than one value.

However if I hard code values, it run fine

var myparam = "Test,Test2,Test3"; 

Or

var myparam = "Test"+"Test2"+"Test3"; 

Please find the code for your review please.(It includes the code that cause error, my attempts and the error message)

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:br></xp:br>
<xp:text escape="true" id="computedField1">
    <xp:this.value><![CDATA[#{javascript:
//use @DbLookup to find value, that value will be the parameter in  postScript
var value = @DbLookup(@DbName(), "myView", keyword, 3);
return value;
}]]></xp:this.value>
</xp:text>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true"
        refreshMode="complete">
        <xp:this.action><![CDATA[#{javascript:
var myparam = getComponent("computedField1").getValue();//does not work
//var myparam = "Test,Test2,Test3"; //works
//var myparam = "Test"+"Test2"+"Test3"; //works
//var myparam = "Test"; //(original) works
var myurl = @LeftBack(context.getUrl(),"/") + "/testpostscript.xsp?id="+myparam;
//error occurs in this code
//Java method 'postScript(Array)' on java class 'com.ibm.xsp.component.UIViewRootEx2' not found
view.postScript("window.open('" + myurl + "')");}]]></xp:this.action>
    </xp:eventHandler></xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
</xp:view>

I read this post and it seems different to my question.

When I search "postScript(Array) xpages" on the Internet, I don't find much information about it.

So my question is how to let view.postScript runs when the parameter contains multiple values?

Grateful for your advice please. Thank you.

1

1 Answers

3
votes

You are right that the result of your @DbLookup returns more than one value (an array). That's why you see the underlying Java error that postScript(Array) is an unknown method. The postScript method expects a String as input.

I will suggest that you use @Implode() to join the result from the @DbLookup:

<xp:button value="Label" id="button1">
    <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
        <xp:this.action>
            <![CDATA[#{javascript:
                var myparam = @Implode(getComponent("computedField1").getValue(); ",")
                var myurl = @LeftBack(context.getUrl(),"/") + "/testpostscript.xsp?id="+myparam;
                view.postScript("window.open('" + myurl + "')");}]]>
        </xp:this.action>
    </xp:eventHandler>
</xp:button>