p:wizardonnext不停'navigation'
p:wizard onnext not stopping 'navigation'
当我使用 p:wizard 时,我对 onnext 属性使用自定义处理程序,该处理程序只是警告和 return false 来测试行为。
我从 primefaces 库中的 wizard.js 了解到,单击向导的下一步按钮时,应执行以下代码:
next: function () {
if (this.cfg.onnext) {
var b = this.cfg.onnext.call(this);
if (b == false) {
return
}
}
var a = this.cfg.steps[this.getStepIndex(this.currentStep) + 1];
this.loadStep(a, false)
}
我的理解是这样的:向导首先执行自定义处理程序,如果自定义处理程序 return 为假,则不应加载下一个选项卡(调用 PrimeFaces.widget.Wizard.loadStep)。但实际上发生的是自定义处理程序被调用 ,然后 被调用 PrimeFaces.widget.Wizard.loadStep 向导的函数,因此下一个选项卡被聚焦。
是我的理解有误,还是PF的bug?
刚查了一下,'order'没问题,所以你说的then没有错,问题是叫反正,就算你(认为)你return错了。
问题是这样的:
this.cfg.onnext.call(this);
它总是 returns undefined
。它在 5.3 和 5.1、5.0 和 4.0 中都失败了,所以这最初让我认为它要么从未经过全面测试,要么在最近的浏览器中发生了一些变化。但实际发生的是定义的函数(在我的例子中是演示)被包裹在一个匿名函数中
function (){demo()}
没有 return 值,所以不是
function (){return demo()}
没有 'return',导致它永远不会 return 从你的函数中获取你 return 的实际值,但总是 'undefined'。
这让我想到在 onnext="demo()"
中添加 return... 所以使其成为 onnext="return demo()"
瞧,它起作用了。
请记住,这很容易使用 javascript 调试器进行调试,并且您始终可以覆盖函数以添加额外的日志语句。
我测试的代码:
<html xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head />
<h:body>
<h:form id="form">
<p:wizard onnext="demo()" flowListener="#{mailTemplateBean.onFlowProcess}">
<p:tab title="Step 1"/>
<p:tab title="Step 2"/>
<p:tab title="Step 3"/>
<p:tab title="Step 4"/>
</p:wizard>
<script>
PrimeFaces.widget.Wizard.prototype.next = function() {
if(this.cfg.onnext) {
var value = this.cfg.onnext.call(this);
console.log("Return: " + value + " function: " + this.cfg.onnext);
if(value === false) {
return;
}
}
var targetStepIndex = this.getStepIndex(this.currentStep) + 1;
if(targetStepIndex < this.cfg.steps.length) {
var stepToGo = this.cfg.steps[targetStepIndex];
this.loadStep(stepToGo, false);
}
}
function demo() {
var bla = confirm("Sure?");
console.log("Choosen: " + bla);
return bla;
}</script>
</h:form>
</h:body>
</html>
并且请向 PF 提出问题并要求他们将其添加到文档中,或者让他们修复函数中的 'wrapping' 添加一个 automagic return.
当我使用 p:wizard 时,我对 onnext 属性使用自定义处理程序,该处理程序只是警告和 return false 来测试行为。
我从 primefaces 库中的 wizard.js 了解到,单击向导的下一步按钮时,应执行以下代码:
next: function () {
if (this.cfg.onnext) {
var b = this.cfg.onnext.call(this);
if (b == false) {
return
}
}
var a = this.cfg.steps[this.getStepIndex(this.currentStep) + 1];
this.loadStep(a, false)
}
我的理解是这样的:向导首先执行自定义处理程序,如果自定义处理程序 return 为假,则不应加载下一个选项卡(调用 PrimeFaces.widget.Wizard.loadStep)。但实际上发生的是自定义处理程序被调用 ,然后 被调用 PrimeFaces.widget.Wizard.loadStep 向导的函数,因此下一个选项卡被聚焦。
是我的理解有误,还是PF的bug?
刚查了一下,'order'没问题,所以你说的then没有错,问题是叫反正,就算你(认为)你return错了。
问题是这样的:
this.cfg.onnext.call(this);
它总是 returns undefined
。它在 5.3 和 5.1、5.0 和 4.0 中都失败了,所以这最初让我认为它要么从未经过全面测试,要么在最近的浏览器中发生了一些变化。但实际发生的是定义的函数(在我的例子中是演示)被包裹在一个匿名函数中
function (){demo()}
没有 return 值,所以不是
function (){return demo()}
没有 'return',导致它永远不会 return 从你的函数中获取你 return 的实际值,但总是 'undefined'。
这让我想到在 onnext="demo()"
中添加 return... 所以使其成为 onnext="return demo()"
瞧,它起作用了。
请记住,这很容易使用 javascript 调试器进行调试,并且您始终可以覆盖函数以添加额外的日志语句。
我测试的代码:
<html xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head />
<h:body>
<h:form id="form">
<p:wizard onnext="demo()" flowListener="#{mailTemplateBean.onFlowProcess}">
<p:tab title="Step 1"/>
<p:tab title="Step 2"/>
<p:tab title="Step 3"/>
<p:tab title="Step 4"/>
</p:wizard>
<script>
PrimeFaces.widget.Wizard.prototype.next = function() {
if(this.cfg.onnext) {
var value = this.cfg.onnext.call(this);
console.log("Return: " + value + " function: " + this.cfg.onnext);
if(value === false) {
return;
}
}
var targetStepIndex = this.getStepIndex(this.currentStep) + 1;
if(targetStepIndex < this.cfg.steps.length) {
var stepToGo = this.cfg.steps[targetStepIndex];
this.loadStep(stepToGo, false);
}
}
function demo() {
var bla = confirm("Sure?");
console.log("Choosen: " + bla);
return bla;
}</script>
</h:form>
</h:body>
</html>
并且请向 PF 提出问题并要求他们将其添加到文档中,或者让他们修复函数中的 'wrapping' 添加一个 automagic return.