PDA

View Full Version : GroupingStore Grid loading problems



xworker
20 Jul 2010, 4:29 AM
Hi

I want to populate my Grid with a GroupingStore with a List of entitys without calling a loader, but the contents of the grid is not shown. The Grid shows up, and the summarys are correct but all rows are empty. this is my code:

creating the grid:




List<Holding> holdings =

customerDetail.getHoldings();


GroupingStore<Holding> store = new GroupingStore<Holding>();
store.groupBy("holdingType");
store.add(holdings);


List<ColumnConfig> columns = new ArrayList<ColumnConfig>();



//id
SummaryColumnConfig<Double> ids =


new SummaryColumnConfig<Double>(
"fundId", "FundId", 10);
.....
....



The holding object looks like this:




@SuppressWarnings


("serial")

public


class Holding extends BaseModel implements Serializable{


privateintfundId;
private String holdingType;
private String fundName;
private Double shares;
private Double price;
private String priceDates;
private String currency;
private Double value;
private Double buyAmount;
private Double lockedShares;




public Holding() {
super();
}


?
?
public Holding(int fundId, String holdingType, String fundName,
Double shares, Double price, String priceDates, String currency,
Double value, Double buyAmount, Double lockedShares) {
super();
this.fundId = fundId;
this.holdingType = holdingType;
this.fundName = fundName;
this.shares = shares;
this.price = price;
this.priceDates = priceDates;
this.currency = currency;
this.value = value;
this.buyAmount = buyAmount;
this.lockedShares = lockedShares;
}


?
?
public String getFundName() {
returnfundName;
}




publicint getFundId() {
returnfundId;
}




public String getHoldingType() {
returnholdingType;
}


publicvoid setHoldingType(String holdingType) {
this.holdingType = holdingType;
}


?
?
publicvoid setFundId(int fundId) {
this.fundId = fundId;
}


?
?
publicvoid setFundName(String fundName) {
this.fundName = fundName;
}
public Double getShares() {
returnshares;
}
publicvoid setShares(Double shares) {
this.shares = shares;
}
public Double getPrice() {
returnprice;
}
publicvoid setPrice(Double price) {
this.price = price;
}
public String getPriceDates() {
returnpriceDates;
}
publicvoid setPriceDates(String priceDates) {
this.priceDates = priceDates;
}
public String getCurrency() {
returncurrency;
}
publicvoid setCurrency(String currency) {
this.currency = currency;
}
public Double getValue() {
returnvalue;
}
publicvoid setValue(Double value) {
this.value = value;
}
public Double getBuyAmount() {

kolli
20 Jul 2010, 5:40 AM
Well did u create any columnConfigs. U didnot in the code.

xworker
20 Jul 2010, 5:51 AM
Hi

I did not post the complete code for creating the grid. Here it is:




List<Holding> holdings = customerDetail.getHoldings();

GroupingStore<Holding> store = new GroupingStore<Holding>();
store.groupBy("holdingType");
store.add(holdings);

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();


//id

SummaryColumnConfig<Double> id = new SummaryColumnConfig<Double>(
"fundId", "FundId", 10);

//holdingType

SummaryColumnConfig<Double> holdingType = new SummaryColumnConfig<Double>(
"holdingType", "holdingType", 40);



//fundName

SummaryColumnConfig<Integer> fundName = new SummaryColumnConfig<Integer>(
"fundName", "Fund Name", 50);

fundName.setSummaryType(SummaryType.COUNT);
fundName.setSummaryRenderer(new SummaryRenderer() {
public String render(Number value, Map<String, Number> data) {
return value.intValue() > 1 ? "(" + value.intValue()
+ " Funds)" : "(1 Fund)";
}
});

//shares

SummaryColumnConfig<Double> shares = new SummaryColumnConfig<Double>(
"shares", "Shares", 20);

//price

SummaryColumnConfig<Double> price = new SummaryColumnConfig<Double>(
"price", "Price", 20);
price.setNumberFormat(NumberFormat.getCurrencyFormat());
price.setSummaryFormat(NumberFormat.getCurrencyFormat());
price.setSummaryType(SummaryType.SUM);



//priceDate

SummaryColumnConfig<Double> priceDate = new SummaryColumnConfig<Double>(
"priceDate", "Price date", 30);



//value

SummaryColumnConfig<Double> value = new SummaryColumnConfig<Double>(
"value", "Value", 30);
value.setNumberFormat(NumberFormat.getCurrencyFormat());
value.setSummaryFormat(NumberFormat.getCurrencyFormat());
value.setSummaryType(SummaryType.SUM);
value.setAlignment(HorizontalAlignment.RIGHT);

NumberField nf = new NumberField();
nf.setAutoValidate(true);

//buyAmount

SummaryColumnConfig<Double> buyAmount = new SummaryColumnConfig<Double>(
"buyAmount", "buyAmount", 30);
buyAmount.setNumberFormat(NumberFormat.getCurrencyFormat());
buyAmount.setSummaryFormat(NumberFormat.getCurrencyFormat());
buyAmount.setSummaryType(SummaryType.SUM);


//lockedShares

SummaryColumnConfig<Double> lockedShares = new SummaryColumnConfig<Double>(
"lockedShares", "lockedShares", 10);

columns.add(id);
columns.add(holdingType);

columns.add(fundName);
columns.add(shares);
columns.add(price);
columns.add(priceDate);
columns.add(value);
columns.add(buyAmount);
columns.add(lockedShares);

ColumnModel cm = new ColumnModel(columns);

GroupSummaryView summary = new GroupSummaryView();
summary.setForceFit(true);
summary.setShowGroupedColumn(false);



Grid<Holding> customerGrid = new Grid<Holding>(store, cm);

customerGrid.setBorders(true);
customerGrid.setView(summary);
customerGrid.getView().setShowDirtyCells(false);

ContentPanel panel = new ContentPanel();
panel.setHeading("Holdings");
// panel.setIcon(Resources.ICONS.table());

panel.setCollapsible(true);
panel.setFrame(true);
panel.setSize(1000, 600);
panel.setLayout(new FitLayout());
panel.add(customerGrid);
contentPanel.add(panel);


Thanks

sven
20 Jul 2010, 5:52 AM
The problem is your model. You dont want to extend BaseModel with your structure. You want to implement BeanModelTag

xworker
20 Jul 2010, 5:55 AM
Ok, tried that, but then I get an error on the line :
GroupingStore<Holding> store = new GroupingStore<Holding>(); saying
"

Multiple markers at this line
- Bound mismatch: The type Holding is not a valid substitute for the bounded parameter <M extends ModelData> of
the type GroupingStore<M>
- Bound mismatch: The type Holding is not a valid substitute for the bounded parameter <M extends ModelData> of
the type GroupingStore<M>"

xworker
20 Jul 2010, 10:55 PM
So the problem seems to be that its not possible to create a GroupingStore with a pojo implementing
BeanModelTag instead of extending ModelData ?

sven
21 Jul 2010, 1:12 AM
It is possible. Your errormessage already told you exactly what is wrong. When using GWT you need to have basic java skills to interprete errormessages that are not even linked to GXT or GWT.

GroupingStore<BeanModel> store = new GroupingStore<BeanModel>();

You Holding gets transformed to a BeanModel.

This is also covered in several examples in the explorer.

xworker
21 Jul 2010, 1:19 AM
Thank you for your reply.

I have tried what you suggest but it doesnt work.




GroupingStore<BeanModel> store = new GroupingStore<BeanModel>();
store.add(customerDetail.getHoldings());


customerDetail.getHoldings() returns a List<Holding> and Holding is declared as

public class Holding implements Serializable, BeanModelTag

sven
21 Jul 2010, 1:23 AM
If you dont want help, just say it, i can ignore this thread.

I removed your improper comment

xworker
21 Jul 2010, 1:25 AM
When have I stated that I don't want help? I have posted the code I tried after your suggestion.

sven
21 Jul 2010, 1:28 AM
Your improper comment told me that you dont want help, as you already know everything, never make mistakes and dont accept any help.

sven
21 Jul 2010, 1:40 AM
This could also be found be the forum search, but here it is:

store.add(BeanModelLookup.get().getFactory(Holding.class).createModel(customerDetail.getHoldings()));

xworker
21 Jul 2010, 1:44 AM
Thank you. That was the answer, now it works.

xworker
21 Jul 2010, 1:49 AM
What improper comment would that be? I just think your answer that "I lack basic java knowledge" was rude and uncalled for. I don't think I lack basic java knowledge. I don't know everything, have never stated so, and I am new the GXT framework.

sven
21 Jul 2010, 1:53 AM
YOu got a detailed description of what was wrong. If you were unable to understand it, than you lack basic knowledge about java.

It should be normal that you cannot just copy&paste code and hope it works. You need to understand the code. That is why it does nothelp if i give the code. You need to want to try to understand it, but your comment just told me that you dont want to understand it, you want me to give you the full code you need.

The comment was nothing than rude or anything. But attacking me than that i spend my free time to help you is rude.