Zolf
asked on
Behaviour of Java List
Hello there,
I have this requirement to show the amount with thousand separator. I have this POJO class with these two methods which I call according to my requirements
r() in my another class which looks like this and I do a println to see if the amount is being shown properly(which it does).
here is the actual method getSupplierOrderDetailsFro msupplierO rder(suppl ierOrder); which gets the data from the db.
I have this requirement to show the amount with thousand separator. I have this POJO class with these two methods which I call according to my requirements
public Integer getTotalAmount() {
return totalAmount;
}
public String getTotalAmountWithSeparator() {
return String.format("%,d", totalAmount);
}
public void setTotalAmount(Integer totalAmount) {
this.totalAmount = totalAmount;
}
now when I use this method getTotalAmountWithSeparatoList<SupplierOrderDetails> list = SupplierOrderDetailBussinessLogic.getInstance().getSupplierOrderDetailsFromsupplierOrder(supplierOrder);
DataProviderBuilder dpb = new DataProviderBuilder();
// add heading data
dpb.add("so", supplierOrder.getSupplierOrderNo());
dpb.add("sn", supplierOrder.getSupplier().getPerName());
dpb.add("sec", supplierOrder.getSection().getAlternateName());
dpb.add("od", supplierOrder.getSupplierOrderCreated().toString());
// add table data
dpb.addJavaObject(list, "data");
here is the actual method getSupplierOrderDetailsFro
@SuppressWarnings("unchecked")
public List<SupplierOrderDetails> getSupplierOrderDetailsFromsupplierOrder(SupplierOrder supplierOrderDetails){
Session hibernateSession = HibernateUtills.getInstance().getHibernateSession();
Criteria criteria = hibernateSession.createCriteria(SupplierOrderDetails.class);
criteria.add(Restrictions.eq("supplierOrderID", supplierOrderDetails));
List<SupplierOrderDetails> models = criteria.list();
System.out.println(" models.size() " + models.size());
for (int i = 0; i < models.size(); i++)
{
if (models.get(i).getId() != null)
{
models.get(i).getProductID().getProductCode();
models.get(i).getProductID().getBrandName();
models.get(i).getPurchasePrice();
models.get(i).getOrderQty();
models.get(i).getTotalAmountWithSeparator();
System.out.println(models.get(i).getProductID().getBrandName() + " TotalAmount " + models.get(i).getTotalAmountWithSeparator());
}
// System.out.println(models.get(i).getPurchasePrice());
}
return models;
}
but when I do a println of the list data here,it does not show the separator in the amount why?????what am I doing wrongdp = getSupplierOrderData(Long.parseLong(supplierOrderId));
System.out.println("DATA "+dp.getString("data"));
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
your comments helped me to find the problem. thanks a lot
ASKER
thanks for your comments
this is another method which looks like this
private DataProvider getSupplierOrderData(Long supplierorderid)
{
SupplierOrder supplierOrder = SupplierOrderBussinessLogi
List<SupplierOrderDetails>
System.out.println(" list.size() " + list.size());
for (SupplierOrderDetails supplierOrderDetails : list)
{
Integer totalAmount = supplierOrderDetails.getTo
System.out.println("totalA
Integer orderQty = supplierOrderDetails.getOr
Integer purchasePrice = supplierOrderDetails.getPu
String brandName = supplierOrderDetails.getPr
Integer productCode = supplierOrderDetails.getPr
String supplierEngName = supplierOrderDetails.getSu
String section = supplierOrderDetails.getSu
String supplierOrderNo = supplierOrderDetails.getSu
Date supplierOrderCreated = supplierOrderDetails.getSu
System.out.println(" supplierOrderDetails " + supplierOrderDetails.toStr
}
DataProviderBuilder dpb = new DataProviderBuilder();
// add heading data
dpb.add("so", supplierOrder.getSupplierO
dpb.add("sn", supplierOrder.getSupplier(
dpb.add("sec", supplierOrder.getSection()
dpb.add("od", supplierOrder.getSupplierO
// add table data
dpb.addJavaObject(list, "data");
return dpb.getDataProvider();
}