[英]p:selectManyCheckbox : getting the selected value into bean
I want to assign a List of users to a project then my xhtml is like this: 我想为项目分配用户列表,然后我的xhtml像这样:
<p:dataTable id="dta" value="#{UtilisateurComponent.listUtilisateurs()}" var="current" rows="15" paginator="true" paginatorPosition="bottom">
<p:column>
<h:selectManyCheckbox id="selectUser" value="#{ProjetComponent.projet.utilisateurs}" >
<f:selectItem var="utilisateurs" value="#{utilisateurs.iduser}" itemLabel=""/>
<f:converter converterId="entityConverter" />
</h:selectManyCheckbox>
</p:column>
</p:dataTable>
</h:panelGrid>
<h:panelGroup>
<p:commandButton image="save" ajax="false" style="margin-right:20px;" value="#{projetmsgs['navigation.save']}" action="#{ProjetComponent.saveProjetUtilisateurs1(ProjetComponent.projet,ProjetComponent.projet.utilisateurs)}"/>
</h:panelGroup>
</p:panel>
and this is the method save in the ProjetComponent: 这是保存在ProjetComponent中的方法:
private Projet projet;
private Utilisateur utilisateurs;
@Autowired
private ProjetDAO projetDAO;
@Autowired
private UtilisateurDAO utilisateurDAO;
@Autowired
private ProjetService projetService;
@Transactional
public String saveProjetUtilisateurs1(Projet p, List<Utilisateur> utilisateur) {
projet = projetService.saveProjetUtilisateurs(p, utilisateur);
return "/jsf/projet/viewProjet.xhtml";
}
and this the method save in the ProjetService class called by the component ProjetCompnent: 并且此方法保存在由组件ProjetCompnent调用的ProjetService类中:
@Transactional
public Projet saveProjetUtilisateurs(Projet projet,List<Utilisateur> ut)
{
projet.setAvancement(projet.getAvancement());
projet.setConfidentialite(projet.getConfidentialite());
projet.setDatedebut(projet.getDatedebut());
projet.setDatefineffective(projet.getDatefineffective());
projet.setDatefinprevu(projet.getDatefinprevu());
projet.setDescription(projet.getDescription());
projet.setDurreprojet(projet.getDurreprojet());
projet.setNomprojet(projet.getNomprojet());
projet.setObjectifprojet(projet.getObjectifprojet());
projet.setStatut(projet.getStatut());
projet.setUtilisateurs(ut);
projet = projetDAO.store(projet);
projetDAO.flush();
return projet;
}
and this is the Projet Entity: 这是Projet实体:
@Entity
public class Projet implements Serializable {
@Id
private Integer idprojet;
@ManyToMany(mappedBy = "projets", fetch = FetchType.LAZY)
java.util.List<com.gestion.projet.domain.Utilisateur> utilisateurs;
}
screentshot: 屏幕截图:
and the problem is getting an empty list of users: 问题是用户列表为空:
Try using p:ajax
on h:selectManyCheckbox
. 尝试在h:selectManyCheckbox
上使用p:ajax
。
<p:ajax event="change" process="@this" />
If you want the Checkbox based multiple selection on Primeface Datatable, no need to use the explicit h:selectManyCheckbox
. 如果要在Primeface Datatable上基于复选框的多项选择,则无需使用显式的h:selectManyCheckbox
。
You could do that by specifying selectionMode="multiple"
attribute on first/last p:column
. 您可以通过在first / last p:column
上指定selectionMode="multiple"
属性来实现。
See the Primefaces Showcase . 请参阅Primefaces展示柜 。
this is the entityConverter: 这是entityConverter:
@FacesConverter(value = "entityConverter")
public class EntityConverter implements Converter {
private static Map<Object, String> entities = new WeakHashMap<Object, String>();
public String getAsString(FacesContext context, UIComponent component, Object entity) {
synchronized (entities) {
if (!entities.containsKey(entity)) {
String uuid = UUID.randomUUID().toString();
entities.put(entity, uuid);
return uuid;
} else {
return entities.get(entity);
}
}
}
public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
for (Entry<Object, String> entry : entities.entrySet()) {
if (entry.getValue().equals(uuid)) {
return entry.getKey();
}
}
return null;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.