Does datatable supports composite key?

UI Components for JSF
Post Reply
Bwang
Posts: 7
Joined: 23 Aug 2011, 08:27

27 Oct 2011, 09:29

Hi All,

I use JPA to manipulate the database. One table "User" adopts the primary key ("first name", "second name").
So I tag @Embeddable with the class "Name".

Code: Select all

@Embeddable
public class Name implements Serializable {
    @Column(name="firstname", nullable=false)
    private String firstname= "";

    @Column(name="secondname", nullable=false)
    private String firstname= "";
//getter setter hash equals

Here is the entity Class: "User":

Code: Select all

@Entity
@Table(name="User")
public class Userimplements Serializable {

    @EmbeddedId
    private Name name = new Name();
//Other properties
//getter setter hash equals
I want to this page to render my content like this :http://www.primefaces.org/showcase-labs ... eckbox.jsf

But I don't how to implements the datamodel:

Code: Select all

 public Car getRowData(String rowKey) {  
       //I don't know how to write here???
        return null;  
    } 
Because in my case, the rowKey is combination of both "firstname" and "secondname".

Can someone met this before?

Thank you,

Colin
Mojarra 2.1.2, PrimeFaces 3.0.M2, Tomcat 7.0.16

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

27 Oct 2011, 11:10

I would write so (if getFirstname() and getLastname() are Strings)

Code: Select all

public Car getRowData(String rowKey) {  
    List<Name> names = (List<Name>) getWrappedData();  
          
    for(Name name : names) {  
         if(name.getFirstname + name.getLastname).equals(rowKey))  
              return name;  
    }  
        
    return null;  
}

public Object getRowKey(Name name) {  
    return name.getFirstname + name.getLastname;  
}  
You should implement getRowData and getRowKey where you combine multiply values to one rowKey.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 27 guests