I want to create a group of checkbox ,but the user have the right to check just 3, each checkbox represent a criteria of research in my database(eg 开发者_运维知识库:if user check checkbox by priority I should concat this search criteria to my request SQL). I have done some research in the internet but I have just found examples with ajax ,I dont want to use it.And I want to know should I use selectBooleanCheckbox OR selectManyCheckbox Is there a simple example?
JSF
<h:selectManyCheckbox value="#{myBean.values}">
<f:selectItem itemValue="1" itemLabel="Value - 1" />
<f:selectItem itemValue="2" itemLabel="Value - 2" />
<f:selectItem itemValue="3" itemLabel="Value - 3" />
</h:selectManyCheckbox>
Bean
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="myBean")
@RequestScoped
public class MyBean{
public String[] values;
//getters setters
}
Update:
To print array values as mentioned in the example, you can have following util method
public String getFavNumber3InString() {
return Arrays.toString(favNumber3);
}
- Reference
You should use selectManyCheckbox
. And here is a simple example for you to follow
精彩评论