简体   繁体   English

有人可以帮我解决XPages中奇怪的页面刷新问题吗?

[英]Can someone help me with a strange page refresh issue in XPages?

Just fyi, I've been developing with xpages since they were introduced, so I feel like I somewhat know what I'm doing. 只是,自从xpages引入以来,我一直在开发它们,所以我觉得我有点知道自己在做什么。 However, this one case is driving me nuts. 但是,这种情况使我发疯。

I have two combo boxes, a ShipTo and a BillTo. 我有两个组合框,一个ShipTo和一个BillTo。 The ShipTo selection will update the choices for the BillTo combobox. ShipTo选择将更新BillTo组合框的选择。 Nothing fancy. 没有什么花哨。

Here's the problem. 这是问题所在。 When the page opens, both fields are set with defaults. 当页面打开时,两个字段均设置为默认值。 If I choose a different ShipTo, the BillTo choices change (as expected, from the panel partial refresh) BUT the onChange ssjs code in the ShipTo field does not run. 如果选择其他ShipTo,则BillTo选项会更改(按预期,从面板局部刷新),但ShipTo字段中的onChange ssjs代码不会运行。 Follow me, here.... when I change the ShipTo, it partial refreshes the enclosing panel onChange. 在这里跟随我。...当我更改ShipTo时,它会部分刷新封闭面板onChange。 The first thing that recomputes is the choices for the BillTo field. 重新计算的第一件事是BillTo字段的选择。 THEN, the onChange ssjs is triggered in the ShipTo field. 然后,在ShipTo字段中触发onChange ssjs。 It's not what one would expect, but my console messages show this to be true. 这不是人们所期望的,但是我的控制台消息表明这是正确的。

So, when the BillTo has a value (ie not = "-Select-") then the onChange ssjs does not fire. 因此,当BillTo有一个值(即不是=“ -Select-”)时,则不会触发onChange ssjs。 Once the BillTo refreshes to -Select- (because of the ShipTo change) then the ShipTo onChange ssjs will run just fine. 一旦BillTo刷新到-Select-(由于ShipTo更改),然后ShipTo onChange ssjs将运行良好。 Every time. 每次。 UNTIL I select a BillTo... then the onChange ssjs will not run. 直到我选择一个BillTo ...,然后onChange ssjs才会运行。

Crazy, I know. 疯狂,我知道。 But, this is for a customer application, so I need to get it figured out. 但是,这是针对客户应用程序的,因此我需要弄清楚它。

Here's the console when the BillTo = "-Select-" 这是BillTo =“ -Select-”时的控制台

HTTP JVM: getting billto choices HTTP JVM:获取Billto选择

HTTP JVM: ... billto values complete HTTP JVM:... billto值已完成

HTTP JVM: shipto onchange HTTP JVM:shipto onchange

HTTP JVM: sel=CelayaH4999 HTTP JVM:sel = CelayaH4999

Now, when I select a valid BillTo (no refresh or onchange events there) and then reselect a ShipTo, I get this... 现在,当我选择有效的BillTo(那里没有刷新或onchange事件)然后重新选择ShipTo时,我得到了...

HTTP JVM: getting billto choices HTTP JVM:获取Billto选择

HTTP JVM: ... billto values complete HTTP JVM:... billto值已完成

The ShipTo onChange ssjs NEVER RUNS. ShipTo onChange ssjs永远不会运行。 Go figure. 去搞清楚。

Here's my test page: 这是我的测试页:

    <?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:this.data>
        <xp:dominoDocument var="document1" formName="Entry1">

        <xp:this.postNewDocument>
            <xp:executeScript>
                <xp:this.script><![CDATA[#{javascript:document1.replaceItemValue("CurrentForm","Entry1");
var res = InitializeWF("Entry1",document1,true);  //newdoc
var res = InitializeDefaults(document1);

document1.replaceItemValue("ShipToKeyx",document1.getItemValueString("ShipToKey"));
document1.replaceItemValue("BillToKeyx",document1.getItemValueString("BillToKey"));

document1.replaceItemValue("MpxLoc","Y");   //for compatibility

}]]></xp:this.script>
            </xp:executeScript>
        </xp:this.postNewDocument></xp:dominoDocument>
    </xp:this.data>
    <xp:this.resources>
        <xp:script src="/xpServerSide.jss" clientSide="false"></xp:script>
    </xp:this.resources>
    <xp:panel id="panelPage">


        <xp:comboBox id="ShipToKey" value="#{document1.ShipToKeyx}">
            <xp:selectItems id="selectItems5">
                <xp:this.value><![CDATA[#{javascript:var list = @DbColumn(@DbName(),"shpmstlookupui",9);
list.sort();
list.unshift("-Select-");
@Unique(list)}]]></xp:this.value>
            </xp:selectItems>
            <xp:eventHandler event="onchange" submit="true"
                refreshMode="partial" refreshId="panelPage" id="eventHandler9">
                <xp:this.action>
                    <xp:executeScript>
                        <xp:this.script><![CDATA[#{javascript:print("shipto onchange")
var sel = getComponent("ShipToKey").getValue();
print("sel="+sel)
var res = true;
if(sel==null || sel=="" || sel=="-Select-"){
    document1.replaceItemValue("ReqShipToAddress","");
    res = false;
}

if(res){
    var sview = database.getView("shpmstlookupui");
    var vdoc = sview.getDocumentByKey(sel,true);
    if(vdoc!=null){
        document1.replaceItemValue("ReqShipToAddress",vdoc.getItemValue("ShipFull"));
    }
}

//verify billto is from this same whs
//print("shipwh = " + document1.getItemValueString("ShipWh")+", billwh = "+document1.getItemValueString("BillWh"))
if(!res || document1.getItemValueString("ShipWh")!=document1.getItemValueString("BillWh")){
    document1.replaceItemValue("BillToKey","-Select-");
}
    }]]></xp:this.script>
                    </xp:executeScript>
                </xp:this.action>
            </xp:eventHandler>
        </xp:comboBox>
        <xp:br></xp:br>
        <xp:text escape="false" id="computedField11">
            <xp:this.value><![CDATA[#{javascript:var list = new Array(document1.getItemValue("ReqShipToAddress"));
//print("shipto address list len = "+list.length+", list = "+list)
if(list.length==0){return null;}
return "<UL style='list-style-type: none;padding: 0px;margin: 0px'><LI>" + @Implode(list,"<LI>") + "</UL>";}]]></xp:this.value>
        </xp:text>
        <xp:br></xp:br>
        <xp:br></xp:br>
        <xp:comboBox id="BillToKey" value="#{document1.BillToKeyx}">
            <xp:selectItems id="selectItems6">
                <xp:this.value><![CDATA[#{javascript:var tmparrx = new Array("bob","tim")
tmparrx.sort();
tmparrx.unshift("-Select-");

print("getting billto choices ==============================================================================")
var sel = getComponent("ShipToKey").getValue();
if(sel==null || sel=="-Select-" || sel==""){
print("sel is null, returning tmparrx");
return @Unique(tmparrx);
    //try xsp value
    sel = document1.getItemValueString("ShipToKey");
    if(sel==null || sel=="-Select-" || sel==""){
        var shipwh = null;
    }
    else {
        var shipwh = null;
        var sview = database.getView("shpmstlookupui");
        var vdoc = sview.getDocumentByKey(sel,true);
        if(vdoc!=null){
            shipwh = vdoc.getItemValueString("Shipwh");
        }
    }
}
else {
    var shipwh = null;
    var sview = database.getView("shpmstlookupui");
    var vdoc = sview.getDocumentByKey(sel,true);
    if(vdoc!=null){
        shipwh = vdoc.getItemValueString("Shipwh");
    }
//  print("got shipwh = "+shipwh)
//  return @Unique(tmparrx);
}
if(shipwh==null){return null;}

var list = @DbLookup(@DbName(),"shpmstlookup2",shipwh,9);
if(typeof list==="string"){
    var tmparr = new Array(list);
}
else {
    var tmparr = list;
}
tmparr.sort();
tmparr.unshift("-Select-");
print("... billto values complete");
//return @Unique(tmparrx);
return @Unique(tmparr);


/*
//check existing selection
var sel = document1.getItemValueString("BillToKey");
print("initial value = "+sel)
var found = false;
for(x=0;x<tmp2.length;x++){
    var entry = tmp2[x];
    if(entry.toLowerCase().indexOf(sel.toLowerCase())>=0){
    print("found = true")
        found = true;
    }
}
if(!found){
print("not found")
    document1.replaceItemValue("BillToKey","-Select-");
}
var sel = document1.getItemValueString("BillToKey");
print("post value = "+sel)
tmp2
*/}]]></xp:this.value>
            </xp:selectItems>

        </xp:comboBox>
        <xp:br></xp:br>
        <xp:br></xp:br>

    </xp:panel>

</xp:view>

It's the craziest thing. 这是最疯狂的事情。

If I return a new Array("bob","tim") for the BillTo choices, then all works as it should - no matter what the BillTo selection is. 如果我为BillTo选项返回一个新的Array(“ bob”,“ tim”),那么无论BillTo选择是什么,所有操作都应按预期进行。 But, when I return the BillTo choices as computed, then it doesn't work. 但是,当我按计算返回BillTo选项时,它不起作用。 So, it appears there's a problem with the BillTo choices formula, but I can't find anything wrong. 因此,看来BillTo选择公式存在问题,但我找不到任何错误。

Can someone identify the stupid mistake I'm making? 有人可以识别我正在犯的愚蠢错误吗? - or, point me in the right direction to get this cleared up? -或者,为我指出正确的方向以消除这种情况?

I narrowed down the problem to this: The ShipTo selection changes the choices for the BillTo field. 我将问题缩小到此范围:ShipTo选择更改了BillTo字段的选择。 If the BillTo was -Select- then everything worked fine, because -Select- is always a valid choice for any ShipTo. 如果BillTo是-Select-,则一切正常,因为-Select-始终是任何ShipTo的有效选择。 However, if the BillTo had a valid selection, then when the ShipTo was changed, that BillTo selection is now no longer valid for the new BillTo choices. 但是,如果BillTo有一个有效的选择,则在更改ShipTo时,该BillTo选择现在对于新的BillTo选项不再有效。 This caused the ShipTo onChange event to not run. 这导致ShipTo onChange事件无法运行。 (remember, the BillTo choices formula runs BEFORE the ShipTo onChange) (请记住,BillTo选项公式在ShipTo onChange之前运行)

I could not find a solution, so I instead just used a workaround. 我找不到解决方案,所以我只使用了一种解决方法。

I put my ShipTo onChange code in a script library function and then call it in both the ShipTo onChange event AND also the BillTo selection choices formula. 我将ShipTo onChange代码放在脚本库函数中,然后在ShipTo onChange事件和BillTo选择选择公式中调用它。 So, now, if the current BillTo selection does not match the new list of choices for the BillTo, then I call the ShipTo onChange function from the choices formula - because I know it won't run once the choices are calculated. 因此,现在,如果当前的BillTo选择与BillTo的新选择列表不匹配,那么我从choices公式调用ShipTo onChange函数-因为我知道一旦计算出选择就不会运行。 This workaround works, but I have a feeling this issue will probably bite me again in the future. 该解决方法有效,但是我觉得这个问题将来可能会再次困扰我。

Now that I have a better understanding, you can easily test it yourself by using two comboboxes where the second set of choices depends on the first box selection. 现在,我有了更好的理解,您可以使用两个组合框轻松地自己进行测试,其中第二组选择取决于第一个框的选择。 Put a print statement in the first box onChange and you'll see that it will not fire unless the second box selection matches one of the new set of choices based on the first box selection. 将打印语句放在onChange的第一个框中,您将看到它将不会触发,除非第二个框选择与基于第一个框选择的一组新选择匹配。

I can't explain it any more than that, but I hope this post can help someone else. 除此以外,我无法解释,但我希望这篇文章能对其他人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM