Multiple Select Datatable

UI Components for JSF
Post Reply
dark_prime
Posts: 46
Joined: 02 Dec 2010, 14:30

02 Dec 2010, 14:44

Hi,

i try to get the multiple selected Datable to work, but until now i have failed.

First of all I am not sure if there isn't a bug in the showcase:

Code: Select all

   public void setSelectedCar(Car[] selectedCars) {  
        this.selectedCar = selectedCars;  
    }  
cause there is no attribute called selectedCar in the bean.

I try to manage to send 2 variables to a method of a controller, one of them works fine, the second is the array/list (tried both) of the selected items from the datatable and it is always null.

Code: Select all

  <p:dataTable var="participant" value="#{schulungView.getSchulung().getParticipants()}"  
                  selection="#{schulungView.participatedParticipants}" selectionMode="multiple">  
 						
 						<p:column>
 							 
				                 <h:outputText value="#{participant.firstname}" />  
            				 
 						</p:column>
 						<p:column>
 							 
				                 <h:outputText value="#{participant.lastname}" />  
            				 
 						</p:column>
 						  <f:facet name="footer"> 
 						 <p:commandButton value="PDF" action="#{pDF.generateCertificates(participatedParticipants, schulung)}"/>
                         </f:facet>
	    			</p:dataTable>>
Hope someone can help me and thx

fiktion
Posts: 100
Joined: 25 Aug 2010, 17:47

02 Dec 2010, 15:02

To the first question there is a selectedCars attribute in the backing bean and if you look at the primefaces showcase example it is on line 43 of the TableBean.java code.

Code: Select all

private Car[] selectedCars; 
To your second question. The reason you are having an issue is you are trying to pass values via a parameter

Code: Select all

action="#{pDF.generateCertificates(participatedParticipants, schulung)}"/>
You are not allowed to pass participatedParticipants, and schulung this way. You should set params on the command button. Also you might want to consider using an actionListener instead of action. See code below for the commandButtonand then your backing bean.

Code: Select all

<p:commandButton value="PDF" actionListener="#{pDF.generateCertificates}" >
         <f:param name="participants" value="#{yourbean.participatns}" />
         <f:param name="shulung" value="#{yourbean.shulung"} />
</p:commandButton
YourBackingBean.java
In here you will want to get these params via the facesContext so it would look like this

Code: Select all

   FacesContext context = FacesContext.getCurrentInstance();
    String participants = context.getExternalContext().getRequestParameterMap().get("participants");

dark_prime
Posts: 46
Joined: 02 Dec 2010, 14:30

02 Dec 2010, 15:44

Hi first of all thank you for your answer,

to the showcase :

there is no selectedCar (WITHOUT S) in the whole TableBean.

Code: Select all

#   public void setSelectedCar //WITHOUT S
(Car[] selectedCars) {   
      this.selectedCar //WITHOUT S
 = selectedCars;  
 }
  
so where does it come from?


to my problem.

I want to hand over 2 more complex parameters:

participatedParticipants is a list of the type List<Participant>, the whole list is displayed in my dataTable - the selection is, what i want to hand over to the function.
schulung is an Object Schulung schulung.

As far as I know I can only pass simple key/value pairs via ParamterMap.

fiktion
Posts: 100
Joined: 25 Aug 2010, 17:47

02 Dec 2010, 15:53

Oh okay I did not see that, then it might be an error in the showcase.

To the second response. I am new to this but I have encountered your situation. What I would do is pass the Participants ID and a shulong ID to the controller and then inside the controller call your DAO passing in the ID's to retrieve the objects. That might be workaround but it will get your the objects you need inside the controller.

dark_prime
Posts: 46
Joined: 02 Dec 2010, 14:30

02 Dec 2010, 16:01

I'll probably do something like this.

It is kind a disappointing, that it doesn't work out of the box.

Having a List of objects -> making a selection -> handing it over to a function is daily routine...

Well thx for your answer.

fiktion
Posts: 100
Joined: 25 Aug 2010, 17:47

02 Dec 2010, 16:08

Yea I agree with this, but so far I have not found any solution on passing Object's from a view to a controller. Sorry I could not have been more help.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 61 guests