Xpages 更新某些页面时出错
我有一个组合框,它执行隐藏表的部分刷新。我试图在选择除默认值以外的任何值后显示该表。我正在使用绑定到范围变量的隐藏编辑字段来控制表的呈现与否。我认为我遇到的问题是,我的代码在设置范围变量之前首先进行了部分刷新(请参阅下面的代码onComplete…)。但是,我不确定如何在刷新之前首先设置范围变量。谁能给我指出正确的方向吗Xpages 更新某些页面时出错,xpages,Xpages,我有一个组合框,它执行隐藏表的部分刷新。我试图在选择除默认值以外的任何值后显示该表。我正在使用绑定到范围变量的隐藏编辑字段来控制表的呈现与否。我认为我遇到的问题是,我的代码在设置范围变量之前首先进行了部分刷新(请参阅下面的代码onComplete…)。但是,我不确定如何在刷新之前首先设置范围变量。谁能给我指出正确的方向吗 <xp:comboBox id="vendorAppAdvSkills1"> <xp:selectItem itemLabel="-Select a
<xp:comboBox id="vendorAppAdvSkills1">
<xp:selectItem itemLabel="-Select a Category-"
itemValue="" id="selectItem1">
</xp:selectItem>
<xp:selectItems id="selectItems1">
<xp:this.value><![CDATA[#{javascript:getComponent( "vendorAppSkills1" ).getValue();}]]></xp:this.value>
</xp:selectItems>
<xp:eventHandler event="onblur" submit="false"
id="eventHandler1">
<xp:this.script><![CDATA[
XSP.partialRefreshPost("#{id:tblAdvertising}",
{
// Added showAdvertising code to hide the advertising table until the user selects their free category!
onComplete: function()
{
// Fetch a handle to the first category field
var freeCategory = dojo.byId('#{id:vendorAppAdvSkills1}');
var showAdvertising = document.getElementById('#{id:showAdvertising}');
// If it's blank, force the cursor off the field to fire the onBlur Event
if( freeCategory.value == "" || freeCategory.value == null )
{
if($('body').scrollTop()>0)
{
$('body').scrollTop(0); //Chrome,Safari
}
else
{
if($('html').scrollTop()>0)
{ //IE, FF
$('html').scrollTop(0);
}
}
showAdvertising.value = false;
// Notify the user this is required
alert( "Please Select Your FREE Category Listing!" );
// Place the cursor back in the first category field again
freeCategory.focus();
}
else
showAdvertising.value = true;
}
} );]]></xp:this.script>
</xp:eventHandler>
</xp:comboBox>
不要使用XSP.partialRefreshPost
执行部分刷新,而是使用事件处理程序的refreshId
参数,设置范围变量,然后在为范围变量赋值后运行onComplete代码:
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.afterPageLoad><![CDATA[#{javascript:viewScope.myVar = "initial value";}]]></xp:this.afterPageLoad>
<xp:comboBox id="comboBox1">
<xp:selectItem itemLabel="val 1" itemValue="val1"></xp:selectItem>
<xp:selectItem itemLabel="val 2" itemValue="val2"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true" refreshMode="partial"
refreshId='#{javascript:(viewScope.myVar == "someValue") ? "idToUpdate" : ""}'
onComplete="alert('ssjs code done');">
<xp:this.action><![CDATA[#{javascript:viewScope.myVar = "someValue";}]]></xp:this.action>
</xp:eventHandler>
</xp:comboBox>
<xp:panel id="idToUpdate">
<xp:this.rendered><![CDATA[#{javascript:(viewScope.myVar == "someValue")}]]></xp:this.rendered>
table data
</xp:panel>
</xp:view>
表数据
我尝试实现您所说的内容,但仍然得到相同的错误:(看看我的新代码,如果你看到了什么错误,请告诉我。我还意识到我的打印语句只在加载时执行,而不是刷新。所有服务器端代码都应该在
标记中,而不是
。尝试使用我的示例中的语法…,因为默认情况下隐藏了表,所以需要计算。)refreshId属性…看看我的更新答案,伙计,你真厉害!这解决了我的问题!非常感谢。
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.afterPageLoad><![CDATA[#{javascript:viewScope.myVar = "initial value";}]]></xp:this.afterPageLoad>
<xp:comboBox id="comboBox1">
<xp:selectItem itemLabel="val 1" itemValue="val1"></xp:selectItem>
<xp:selectItem itemLabel="val 2" itemValue="val2"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true" refreshMode="partial"
refreshId='#{javascript:(viewScope.myVar == "someValue") ? "idToUpdate" : ""}'
onComplete="alert('ssjs code done');">
<xp:this.action><![CDATA[#{javascript:viewScope.myVar = "someValue";}]]></xp:this.action>
</xp:eventHandler>
</xp:comboBox>
<xp:panel id="idToUpdate">
<xp:this.rendered><![CDATA[#{javascript:(viewScope.myVar == "someValue")}]]></xp:this.rendered>
table data
</xp:panel>
</xp:view>