JSF DataModel getRowData всегда возвращает первую строку (с нулевым индексом)
У меня есть rich: выберите компонент внутри столбца rich:dataTable. Я добавил тег 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>
1 ответ
Я не использовал эту конструкцию раньше, поэтому я не уверен. Но попробуйте SaleLine currentSaleLine = context.getApplication().valuExpressionGet(context, "#{line}", SaleLine.class); проверить, возвращает ли он текущую строку. - @BalusC вчера