Jsf 如何向数据库插入素面p:selectManycheckbox值

Jsf 如何向数据库插入素面p:selectManycheckbox值,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我不熟悉primefaces,在将primefaces SelectManyCheckbox值保存到数据库时遇到问题。我正在使用hibernate和mysql。示例代码如下所示 我的xhtml页面代码是: 我无法确定如何在方法上设置选中和未选中复选框值查看primefaces展示: 检查FormBean.CheckPart中的选定值应在p:selectManyCheckbox属性值中设置,然后您可以在bean方法中使用此选定列表。 例如,你的例子应该是: <p:selectMany

我不熟悉primefaces,在将primefaces SelectManyCheckbox值保存到数据库时遇到问题。我正在使用hibernate和mysql。示例代码如下所示

我的xhtml页面代码是:


我无法确定如何在方法上设置选中和未选中复选框值

查看primefaces展示:

检查FormBean.CheckPart中的选定值应在p:selectManyCheckbox属性值中设置,然后您可以在bean方法中使用此选定列表。 例如,你的例子应该是:

    <p:selectManyCheckbox id="grid" value="#{examinationFormBean.selectedExaminationParts}" layout="grid" columns="1">
                <f:selectItems value="#{examinationFormBean.examinationParts}" var="className" itemLabel="#{className.name}" itemValue="#{className}" /> 
</p:selectManyCheckbox>
然后,您可以在SaveExaminationalDetails中使用SelectedExaminationalParts

p:selectManyCheckbox选择值与字符串集合列表、ArrayList。。。管理bean上的etc。您只需要保存集合中存在的每个字符串

我将给您举一个例子,说明如何做到这一点:

例如:

...
@Named(value = "myBean")
@SessionScoped
public class InscricaoBean implements Serializable {
...
private List<String> selectedElemnts = new ArrayList();

//selectedElements get and set
...

我的问题是我需要一个复选框。如果是检查其应显示为真,否则为假有什么问题?您有ExaminationalFormBean.SelectedExaminationalParts和ExaminationalFormBean.ExaminationalParts列表。因此,您可以返回一些其他对象,而不仅仅是检查零件模型,如果您需要,为此需要使用getAsObject和getAsString方法实现转换器。如果我没有错,请选择p:selectManyCheckbox将选择值保存在String CollectionList、ArrayList。。。等等。你只需要保存集合中的每个元素。我会发布答案好的,结束这个问题,可以吗?不,请帮我解决它,因为我没有找到解决方案
        private void saveExaminationDetails()
          {
             examDetails.setElementaryPrinciples();  //bolean field
             examDetails.setLightinig()
             //no of setter
           }
    <p:selectManyCheckbox id="grid" value="#{examinationFormBean.selectedExaminationParts}" layout="grid" columns="1">
                <f:selectItems value="#{examinationFormBean.examinationParts}" var="className" itemLabel="#{className.name}" itemValue="#{className}" /> 
</p:selectManyCheckbox>
...
@Named(value = "myBean")
@SessionScoped
public class InscricaoBean implements Serializable {
...
private List<String> selectedElemnts = new ArrayList();

//selectedElements get and set
...
...
<h:outputText value="#{msg['elicense.examinationform.personal.classofcertificates']}"/> 
        <p:selectManyCheckbox id="grid" value="#{examinationFormBean.selectedElemnts}"...>
            <f:selectItems value="#{examinationFormBean.examinationPart}"var="className"   
            itemLabel="#{className.name}" itemValue="#{className}" />
      </p:selectManyCheckbox>
...
...
private void saveExaminationDetails()
{
   for (String nameAux: selectedElemnts )
   {
       //you save the data here
   }
}
...