我从Primefaces 5.2迁移到6.1。但是,我在inputNumber中使用了widgetVar,用于使用javascript解析操作。但是,widgetVar不适用于6.1版本的inputNumber。
示例:
HEAD
<h:head>
<title>TODO supply a title</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<h:outputScript name="jquery/jquery.js" library="primefaces" />
<h:outputScript name="jquery/jquery-plugins.js" library="primefaces" />
<h:outputScript name="core.js" library="primefaces" />
<h:outputScript name="components.js" library="primefaces" />
</h:head>
<p:inputNumber thousandSeparator="." decimalSeparator="," widgetVar="wInput"
onchange="valueForInput('wInput')"/>
<script>
function valueForInput(wInput){
var inputNumber = PF(wInput);
console.log(inputNumber.getValue());
}
</script>
CONSOLE ERROR
Uncaught TypeError: Cannot read property 'getValue' of undefined
at valueForInput (http://localhost:8084/sgwapp/:15:40)
at HTMLInputElement.onchange (http://localhost:8084/sgwapp/:11:2197)
at Object.trigger (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:4585:27)
at HTMLInputElement.<anonymous> (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:5289:17)
at Function.each (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:384:23)
at jQuery.fn.init.each (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:136:17)
at jQuery.fn.init.trigger (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:5288:15)
at jQuery.fn.init.jQuery.fn.(anonymous function) [as change] (http://localhost:8084/sgwapp/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=6.1:8481:9)
at c.setValueToHiddenInput (http://localhost:8084/sgwapp/javax.faces.resource/inputnumber/inputnumber.js.xhtml?ln=primefaces&v=6.1:3:1714)
at copyValueToHiddenInput (http://localhost:8084/sgwapp/javax.faces.resource/inputnumber/inputnumber.js.xhtml?ln=primefaces&v=6.1:3:1542)
valueForInput @ (index):15
onchange @ (index):11
trigger @ jquery.js.xhtml?ln=primefaces&v=6.1:4585
(anonymous) @ jquery.js.xhtml?ln=primefaces&v=6.1:5289
each @ jquery.js.xhtml?ln=primefaces&v=6.1:384
each @ jquery.js.xhtml?ln=primefaces&v=6.1:136
trigger @ jquery.js.xhtml?ln=primefaces&v=6.1:5288
jQuery.fn.(anonymous function) @ jquery.js.xhtml?ln=primefaces&v=6.1:8481
setValueToHiddenInput @ inputnumber.js.xhtml?ln=primefaces&v=6.1:3
copyValueToHiddenInput @ inputnumber.js.xhtml?ln=primefaces&v=6.1:3
init @ inputnumber.js.xhtml?ln=primefaces&v=6.1:3
e.(anonymous function) @ core.js.xhtml?ln=primefaces&v=6.1:5
c @ core.js.xhtml?ln=primefaces&v=6.1:5
createWidget @ core.js.xhtml?ln=primefaces&v=6.1:1
cw @ core.js.xhtml?ln=primefaces&v=6.1:1
(anonymous) @ (index):11
fire @ jquery.js.xhtml?ln=primefaces&v=6.1:3148
fireWith @ jquery.js.xhtml?ln=primefaces&v=6.1:3260
ready @ jquery.js.xhtml?ln=primefaces&v=6.1:3472
completed @ jquery.js.xhtml?ln=primefaces&v=6.1:3503
答案 0 :(得分:2)
您可以在堆栈中看到在窗口小部件构造期间触发了onchange侦听器,这就是为什么您无法使用PF
函数找到它 - 它还没有准备好。
无论如何,您可能对初始值不感兴趣,因此请跳过此调用:
function valueForInput(wInput){
if (PF(wInput)) {
var inputNumber = PF(wInput);
console.log(inputNumber.getValue());
}
}