简体   繁体   中英

How I can consult fields when selecting a row in p:dataTable?

I have a form and data table, my problem is when I select a row in my table, all fields are consulted expect a field because it depends with another field. I will appreciate if you help me to consult this field.

my form

<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.onPortfolioChange:

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

CashMvtView.java:

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;
}

my data table:

<p:dataTable var="cashMvt"  value="#{cashMvtView.listeFilteredCashMvt}" 
                                 selectionMode="single" filteredValue="#{cashMvtView.listeFilteredCashMvt}"
                                 selection="#{cashMvtView.selectedCashMvt}" 
                                 rowKey="#{cashMvt.id}"  tableStyle="width:auto"
                                 paginator="true" widgetVar="tabRecherche" id="tabRecherche"
                                 paginatorPosition="bottom"  rows="14"
                                 paginatorTemplate="{Exporters} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} 
                                 {RowsPerPageDropdown} {JumpToPageDropdown} {Controle}" 
                                 >
                        <p:ajax event="rowSelect"  listener="#{cashMvtView.onRowSelect}"  update="form form2" id="ajaxRS" />

                            <p:column style="white-space: nowrap" headerText="#{msg['Portfolio']}" sortBy="#{cashMvt.portfolio}" ><h:outputText value="#{cashMvt.portfolio}" /></p:column>
                            <p:column style="white-space: nowrap" headerText="#{msg['Cashaccount']}" sortBy="#{cashMvt.cashAccount}" ><h:outputText value="#{cashMvt.cashAccount}"/> </p:column>

cashMvtView.listeFilteredCashMvt is a list that return what I want to display in my form

this is a screen for my web app enter image description here

As you see, all fields are consulted expect "comptes especes" (cashaccount in my code) Note that "portefeuille" in this scrren is portfolio in my code.

I fixed the problem : I added this code in cashMvtView.onRowSelect, in my data table.

 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>();
    }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM