【问题标题】:JSF DataModel getRowData always return the first row (which has index zero)JSF DataModel getRowData 始终返回第一行(索引为零)
【发布时间】:2012-02-05 14:59:35
【问题描述】:

我在rich:dataTable 列中有rich:select 组件。 我添加了 a4j:ajax 标记来处理 onblur 事件,以处理与此选定行相关的一些值。

但这仅适用于数据表的第一行,第二行与第一行相同。

当我跟踪我的代码时,我发现 datamodel.getRowData() 方法总是返回第一行。 我还发现 datamodel.getRowCount() 返回正确的行数。 但是 datamodel.getRowIndex() 总是返回零。

任何帮助???

这是我的 ManagedBean 代码(仅需要的代码)**

@ManagedBean(name = "saleBacking")
@SessionScoped
public class SaleBacking  implements Serializable{


private DataModel<SaleLine> model ;
   public DataModel<SaleLine> getModel() {
       if (model == null) {
            model = new ListDataModel<SaleLine>(salesLines);
        }
        return model;
    }

  public void updateRowData(AjaxBehaviorEvent event)
    {
        currentSaleLine = (SaleLine)getModel().getRowData();
        System.out.println("Row count= "+getModel().getRowCount() + " , Row index= " + getModel().getRowIndex()) ;// this always  return the correct rowCount but the index equal Zero (the first row of the datamodel)
        if(currentSaleLine.getItemId() != null && currentSaleLine != null)
         {
             currentSaleLine.setItemPrice(currentSaleLine.getItemId().getItemDefEndUserPrice());
             currentSaleLine.setPl(currentSaleLine.getItemId().getItemDefEndUserPrice());
             currentSaleLine.setQuantity(1d);
             currentSaleLine.setNetValue(currentSaleLine.getItemPrice() *  currentSaleLine.getQuantity()) ;
             calculateTotalSale();
         }
    }
}

Sale.xhtml

<rich:dataTable value="#{saleBacking.salesLines}" var="line" rows="50" id="datatable">                                  
    <rich:column>
                                               <f:facet name="header"><h:outputLabel value="#{msgs.item}" style="font-size:15px;"/></f:facet>
        <rich:select enableManualInput="true" 
                    value="#{line.itemId}"
                    clientFilterFunction="containsFilter"
                    converter="#{itemConverter}"
                    defaultLabel="please write the item name" onlistshow="alert('jhjhj');"
                    >
            <f:selectItems value="#{saleBacking.items}" var="item" itemValue="#{item}" itemLabel="#{item.code} #{item.name}"/>
            <a4j:ajax event="blur" execute="@this" listener="#{saleBacking.updateRowData}" render="datatable master2"  oncomplete="document.getElementById('myform:datatable:#{line.viewNo-1}:price').focus();"/>
        </rich:select>
    </rich:column>
</rich:dataTable>

【问题讨论】:

  • 我之前没有使用过这个结构,所以我不确定。但是尝试SaleLine currentSaleLine = context.getApplication().evaluateExpressionGet(context, "#{line}", SaleLine.class); 来检查它是否返回当前行。
  • 成功了!!!!非常感谢。

标签: ajax jsf datatable richfaces datamodel


【解决方案1】:

我以前没有使用过这个结构,所以我不确定。但是试试 SaleLine

currentSaleLine = context.getApplication().evaluateExpressionGet(context, 
"#{line}", SaleLine.class); 

检查是否返回当前行。

@BalusC 昨天

【讨论】:

    猜你喜欢
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    • 2021-09-24
    • 2017-09-05
    • 1970-01-01
    相关资源
    最近更新 更多