2012-01-08 51 views
1

我有丰富的内容:在rich:dataTable列中选择组件。 我添加了a4j:ajax标签来处理onblur事件,以处理与此选定行相关的一些值。JSF DataModel getRowData总是返回第一行(其索引为零)

但是,这只适用于数据表的第一行,在第二行,它与第一行相同。

当我追查我的代码时,发现datamodel.getRowData()方法总是返回第一行。 另外我发现datamodel.getRowCount()返回正确的行数。 但是datamodel.getRowIndex()总是返回ZERO。

任何帮助???

这是我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> 
+1

我之前没有使用过这个构造,所以我不确定。但尝试'SaleLine currentSaleLine = context.getApplication()。evaluateExpressionGet(context,“#{line}”,SaleLine.class);'检查它是否返回当前行。 – BalusC 2012-01-09 11:59:08

+0

它的工作!非常感谢。 – 2012-01-11 11:52:02

回答

0

,所以我不确定。但尝试SaleLine currentSaleLine = context.getApplication()。evaluateExpressionGet(context,“#{line}”,SaleLine.class);检查它是否返回当前行。 - @BalusC昨天