【发布时间】: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