admin管理员组文章数量:1394769
My codes are bellow,
JSF :
<h:selectBooleanCheckbox id="bundleAdded" value="#{accountAdjustmentBean.bundleAdded}"
required="true" onchange="if(this.checked != bundleAdded) {
alert('Click works')}
else { alert('Not worked!') }"/>
<h:message styleClass="errors" for="bundleAdded"/>
My backing bean :
public class AccountAdjustmentsBean extends BaseBean {
private boolean bundleAdded;
// public setters, getters and other stuffs
}
face-config.xml :
<managed-bean>
<description>
Backing bean used do account adjustments
</description>
<managed-bean-name>accountAdjustmentBean</managed-bean-name>
<managed-bean-class>beyondm.bi.customercare.view.bean.AccountAdjustmentsBean</managed-bean-class>
<!-- NOTE!: proper behaviour of this bean relies on being created for each request -->
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>serviceLocator</property-name>
// propagates.......
When I checked the box, there is no alert. Where is the problem? I can't figure out it. Can anyone point out it?
Thanks!
My codes are bellow,
JSF :
<h:selectBooleanCheckbox id="bundleAdded" value="#{accountAdjustmentBean.bundleAdded}"
required="true" onchange="if(this.checked != bundleAdded) {
alert('Click works')}
else { alert('Not worked!') }"/>
<h:message styleClass="errors" for="bundleAdded"/>
My backing bean :
public class AccountAdjustmentsBean extends BaseBean {
private boolean bundleAdded;
// public setters, getters and other stuffs
}
face-config.xml :
<managed-bean>
<description>
Backing bean used do account adjustments
</description>
<managed-bean-name>accountAdjustmentBean</managed-bean-name>
<managed-bean-class>beyondm.bi.customercare.view.bean.AccountAdjustmentsBean</managed-bean-class>
<!-- NOTE!: proper behaviour of this bean relies on being created for each request -->
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>serviceLocator</property-name>
// propagates.......
When I checked the box, there is no alert. Where is the problem? I can't figure out it. Can anyone point out it?
Thanks!
Share Improve this question edited Aug 10, 2011 at 6:06 Abimaran Kugathasan asked Aug 10, 2011 at 5:24 Abimaran KugathasanAbimaran Kugathasan 32.5k11 gold badges80 silver badges108 bronze badges3 Answers
Reset to default 3You're expecting the bundleAdded
property to be magically present as a JavaScript variable in the onclick
function scope. This is not true. Java/JSF and JavaScript does not run in the same environment. You should see Java/JSF more as a HTML/CSS/JS code generator. Java/JSF runs in webserver, generates HTML/CSS/JS and sends it to webbrowser. HTML/CSS/JS runs in the webbrowser.
You need to let Java/JSF print the bundleAdded
property value using EL.
onclick="if(this.checked != #{accountAdjustmentBean.bundleAdded}) ..."
This condition is invalid: if(this.checked != bundleAdded) I think you just need to do: if(this.checked)
If you are trying to see if the value (bundleAdded) has actually been set then you shouldn't use Javascript to do it as this is only on the client side (unless of course you use Ajax but looking at your example I can't see why you would want to).
I do not know JSF but IMHO it should be
if(this.checked && this.value=='bundleAdded'){alert('Worked');}else{alert('failed');}
本文标签: javaCheckbox39s onchange method not working with jsf and javascriptStack Overflow
版权声明:本文标题:java - Checkbox's onchange method not working with jsf and javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744103741a2590978.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论