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>
我之前沒有使用過這個構造,所以我不確定。但嘗試'SaleLine currentSaleLine = context.getApplication()。evaluateExpressionGet(context,「#{line}」,SaleLine.class);'檢查它是否返回當前行。 – BalusC 2012-01-09 11:59:08
它的工作!非常感謝。 – 2012-01-11 11:52:02