0
votes

I have a comboxbox whose values come directly from a backend view. The backend view consisted of one sorted column that is created by 2 fields with a "|" character in the middle (field1 + "|" + field2). The formula that creates the values in the combobox is

var dbName = session.getCurrentDatabase();
var view = ("UniNames&Abbr");
var UniList = @Unique(@DbColumn(dbName,view,1));
return UniList

When a value is chosen from the list this formula creates, the view.postscipt alert breaks. Nothing else breaks. The error message is:

Error while executing JavaScript action expression Script interpreter error, line=9, col=14: [TypeError] Error calling method 'postScript(string)' on an object of type 'String [JavaScript Object]'

JavaScript code 1: //sessionScope.SavUniAbbr = sessionScope.UniAbbr; 2: var ComboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("ComboBox1").getValue(); 3: if (!!ComboBox1) { 4: print("ComboBox1 = ",ComboBox1); 5: var type = typeof ComboBox1; 6: print("ComboBox1 is type ",type) 7: var varAlert = ComboBox1 + " is type " + type + "."; 8: var al = "alert('"+ varAlert +"')"; 9: view.postScript(al); 10: var varAlert = "You selected " + ComboBox1 + "."; 11: var al = "alert('"+ varAlert +"')"; 12: view.postScript(al); 13: }

Here is my code:

<?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"
    xmlns:xc="http://www.ibm.com/xsp/custom"
    xmlns:bz="http://www.ibm.com/xsp/bazaar">
    <xp:this.resources>
        <xp:styleSheet href="/buttonptr.css"></xp:styleSheet>
        <xp:script src="/SSJS.jss" clientSide="false"></xp:script>
        <xp:styleSheet href="/CoopTeacher.css"></xp:styleSheet>
        <xp:script src="/CSJS.js" clientSide="true"></xp:script>
    </xp:this.resources>


    <xp:panel id="APanel"
        style="padding-left:10.0px;padding-right:10.0px">
        <xp:table style="width:50.0%">

            <xp:tr>


                <xp:td>


                    <xp:comboBox id="ComboBox1" style="width:99.0%">


                        <xp:selectItems id="selectItems1">
                            <xp:this.value><![CDATA[#{javascript:return ""}]]></xp:this.value>
                        </xp:selectItems>
                        <xp:selectItem itemLabel="Item1"
                            itemValue="Value1" id="selectItem1">
                        </xp:selectItem>
                        <xp:selectItem itemLabel="Item2"
                            itemValue="Value2" id="selectItem2">
                        </xp:selectItem>
                        <xp:selectItem itemLabel="Item3"
                            itemValue="Value3" id="selectItem3">
                        </xp:selectItem>
                        <xp:selectItem itemLabel="Item4"
                            itemValue="Value4" id="selectItem4">
                        </xp:selectItem>
                        <xp:selectItem itemLabel="Item5"
                            itemValue="Value5" id="selectItem5">
                        </xp:selectItem>


                        <xp:selectItems>
                            <xp:this.value><![CDATA[#{javascript:var dbName = session.getCurrentDatabase();
var view = ("UniNames&Abbr");
var UniList = @Unique(@DbColumn(dbName,view,1));
return UniList}]]></xp:this.value>
                        </xp:selectItems>
                        <xp:eventHandler event="onchange" submit="true"
                            refreshMode="partial" refreshId="APanel">
                            <xp:this.action><![CDATA[#{javascript://sessionScope.SavUniAbbr = sessionScope.UniAbbr;
var ComboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("ComboBox1").getValue();
if (!!ComboBox1) {
    print("ComboBox1 = ",ComboBox1);
    var type = typeof ComboBox1;
    print("ComboBox1 is type ",type)
    var varAlert = ComboBox1 + " is type " + type + ".";
    var al = "alert('"+ varAlert +"')";
    view.postScript(al);
    var varAlert = "You selected " + ComboBox1 + ".";
    var al = "alert('"+ varAlert +"')";
    view.postScript(al);
}
}]]></xp:this.action>
                        </xp:eventHandler></xp:comboBox>
                </xp:td>

            </xp:tr>

        </xp:table>

    </xp:panel>
</xp:view>

Thanks so much for looking at this. ---Lisa&

1

1 Answers

0
votes

I do not know why the problem occurs - but there is a workaround. However, I had to add a button and change the serverside script on the comboBox.

1) I added "viewScope.SavChoice = viewScope.Choice;" to the onChange event of the comboBox. 2) In the onClick event of the of button the first thing line of code is "viewScope.Choice = viewScope.SavChoice;" and after which I was able to use serverside alerts to announce things. Here is the new code:

<?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"
    xmlns:xc="http://www.ibm.com/xsp/custom" xmlns:bz="http://www.ibm.com/xsp/bazaar">
    <xp:panel id="APanel" style="padding-left:10.0px;padding-right:10.0px">
        <xp:table>
            <xp:tr>
                <xp:td>
                    <xp:comboBox id="ComboBox1" value="#{viewScope.Choice}">
                        <xp:selectItems id="selectItems1">
                            <xp:this.value><![CDATA[#{javascript:return ""}]]></xp:this.value>
                        </xp:selectItems>
                        <xp:selectItem itemLabel="Item1" itemValue="Value1"
                            id="selectItem1">
                        </xp:selectItem>
                        <xp:selectItem itemLabel="Item2" itemValue="Value2"
                            id="selectItem2">
                        </xp:selectItem>
                        <xp:selectItem itemLabel="Item3" itemValue="Value3"
                            id="selectItem3">
                        </xp:selectItem>
                        <xp:selectItem itemLabel="Item4" itemValue="Value4"
                            id="selectItem4">
                        </xp:selectItem>
                        <xp:selectItem itemLabel="Item5" itemValue="Value5"
                            id="selectItem5">
                        </xp:selectItem>
                        <xp:selectItems id="selectItems2">
                            <xp:this.value><![CDATA[#{javascript:var dbName = session.getCurrentDatabase();
var view = ("UniNames&Abbr");
var UniList = @Unique(@DbColumn(dbName,view,1));
return UniList}]]></xp:this.value>
                        </xp:selectItems>
                        <xp:eventHandler event="onchange" submit="true"
                            refreshMode="partial" refreshId="APanel" id="eventHandler1">
                            <xp:this.action><![CDATA[#{javascript:viewScope.SavChoice = viewScope.Choice;}]]></xp:this.action>
                        </xp:eventHandler>
                    </xp:comboBox>
                </xp:td>
                <xp:td>
                    <xp:button id="button5" value="Server Side Alert">
                        <xp:eventHandler event="onclick" submit="true"
                            refreshMode="partial" id="eventHandler9" refreshId="APanel">
                            <xp:this.script><![CDATA[XSP.getElementById("#{id:ComboBox1}").value = "";]]></xp:this.script>
                            <xp:this.action><![CDATA[#{javascript:viewScope.Choice = viewScope.SavChoice;
if (!!Choice) {
    print("Choice = ",Choice);
    var type = typeof Choice;
    print("Choice is type ",type)
    var varAlert = Choice + " is type " + type + ".";
    var al = "alert('"+ varAlert +"')";
    view.postScript(al);
    var varAlert = "You selected " + Choice + ".";
    var al = "alert('"+ varAlert +"')";
    view.postScript(al);
}
}]]></xp:this.action>
                        </xp:eventHandler>
                    </xp:button>
                </xp:td>
            </xp:tr>
        </xp:table>
    </xp:panel>
</xp:view>