Reputation: 810
I have rich:select component inside a rich:dataTable column. I added a4j:ajax tag to handle onblur event , to process some values related to this selected row.
But this worked only correct for the first row of the datatable , in the second row it do the same as in the first row.
When I traced my code I found that the datamodel.getRowData() method return the first row always. Also I found that the datamodel.getRowCount() return the correct number of rows. BUT datamodel.getRowIndex() return ZERO always.
ANY help ???
Here is my ManagedBean code (the needed code only) **
@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>
Upvotes: 1
Views: 3129
Reputation: 810
I haven't used this construct before, so I'm not sure. But try SaleLine
currentSaleLine = context.getApplication().evaluateExpressionGet(context,
"#{line}", SaleLine.class);
To check if it returns the current row.
@BalusC yesterday
Upvotes: 1