Datatable multiple Preselection

UI Components for JSF
Post Reply
Luuzz
Posts: 32
Joined: 28 Mar 2011, 15:21

10 Nov 2011, 20:34

Hello there,
I am a happy primefaces user.
i have few issues about datatable with nultiple selection.
Here is my code

Code: Select all

<p:outputPanel xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" rendered="false"
	id="droitsFonctionPanel">
	<h:form>
		<h:panelGrid columns="3" width="100%">
			<h:outputText value="Module" />
			<h:selectOneMenu value="#{droitsFonctionBean.selectedModule}">
				<f:selectItem itemLabel="Choisir..." itemValue="" />
				<f:selectItems value="#{droitsFonctionBean.modules}" var="module"
					itemLabel="#{module.code}" itemValue="#{module.code}" />
				<p:ajax event="valueChange" process="@this" update="tbDroits"
					listener="#{droitsFonctionBean.onModelChange}"></p:ajax>
			</h:selectOneMenu>
		</h:panelGrid>
		<p:dataTable value="#{droitsFonctionBean.droits}" var="droit"
			selection="#{droitsFonctionBean.selectedFonctionnalites}"
			id="tbDroits" rowKey="#{droit.code}">
			<p:column selectionMode="multiple" />
			<p:column headerText="Fonctionnalite">
				<h:outputText value="#{droit.code}" />
			</p:column>
			<f:facet name="footer">
				<p:commandButton value="Valider" image="ui-icon ui-icon-search"
					actionListener="#{droitsFonctionBean.validate}" update="tbDroits" process="tbDroits"/>
			</f:facet>
		</p:dataTable>
	</h:form>
</p:outputPanel>

Code: Select all

package sn.pss.azur.common.referentiel.droits.controllers;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import javax.faces.model.ListDataModel;

import org.primefaces.context.RequestContext;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SelectableDataModel;
import org.primefaces.model.SortOrder;
import org.primefaces.model.TreeNode;

import sn.pss.azur.common.authentification.entites.Affectation;
import sn.pss.azur.common.referentiel.droits.RightsServiceInterface;
import sn.pss.azur.common.referentiel.modules.entities.Fonctionnalite;
import sn.pss.azur.common.referentiel.modules.entities.Module;
import sn.pss.azur.common.referentiel.modules.services.ModulesServiceInterface;
import sn.pss.azur.common.uo.entites.UniteOrganisationnelle;
import sn.pss.azur.common.utilisateurs.entites.Fonction;
import sn.pss.azur.common.utilisateurs.services.UtilisateursServiceInterface;

@ManagedBean(name = "droitsFonctionBean")
@ViewScoped
public class DroitsFonctionBean implements Serializable {
	DroitsSelectableDataModel droits;
	List<Module> modules;
	@ManagedProperty(value="#{listeFonctionsBean.selectedTreeNode.data}")
	Fonction fonction;
	String selectedModule;
	Fonctionnalite[] selectedFonctionnalites;
	@EJB
	ModulesServiceInterface service;
	@EJB
	RightsServiceInterface rightsService;
	
	public Fonction getFonction() {
		return fonction;
	}
	public void setFonction(Fonction fonction) {
		this.fonction = fonction;
	}
	public List<Module> getModules() {
		return modules;
	}
	public void setModules(List<Module> modules) {
		this.modules = modules;
	}
	
	public String getSelectedModule() {
		return selectedModule;
	}
	public void setSelectedModule(String selectedModule) {
		this.selectedModule = selectedModule;
	}	
	
	public DroitsSelectableDataModel getDroits() {
		return droits;
	}
	public void setDroits(DroitsSelectableDataModel droits) {
		this.droits = droits;
	}
	
	public Fonctionnalite[] getSelectedFonctionnalites() {
		System.out.println("getSelectedFonctionnalites "+selectedFonctionnalites.length);
		return selectedFonctionnalites;
	}
	public void setSelectedFonctionnalites(
			Fonctionnalite[] selectedFonctionnalites) {
		System.out.println("setSelectedFonctionnalites "+selectedFonctionnalites.length);
		this.selectedFonctionnalites = selectedFonctionnalites;
	}
	@PostConstruct
	public void init()
	{
		System.out.println("Init");
		modules = service.findModules();
		onModelChange();
	}
	
	public void onModelChange()
	{
		List<Fonctionnalite> _droits = rightsService.findFonctionnalitessInModule(selectedModule);
		droits = new DroitsSelectableDataModel(_droits);
		List<Fonctionnalite> liste = rightsService.findDroitsFonction(fonction.getCode());
		selectedFonctionnalites = new Fonctionnalite[liste.size()];
		liste.toArray(selectedFonctionnalites);
	}
	
	public void validate(ActionEvent event)
	{
		System.out.println("validate "+selectedFonctionnalites.length);
		rightsService.setDroitsFonction(fonction.getCode(), selectedModule, Arrays.asList(selectedFonctionnalites));
		//onModelChange();
	}
	
	public class DroitsSelectableDataModel extends ListDataModel<Fonctionnalite> implements SelectableDataModel<Fonctionnalite>
	{		
		public DroitsSelectableDataModel(List<Fonctionnalite> list) {
			super(list);
			// TODO Auto-generated constructor stub
		}

		@Override
		public Fonctionnalite getRowData(String key) {
			
			return rightsService.findFonctionnaliteByCode(key);
		}

		@Override
		public Object getRowKey(Fonctionnalite f) {
			// TODO Auto-generated method stub
			return f.getCode();
		}	
		
		
	}
}
In the PostConstruct method of my backing bean, i calculate the pre selected items and it is rendered properly.
But when i update my selection and post the form, it doesn't consider the new selection and always consider the one i calculated in the postconstruct method.
It seems like the "apply Request Values" is not processed.
Why that ?
Thanks in advance
Primefaces 3.3 Jboss 7.1

Luuzz
Posts: 32
Joined: 28 Mar 2011, 15:21

11 Nov 2011, 12:45

Someone please answer me i am stuck.
The preselection is working fine but when i submit a new selection it is ignored.
Primefaces 3.3 Jboss 7.1

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

11 Nov 2011, 12:49

Try M4.

Luuzz
Posts: 32
Joined: 28 Mar 2011, 15:21

11 Nov 2011, 12:58

Sorry, i am using M4 i forgot to update my footer in the forum.
Primefaces 3.3 Jboss 7.1

Luuzz
Posts: 32
Joined: 28 Mar 2011, 15:21

11 Nov 2011, 20:54

Why my selected items aren't submitted ?
Help please
Primefaces 3.3 Jboss 7.1

Luuzz
Posts: 32
Joined: 28 Mar 2011, 15:21

13 Nov 2011, 20:42

Hi there,
I just tried the datatable multiple selection showcase in my environmemnt and it isn't working either.
I remember i had a datatable with single selection. I used the selection attribute to retrieve a selection after a select event but it didnt work i had to use selectEvent.getSource to retrieve the selected item.
It seems to be a bug in my environment may be mojarra ?
Help me please
Primefaces 3.3 Jboss 7.1

Luuzz
Posts: 32
Joined: 28 Mar 2011, 15:21

15 Nov 2011, 11:10

My guess is that there must be a bug in Glassfish because the primefaces example doesnt even work.
Help please.
Primefaces 3.3 Jboss 7.1

Luuzz
Posts: 32
Joined: 28 Mar 2011, 15:21

17 Nov 2011, 22:13

Hello,
I've been struggling with the issue for days and thanks to the log component i saw the issue.
Indeed, my row key values contain the "_" character. When the datatable is posted, it doesnt post the entire value. Example, if the rowkey value is CREER_UTILISATEUR only CREER is posted what breaks the flow. If i update the value in the database to CREERUTILISATEUR everything works perfectly.
so it seems that there is an issue on the way rowkeys are posted.
Regards
Primefaces 3.3 Jboss 7.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests