[英]How to insert PrimeFaces p:selectManycheckbox value to database
I am new to primefaces and i have a problem to save my primefaces SelectManyCheckbox value to database. 我是primeface的新手,但我无法将我的primefaces SelectManyCheckbox值保存到数据库。 I am using hibernate and mysql.
我正在使用休眠和MySQL。 The sample code are give as below
示例代码如下
My xhtml pages code is: 我的xhtml页面代码是:
<h:outputText value="#{msg['elicense.examinationform.personal.classofcertificates']}"/>
<p:selectManyCheckbox id="grid" value="#{examinationFormBean.selectedClass}" layout="grid" columns="1">
<f:selectItems value="#{examinationFormBean.examinationPart}"var="className" itemLabel="#{className.name}" itemValue="#{className}" />
</p:selectManyCheckbox>
My bean is: 我的豆是:
private String[] selectedClass;
private List<CertificateClass> examinationPart=new ArrayList<CertificateClass>();
getter()
setter()
The method where I want to save my checkbox is: 我要保存复选框的方法是:
private void saveExaminationDetails()
{
examDetails.setElementaryPrinciples(); //bolean field
examDetails.setLightinig()
//no of setter
}
I am not able to find out how I will set the selected and not selected checkbox value on the method 我无法找出如何在方法上设置选定和未选定复选框的值
Look at primefaces showcases: http://primefaces-rocks.appspot.com/ui/selectManyCheckbox.jsf 查看primefaces展示柜: http ://primefaces-rocks.appspot.com/ui/selectManyCheckbox.jsf
Selected values from examinationFormBean.examinationPart
should setting in p:selectManyCheckbox
attribute value
and then you can used this selected list in bean method. 从选择的值
examinationFormBean.examinationPart
应设置p:selectManyCheckbox
属性value
,然后你可以使用bean方法选择这个名单。 For your example should be something: 对于您的示例应该是:
<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>
And then you can use selectedExaminationParts
in your saveExaminationDetails()
然后,您可以在
saveExaminationDetails()
使用selectedExaminationParts
The p:selectManyCheckbox
select values are biding a String
Collection
( List
, ArrayList
... etc) on managed bean. p:selectManyCheckbox
选择值正在托管bean上投标一个String
Collection
( List
, ArrayList
...等)。 You just need to save each String
existent on the Collection
. 您只需要保存
Collection
存在的每个String
。
I will give you an example showing how you can do that: 我会给你一个例子,说明如何做到这一点:
Example: 例:
...
@Named(value = "myBean")
@SessionScoped
public class InscricaoBean implements Serializable {
...
private List<String> selectedElemnts = new ArrayList();
//selectedElements get and set
...
On JSF you have something like: 在JSF上,您有类似以下内容:
...
<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>
...
On save method: 保存方法:
...
private void saveExaminationDetails()
{
for (String nameAux: selectedElemnts )
{
//you save the data here
}
}
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.