Xpages无法使getComponent在Ext:Dialog中工作

时间:2014-12-12 21:00:44

标签: xpages xpages-ssjs

我在对话框中有一个值选择器。用户选择一个值,并将该值输入编辑框,该编辑框绑定到范围变量。到目前为止一切都很好。

然后我有一个按钮,我想要访问编辑框中的值。

我尝试过使用

var satLoc:String = viewScope.get("selLoc");
var satLoc:String = getComponent("selLoc").getValue();

两者都不起作用 - 我只是得到null。

我的代码如下。我将不胜感激。

<?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:button id="button15" style="font-weight:bold;font-size:8pt" value="Load Satellite Dialog">                          
        <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="dialogAddSat">
            <xp:this.action><![CDATA[#{javascript:var d = getComponent('dialogAddSat')d.show()}]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>

    <xp:br></xp:br>

    <xe:dialog id="dialogAddSat" style="width:300px">
            <xe:this.title><![CDATA[#{javascript:"Make This Location A Hub"}]]></xe:this.title>
            <xe:dialogButtonBar>
                <xp:table id="tblCrd" style="width:99.0%">
                    <xp:tr>
                        <xp:td>
                            <xp:label id="label24" for="region" value="Hub Location Number" />
                        </xp:td>
                        <xp:td> 
                        <xe:djTextBox id="djTextBox2"
                            style="width:35px;text-align:right">
                            <xe:this.dojoAttributes>
                                <xp:dojoAttribute name="readOnly"
                                    value="true">
                                </xp:dojoAttribute>
                            </xe:this.dojoAttributes>
                            <xe:this.value><![CDATA[#{javascript:"0002"}]]></xe:this.value><xp:eventHandler event="onChange"
                                submit="true" refreshMode="partial" refreshId="tblCrd">
                            </xp:eventHandler>
                        </xe:djTextBox>
                        </xp:td>
                        <xp:td style="text-align:right">

                        <xp:button id="button13" value="Attach Satellite">
                            <xp:eventHandler event="onclick"
                                submit="true" refreshMode="complete" id="eventHandler7"
                                disableValidators="true">
                                <xp:this.script><![CDATA[XSP.closeDialog('#{id:dialogMakeHub}');]]></xp:this.script>
                                <xp:this.action>
                                    <xp:actionGroup>
                                        <xp:confirm>
                                    <xp:this.message><![CDATA[#{javascript:try {
    var satLoc:String = viewScope.get("selLoc");
    //var satLoc:String = getComponent("selLoc").getValue();
    var hubLoc = "0002";
    //var hubLoc:String = document1.getDocument().getItemValueString("locNum");
    return "Make Location " + satLoc + " a Satellite for Location Number " + hubLoc
} catch(e){
    return e;
}

}]]></xp:this.message>
                                        </xp:confirm>
                                        <xp:executeScript>
                                            <xp:this.script><![CDATA[#{javascript:print ("Here")}]]></xp:this.script>
                                        </xp:executeScript>
                                    </xp:actionGroup>
                                </xp:this.action>
                            </xp:eventHandler>
                        </xp:button></xp:td>
                    </xp:tr>
                    <xp:tr>
                        <xp:td>
                            <xp:label id="label25" for="region" value="Select Location..." />
                        </xp:td><xp:td>
    <xp:inputText id="selLoc" value="#{viewScope.selLoc}"></xp:inputText>
    <xe:valuePicker id="valuePicker77"
        dialogTitle="Choose A Location To Add As A Satellite"
        pickerIcon="/picker.png" for="selLoc">

        <xe:this.dataProvider>
            <xe:simpleValuePicker>
                <xe:this.valueList><![CDATA[#{javascript:import xpUtilities

var tmpLocView:NotesView = database.getView("(DbLocsOperActiveLOnly)");
var arr = new Array();
var tmpLocNum:String;
var hubLocNum:String;

//hubLocNum = padToFour(document1.getDocument().getItemValueString("locNum"));
hubLocNum = "0002;"
//arr[0] = hublocNum

var tmpLocDoc:NotesDocument = tmpLocView.getFirstDocument();
while (tmpLocDoc != null) {
    tmpLocNum = tmpLocDoc.getItemValueString("locNum");
    if (tmpLocNum != hubLocNum)
    {arr.push(tmpLocDoc.getItemValueString("locNum"));}
    var tmpdoc = tmpLocView.getNextDocument(tmpLocDoc);
    tmpLocDoc.recycle();
    tmpLocDoc = tmpdoc;
}

return arr
}]]></xe:this.valueList>
            </xe:simpleValuePicker>
        </xe:this.dataProvider>
    </xe:valuePicker></xp:td>
                        <xp:td style="text-align:right">

                        <xp:button value="Cancel" id="button10">
                            <xp:eventHandler event="onclick"
                                submit="true" refreshMode="complete" id="eventHandler4">
                                <xp:this.script><![CDATA[XSP.closeDialog('#{id:dialogAddSat}')]]></xp:this.script>
                            </xp:eventHandler>
                        </xp:button></xp:td>
                    </xp:tr>
                    <xp:tr>
                        <xp:td>
                        </xp:td>
                        <xp:td>
                        </xp:td>
                        <xp:td style="text-align:right">
                        </xp:td>
                    </xp:tr>
                </xp:table>
            </xe:dialogButtonBar>
        </xe:dialog>
</xp:view>

enter image description here

我找到了解决方案。我有一个带有确认行动的行动小组。我试图在确认行动中获得价值。出于某种原因,它并没有在那里工作。我只是在确认动作中忽略它,现在它可以工作。

1 个答案:

答案 0 :(得分:2)

问题在于时机问题。在以下代码中,您计算​​确认文本。但这是在服务器端计算的,当它被渲染时。在渲染时,viewScope变量为空。

<xp:button 
    id="button13" 
    value="Attach Satellite">
    <xp:eventHandler 
        event="onclick"
        submit="true"
        refreshMode="complete"
        id="eventHandler7"
        disableValidators="true">
        <xp:this.script><![CDATA[XSP.closeDialog('#{id:dialogMakeHub}');]]></xp:this.script>
        <xp:this.action>
            <xp:actionGroup>
                <xp:confirm>
                    <xp:this.message><![CDATA[#{javascript:try {
var satLoc:String = viewScope.get("selLoc");
//var satLoc:String = getComponent("selLoc").getValue();
var hubLoc = "0002";
//var hubLoc:String = document1.getDocument().getItemValueString("locNum");
return "Make Location " + satLoc + " a Satellite for Location Number " + hubLoc
} catch(e){
return e;
}}]]>
                    </xp:this.message>
                </xp:confirm>
                <xp:executeScript>
                    <xp:this.script><![CDATA[#{javascript:print ("Here")}]]></xp:this.script>
                </xp:executeScript>
            </xp:actionGroup>
        </xp:this.action>
    </xp:eventHandler>
</xp:button>

如果在输入值更改时刷新按钮组件,它将显示正确的值。但是,我更喜欢在脚本属性中计算客户端的确认值。关闭对话框应该是最终操作(如果用户没有确认该值,则不应该关闭。这是修改后的版本。

<xp:button
    id="button13"
    value="Attach Satellite">
    <xp:eventHandler
        event="onclick"
        submit="true"
        refreshMode="complete"
        id="eventHandler7"
        onComplete="XSP.closeDialog('#{id:dialogAddSat}');"
        disableValidators="true">
        <xp:this.action>
            <xp:actionGroup>
                <xp:executeScript>
                    <xp:this.script><![CDATA[#{javascript:print ("Here")}]]></xp:this.script>
                </xp:executeScript>
            </xp:actionGroup>
        </xp:this.action>
        <xp:this.script><![CDATA[return confirm("Location will be set "+dojo.byId('#{id:selLoc}').value+". Confirm?")]]></xp:this.script>
    </xp:eventHandler>
</xp:button>