Ajax JSF DataModel getRowData始终返回第一行(索引为零)
我在rich:dataTable列中有rich:select组件。 我添加了a4j:ajax标记来处理onblur事件,以处理与此选定行相关的一些值 但这只适用于datatable的第一行,在第二行中它的操作与第一行相同 跟踪代码时,我发现datamodel.getRowData()方法始终返回第一行。 我还发现datamodel.getRowCount()返回正确的行数。 但是datamodel.getRowIndex()总是返回零 有什么帮助吗 这是我的ManagedBean代码(仅限所需代码)**Ajax JSF DataModel getRowData始终返回第一行(索引为零),ajax,jsf,datatable,richfaces,datamodel,Ajax,Jsf,Datatable,Richfaces,Datamodel,我在rich:dataTable列中有rich:select组件。 我添加了a4j:ajax标记来处理onblur事件,以处理与此选定行相关的一些值 但这只适用于datatable的第一行,在第二行中它的操作与第一行相同 跟踪代码时,我发现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();
}
}
}
@ManagedBean(name=“saleBacking”)
@会议范围
公共类实现可序列化{
私有数据模型;
公共数据模型getModel(){
if(model==null){
模型=新的ListDataModel(销售线);
}
收益模型;
}
public void updateRowData(AjaxBehaviorEvent事件)
{
currentSaleLine=(SaleLine)getModel().getRowData();
System.out.println(“行计数=“+getModel().getRowCount()+”,行索引=“+getModel().getRowIndex());//这始终返回正确的行计数,但索引等于零(数据模型的第一行)
if(currentSaleLine.getItemId()!=null&¤tSaleLine!=null)
{
currentSaleLine.setItemPrice(currentSaleLine.getItemId().GetItemDefensionUserPrice());
currentSaleLine.setPl(currentSaleLine.getItemId().getItemDefensionUserPrice());
currentSaleLine.setQuantity(1d);
currentSaleLine.setNetValue(currentSaleLine.getItemPrice()*currentSaleLine.getQuantity());
计算销售额();
}
}
}
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昨天我以前没有使用过这个结构,所以我不确定。但是试试SaleLine
currentSaleLine = context.getApplication().evaluateExpressionGet(context,
"#{line}", SaleLine.class);
检查是否返回当前行
@BalusC昨天我以前没有使用过这个结构,所以我不确定。但是请尝试
SaleLine currentSaleLine=context.getApplication().evaluateExpressionGet(context,“{line}”,SaleLine.class)
检查它是否返回当前行。它成功了!!!!非常感谢,伙计。我以前没有用过这个结构,所以我不确定。但是请尝试SaleLine currentSaleLine=context.getApplication().evaluateExpressionGet(context,“{line}”,SaleLine.class)
检查它是否返回当前行。它成功了!!!!谢谢你,伙计。