[英]JSF SelectManyCheckbox/SelectOneMenu example
I would like to make a little html page where you can select the operators you would like to use in your calculation in a checkbox and under the checkbox there is a dropdown list which has the above selected operators as content. 我想制作一个HTML页面,您可以在其中选择要在计算中使用的运算符,并在该复选框下方有一个下拉列表,其中包含上述选定的运算符作为内容。 Everytime you check/uncheck an operation, the selectable contents of the dropdown list should change.
每次您选择/取消选择一项操作时,下拉列表的可选内容都应更改。 I want to make this with a ValueChangeListener but I have no idea how to implement a value change listener in this exercise.
我想使用ValueChangeListener做到这一点,但我不知道如何在本练习中实现值更改侦听器。
Here is my index.html 这是我的index.html
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:selectManyCheckbox onchange = "submit()">
<f:selectItems value = "#{selectManyCheckboxBean.list}" valueChangeListener = ""/>
</h:selectManyCheckbox>
<h:outputText id = "outputText" value = ""/>
<h:selectOneMenu value = "">
<f:selectItems value = ""/>
</h:selectOneMenu>
</h:form>
</h:body>
And here is my SelectManyCheckboxBean.java 这是我的SelectManyCheckboxBean.java
@ManagedBean
@SessionScoped
public class SelectManyCheckboxBean {
private List<SelectItem> list;
public SelectManyCheckboxBean() {
list = new ArrayList<>();
list.add(new SelectItem('+'));
list.add(new SelectItem('-'));
list.add(new SelectItem('*'));
list.add(new SelectItem('/'));
}
public List<SelectItem> getList() {
return list;
}
public void operatorValueChange (ValueChangeEvent event) {
}
}
Could anybody give me a solution or at least a code snippet for the value change listener? 有人可以给我一个解决方案,或者至少为价值变更侦听器提供一个代码片段吗? My main problem is that I don't know how to tell the value change listener that it should add the selected operators to a list when they have been checked in the checkboxes above.
我的主要问题是,我不知道如何告诉值更改侦听器在上面的复选框中选中选定的运算符后,应将它们添加到列表中。
Just set a selectOneMenu
attribute value
to #{selectManyCheckboxBean.list}
. 只需将
selectOneMenu
属性value
设置为#{selectManyCheckboxBean.list}
。 That's where your checked values are. 那就是您检查的值所在的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.