使用JSF的单选复选框 [英] Single Select Checkbox Using JSF
本文介绍了使用JSF的单选复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在JSF中创建注册表单,并且我需要使用复选框的字段为活动",非活动",并且这些复选框应为单选". (注意:我可以使用单选按钮来解决问题,但是由于某些问题,我必须使用复选框.)
I am creating registration form in JSF and I have field as Active, Inactive where I need to use check boxes and these checkboxes should be SINGLE SELECT ONLY. (Note: I can use radio button and solve the problem, however due to some problem I have to use check boxes).
请建议我如何完成此工作?
Please suggest me how to get this done?
预先感谢...
推荐答案
我认为您需要的是<h:selectBooleanCheckbox>
.绑定到该组件的值只能是true(有效)或false(无效).它将类似于以下内容:
I think what you need is <h:selectBooleanCheckbox>
. The value binded to this component can only be either true (Active) or false (Inactive). It will be something like the following:
<h:selectBooleanCheckbox id="active" value="#{mrBean.active}" >
<f:ajax render="inactive" listener="#{mrBean.onActiveStatusChange}" />
</h:selectBooleanCheckbox>
<h:selectBooleanCheckbox id="inactive" value="#{mrBean.inactive}" >
<f:ajax render="active" listener="#{mrBean.onInactiveStatusChange}" />
</h:selectBooleanCheckbox>
@ManagedBean
@RequestScoped
public class MrBean {
private boolean active;
private boolean inactive;
@PostConstruct
public void prepareMrBean() {
this.active = true;
}
public void onActiveStatusChange() {
if (active) inactive = false;
}
public void onInactiveStatusChange() {
if (inactive) active = false;
}
}
这篇关于使用JSF的单选复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文