[英]JSF2 or primefaces p:selectManyCheckbox styling with icons
[英]How to insert PrimeFaces p:selectManycheckbox value to database
我是primeface的新手,但我無法將我的primefaces SelectManyCheckbox值保存到數據庫。 我正在使用休眠和MySQL。 示例代碼如下
我的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>
我的豆是:
private String[] selectedClass;
private List<CertificateClass> examinationPart=new ArrayList<CertificateClass>();
getter()
setter()
我要保存復選框的方法是:
private void saveExaminationDetails()
{
examDetails.setElementaryPrinciples(); //bolean field
examDetails.setLightinig()
//no of setter
}
我無法找出如何在方法上設置選定和未選定復選框的值
查看primefaces展示櫃: http ://primefaces-rocks.appspot.com/ui/selectManyCheckbox.jsf
從選擇的值examinationFormBean.examinationPart
應設置p:selectManyCheckbox
屬性value
,然后你可以使用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>
然后,您可以在saveExaminationDetails()
使用selectedExaminationParts
p:selectManyCheckbox
選擇值正在托管bean上投標一個String
Collection
( List
, ArrayList
...等)。 您只需要保存Collection
存在的每個String
。
我會給你一個例子,說明如何做到這一點:
例:
...
@Named(value = "myBean")
@SessionScoped
public class InscricaoBean implements Serializable {
...
private List<String> selectedElemnts = new ArrayList();
//selectedElements get and set
...
在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>
...
保存方法:
...
private void saveExaminationDetails()
{
for (String nameAux: selectedElemnts )
{
//you save the data here
}
}
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.