admin管理员组文章数量:1022719
I have a button has action which can set myBackingBean.myString, and onclick event calls js method to alert that value. I just want to get the value of myString from backing bean by using javascript.
I have a hidden output which has value from backing bean:
h:outputText id="myOutput" rendered="false" value="#{myBackingBean.myString}"
then I need to alert this value in javascript fxn which triggered by a button:
function myFunction() {
var outPut= document.getElementById("myForm:myOutput").value;
...
}
but i got Object required
error. How can i fix this?
thanks in advance.
I have a button has action which can set myBackingBean.myString, and onclick event calls js method to alert that value. I just want to get the value of myString from backing bean by using javascript.
I have a hidden output which has value from backing bean:
h:outputText id="myOutput" rendered="false" value="#{myBackingBean.myString}"
then I need to alert this value in javascript fxn which triggered by a button:
function myFunction() {
var outPut= document.getElementById("myForm:myOutput").value;
...
}
but i got Object required
error. How can i fix this?
thanks in advance.
2 Answers
Reset to default 1Make you sure that the h:outputText is rendered (rendered="false" could just not add it to the DOM. If it does not render, it can't be accessed. If you need it hidden, use h:inputHidden instead).
Then make sure that it renders an HTML tag as or acting like a container with the id attribute as "myForm:myOutput".
Also, the .value javascript accesor is used for input tags, so use inerHTML instead.
You need not always to have a hidden field to access the Bean Property. You can do it as below.
<h:mandButton value="Show" onclick="alert('#{myBackingBean.myString}');"/>
But if you want to change the value of 'myString' when you click the button and then you want to display the new value you should use a <a4j:mandButton/>
and it's onComplete attribute as below.
<a4j:mandButton value="Change" action="#{myBackingBean.changeString()}" onplete="alert('#{myBackingBean.myString}');" />
I have a button has action which can set myBackingBean.myString, and onclick event calls js method to alert that value. I just want to get the value of myString from backing bean by using javascript.
I have a hidden output which has value from backing bean:
h:outputText id="myOutput" rendered="false" value="#{myBackingBean.myString}"
then I need to alert this value in javascript fxn which triggered by a button:
function myFunction() {
var outPut= document.getElementById("myForm:myOutput").value;
...
}
but i got Object required
error. How can i fix this?
thanks in advance.
I have a button has action which can set myBackingBean.myString, and onclick event calls js method to alert that value. I just want to get the value of myString from backing bean by using javascript.
I have a hidden output which has value from backing bean:
h:outputText id="myOutput" rendered="false" value="#{myBackingBean.myString}"
then I need to alert this value in javascript fxn which triggered by a button:
function myFunction() {
var outPut= document.getElementById("myForm:myOutput").value;
...
}
but i got Object required
error. How can i fix this?
thanks in advance.
2 Answers
Reset to default 1Make you sure that the h:outputText is rendered (rendered="false" could just not add it to the DOM. If it does not render, it can't be accessed. If you need it hidden, use h:inputHidden instead).
Then make sure that it renders an HTML tag as or acting like a container with the id attribute as "myForm:myOutput".
Also, the .value javascript accesor is used for input tags, so use inerHTML instead.
You need not always to have a hidden field to access the Bean Property. You can do it as below.
<h:mandButton value="Show" onclick="alert('#{myBackingBean.myString}');"/>
But if you want to change the value of 'myString' when you click the button and then you want to display the new value you should use a <a4j:mandButton/>
and it's onComplete attribute as below.
<a4j:mandButton value="Change" action="#{myBackingBean.changeString()}" onplete="alert('#{myBackingBean.myString}');" />
本文标签: jsf 2how to use javascript to get jsf houtputText valueStack Overflow
版权声明:本文标题:jsf 2 - how to use javascript to get jsf h:outputText value? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745563532a2156309.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论