2014-03-31 27 views
0

這顯示它是搜索標準的數據模型我有兩個數據模型,我想在同一個數據表

private DataModel<Criteres> dataModel = new ListDataModel<Criteres>(); 
private DataModel<Appreciation>dataModelA = new ListDataModel<Appreciation>(); 

public DataModel<Criteres> getDataModel() { 
    dataModel.setWrappedData(criteresservice.findid()); 
    return dataModel; 
} 
    //setter// 

這是數據模型升值

public DataModel<Appreciation> getDataModelA() { 
    dataModelA.setWrappedData(appreciationservice.listAllAppreciation()); 
    return dataModelA; 
} 
    //setter// 

是那裏來顯示它的解決方案我的xhtml頁面中有相同的數據表?

回答

0

一般來說,沒有。數據表用於顯示來自同一類型對象的數據。如果CriteresAppreciation與彼此無關,則無法做到這一點。

但是,如果CriteresAppreciation之間存在關係,則可以創建對象的自定義類(類型)並在那裏聲明該關係。例如,如果每個Appreciation對象就像一個+1 like一個Criteres對象,您可以創建以下類:

public class CustomCriteres { 
    private Criteres criteres; 
    private List<Appreciation> appreciations; // 2 appreciations ~ 2 likes, n appreciations ~ n likes 

    // Getters and Setters 
} 

然後在後臺bean爲您的數據表,你可以有CustomCriteresDataModel對象。它會是這樣的:

@ManagedBean 
@ViewScoped 
public class MrBean { 
    private DataModel<CustomCriteres> customModel; 

    public DataModel<CustomCriteres> getCustomModel() { 
     /* This is where you would get both `Criteres` and ALL of the related 
      `Appreciation` objects at the same time and put them in 1 single 
      instance of `CustomCriteres` object */ 
    } 
} 

在這一點上,你已經可以使用customModel爲您的數據表。

相關問題