在p:dataTable中选择行时,如何查询字段?

时间:2018-04-08 18:02:54

标签: jsf primefaces datatable

我有一个表格和数据表,我的问题是,当我在表格中选择一行时,所有字段都需要一个字段,因为它取决于另一个字段。如果您有帮助,我将不胜感激我可以咨询这个领域。

我的表格

SELECT 
UNIQUE_ID, 
sum(CASE 
WHEN TRAN_TYPE NOT IN('D') THEN 0 
WHEN TRANSACTION > 0 THEN TRAN_AMNT 
WHEN (TRAN_DATE > (min(CASE WHEN TRAN_TYPE = 'N' THEN TRAN_DATE ELSE null END) + 30)) THEN 0 
ELSE TRAN_AMNT END) as GROSS_LOSS
FROM 
TABLE_NAME
WHERE 
TRAN_DATE between '01-jan-2003' and '28-feb-2018' AND 
TRAN_TYPE NOT IN('X') AND 
GROUP BY 
UNIQUE_ID, 
HAVING 
sum(TRAN_AMNT) >= 5000000

cashMvtView.onPortfolioChange:

<p:outputLabel for="Portfolio" value="#{msg['Portfolio']}" />
                    <p:selectOneMenu id="Portfolio" value="#{cashMvtView.beanCashMvt.portfolio}" style="width:120px">
                        <p:ajax listener="#{cashMvtView.onPortfolioChange}" update="Cashaccount" />
                        <f:selectItem itemLabel="Selectionner un portefeuille" itemValue="" noSelectionOption="true" />
                        <f:selectItems value="#{cashMvtView.portfolios}" />
                    </p:selectOneMenu>

                    <p:outputLabel for="Cashaccount" value="#{msg['Cashaccount']}" />
                    <p:selectOneMenu id="Cashaccount" value="#{cashMvtView.beanCashMvt.cashAccount}" style="width:120px">
                        <f:selectItem itemLabel="Selectionner un compte" itemValue="" noSelectionOption="true" />
                        <f:selectItems value="#{cashMvtView.cashAccounts}" />
                    </p:selectOneMenu>

CashMvtView.java:

public void onPortfolioChange() {        
    if(beanCashMvt.getPortfolio() !=null && !beanCashMvt.getPortfolio().equals("")){            
        cashAccounts = data.get(beanCashMvt.getPortfolio());            
    }
    else
        cashAccounts = new HashMap<String, String>();
}

我的数据表:

private Map<String,Map<String,String>> data = new HashMap<String, Map<String,String>>();
private String portfolio; 
private String cashAccount;  
private Map<String,String> portfolios;
private Map<String,String> cashAccounts;

@PostConstruct
public void init() {
    portfolios  = new HashMap<String, String>();
    portfolios.put("Portefeuille1", "Portefeuille1");
    portfolios.put("Portefeuille2", "Portefeuille2");
    portfolios.put("Portefeuille3", "Portefeuille3");

    Map<String,String> map = new HashMap<String, String>();
    map.put("Portefeuille1_1", "Portefeuille1_1");
    map.put("Portefeuille1_2", "Portefeuille1_2");
    map.put("Portefeuille1_3", "Portefeuille1_3");
    data.put("Portefeuille1", map);

    map = new HashMap<String, String>();
    map.put("Portefeuille2_1", "Portefeuille2_1");
    map.put("Portefeuille2_2", "Portefeuille2_2");
    map.put("Portefeuille2_3", "Portefeuille2_3");
    data.put("Portefeuille2", map);

    map = new HashMap<String, String>();
    map.put("Portefeuille3_1", "Portefeuille3_1");
    map.put("Portefeuille3_2", "Portefeuille3_2");
    map.put("Portefeuille3_3", "Portefeuille3_3");
    data.put("Portefeuille3", map);
}

public Map<String, Map<String, String>> getData() {
    return data;
}

public String getPortfolio() {
    return portfolio;
}

public void setPortfolio(String portfolio) {
    this.portfolio = portfolio;
}

public String getCashAccount() {
    return cashAccount;
}

public void setCashAccount(String cashAccount) {
    this.cashAccount = cashAccount;
}

public Map<String, String> getPortfolios() {
    return portfolios;
}

public Map<String, String> getCashAccounts() {
    return cashAccounts;
}

cashMvtView.listeFilteredCashMvt是一个返回我希望在表单中显示的内容的列表

这是我的网络应用的屏幕 enter image description here

如您所见,所有字段都参考了“comptes especes”(在我的代码中为cashaccount) 请注意,此scrren中的“portefeuille”是我的代码中的投资组合。

1 个答案:

答案 0 :(得分:0)

我修复了问题:我在我的数据表中的cashMvtView.onRowSelect中添加了此代码。

 public void onRowSelect(SelectEvent event) {
    beanCashMvt = mapper.map(selectedCashMvt, HcashMvtVO.class)  ;         
    if (beanCashMvt.getPortfolio() != null && !beanCashMvt.getPortfolio().equals("")) {
        cashAccounts = data.get(beanCashMvt.getPortfolio());
    } else {
        cashAccounts = new HashMap<String, String>();
    }
}