我需要一个组合框" PriceList"与显示错误控制相关联。
我是另一个领域" Price"使用OnChange事件设置" Pricelist"的必需属性。如果价格被输入"价目表"组合框所需的属性设置为false,否则为空白," Pricelist"已启用。
两个字段和xpage都禁用了客户端验证。
创建文档时,combox在开头显示错误消息。如果我改变并清空"价格","价值表"虽然required属性为true,但错误控件不会显示消息。
这里有什么问题?
价目表代码:
<xp:comboBox
id="comboBox7"
value="#{document1.PList1}"
style="width:99.0px"
disableClientSideValidation="true">
<xp:this.validators>
<xp:validateRequired
message="Required">
</xp:validateRequired>
</xp:this.validators>
<xp:this.required><![CDATA[#{javascript:var price11:com.ibm.xsp.component.xp.XspInputText = getComponent("price11");
var a=price11.getValueAsString()
if (a == ""){
return true;
}else{
return false;
}}]]></xp:this.required>
<xp:this.disabled><![CDATA[#{javascript:var price11:com.ibm.xsp.component.xp.XspInputText = getComponent("price11");
var a=price11.getValueAsString();
if ( a==""){
return false;
} else {
return true;
}}]]></xp:this.disabled>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var result = [];
var pricelist = @DbLookup("" , "Keywords","Price List", 2)
result.push("")
for (var i = 0; i < pricelist.length; i++) {
var eachName = pricelist[i];
result.push(eachName);
}
return result;}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
价格代码:
<xp:inputText
value="#{document1.Price1}"
id="price11"
style="width:80px"
required="true"
disableClientSideValidation="true">
<xp:this.validators>
<xp:validateRequired
message="Required field">
</xp:validateRequired>
</xp:this.validators>
<xp:eventHandler event="onchange" submit="true" refreshMode="complete">
<xp:this.action>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var comboBox7:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox7");
var price11:com.ibm.xsp.component.xp.XspInputText = getComponent("price11");
var a=price11.getValueAsString();
if(a !=="" ){
//if(comboBox7.isRequired()==true){
//comboBox7.setRequired(false);
//}
//var result = [];
//var pricelist = @DbLookup("" , "Keywords","Price List", 2)
//result.push("")
//for (var i = 0; i < pricelist.length; i++) {
//var eachName = pricelist[i];
//result.push(eachName);
//}
//comboBox7.setValue(result);
comboBox7.setRequired(false);
comboBox7.setDisabled(true);
} else {
comboBox7.setDisabled(false);
comboBox7.setRequired(true);
}
}]]></xp:this.script>
</xp:executeScript>
</xp:this.action></xp:eventHandler></xp:inputText>
答案 0 :(得分:0)
我建议使用SSJS调试器或打印语句来解决这里发生的事情。代码似乎非常复杂。首先,您有将ComboBox上的setRequired设置为true或false的代码。但是只有在验证通过后才能运行。它也会进行全面刷新,因此您似乎正在重新加载页面。此外,您正在计算组合框中的必需属性,因此即使您进行部分刷新并根据需要进行设置,RenderResponse阶段也将重新计算所需的属性并覆盖onChange事件设置的任何状态。残疾人财产也是如此。
如果根据需要设置组件,则已经发生了对该刷新的验证。因此,只有在用户下次提交页面时才需要它。此时验证将失败,因此除非您禁用验证器,否则不能将其设置为未禁用。但是在用户输入值之前,禁用验证器是在服务器端完成的。
我的建议是将验证移到save方法,并从底层数据源而不是组件开始工作。如果你想将组件标记为有效,那么有一个setValid()方法,并且有关于添加FacesMessage以指示错误并将其绑定到组件的博客文章。
对于更高级的方法,Tim Tripcony做了一个NotesIn9,关于使用绑定属性来链接组件以进行此类相关验证。但这需要Java。