1

我有一个datatable我有两列的地方。

第 1 列:输出文本,由 bean 数据填充。第2栏:输入文本框

我已经将 column1 作为commandLink我附加了一个actionListener. 目的是当我单击 UI 上的一行时,应在 bean 中捕获选定的行数据。

这是代码:

<h:dataTable id="headerOverrides" styleClass="header" headerClass="headerTable"
  cellpadding="0" cellspacing="0" width="100%">
        <h:column>
            <f:facet name="header">
                <h:commandLink id="payment_Fund_Name" styleClass="header"
                    actionListener="#{pc_Billing.sortColumn}"
                    onmouseover="resetTargetFrame();">
                    <h:outputText style="width:150px" 
                      value="#{bundle.billing_Fund_Name}">                                                    
                    </h:outputText>
                </h:commandLink>
           </f:facet>
        </h:column>
        <h:column>
           <f:facet name="header">
                <h:commandLink id="allocation_Percent" styleClass="header"
                    actionListener="#{pc_Billing.sortColumn}"
                    onmouseover="resetTargetFrame();">
                    <h:outputText style="width:65px" value="#{bundle.billing_Allocation_Percent}">
                    </h:outputText>
                </h:commandLink>                            
           </f:facet>
        </h:column>
</h:dataTable>
</td>
</tr>

<tr>
<td colspan="2">
    <div class="divTable" style="height: 176px" id="overrideTableData">
    <h:dataTable id="overrideTable" value="#{pc_Billing.overrideFundsList}"
                var="currentRow" columnClasses="column" headerClass="header"
                    rowClasses="#{pc_Billing.paymentRowStyles}" binding="#{pc_Billing.allocationOverrideTable}"
                    styleClass="complexTable" cellpadding="2" cellspacing="0"
                    width="100%" border="1" >


          <h:column id="override_Fund">
            <h:commandLink onmouseover="resetTargetFrame();" id="override_FundLink"
                            actionListener="#{pc_Billing.selectFromRow}" immediate="true"
                            styleClass="textTable" style="width:100%">
                     <h:outputText styleClass="textTable"
                               value="#{currentRow.fundName}" style="width:140px">
                      </h:outputText>
            </h:commandLink>
           </h:column>
           <h:column id="override_Allocation">
              <h:inputText id="allocation_Percent" styleClass="textInput" value="#{currentRow.allocation}"
                                disabled="#{!(pc_Billing.loanPayment || pc_Billing.universalLife)}" onblur="totalFrom();"
                                style="width:70px">
                  <f:convertNumber type="percent" />
              </h:inputText>
        </h:column>
    </h:dataTable>

selectFromRow来自bean的方法

public void selectFromRow(ActionEvent e) {

        if (e.getComponent().getId().equalsIgnoreCase("override_FundLink")) {
            paymentOverrideSelectedRow = (PaymentOverride) allocationOverrideTable.getRowData();
            allocationOverrideTableData.setFundName(paymentOverrideSelectedRow.getFundName());
            allocationOverrideTableData.setAllocation(paymentOverrideSelectedRow.getAllocation());

        }else if(e.getComponent().getId().equalsIgnoreCase("fundLink"))
        {
            preimumOverrideSelectedRow = (PremiumOverride) premiumOverrideTable.getRowData();
            premiumOverrideTableData.setFundName(preimumOverrideSelectedRow.getFundName());
            premiumOverrideTableData.setAmount(preimumOverrideSelectedRow.getAmount());
            premiumOverrideTableData.setEndDate(preimumOverrideSelectedRow.getEndDate());
            premiumOverrideTableData.setInterestRate(preimumOverrideSelectedRow.interestRate);
        }

    FacesContext.getCurrentInstance().renderResponse();
    }

现在发生的事情是我没有从表格上的输入文本框中获取数据。它是空的。我错过了什么?此外,当selectFromRow函数执行表格渲染并且我在文本框中输入的数据被清除时。

4

1 回答 1

1

您是否尝试从此处删除 immediate="true" ?

<h:commandLink onmouseover="resetTargetFrame();" id="override_FundLink"
               actionListener="#{pc_Billing.selectFromRow}" immediate="true"
               styleClass="textTable" style="width:100%">

我猜它会在处理 inputText 的值之前运行你的 selectFromRow 方法。

于 2013-01-02T19:16:10.300 回答