Page 1 of 1

Does datatable supports composite key?

Posted: 27 Oct 2011, 09:29
by Bwang
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

Re: Does datatable supports composite key?

Posted: 27 Oct 2011, 11:10
by Oleg
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.