PDA

View Full Version : problem with GridCellRenderer



ghatfan99
11 Aug 2010, 12:50 AM
hello,
me problem is that i have an class Agent and one of his attribute is abilities witch is a list of string like("barMan","hero",... ), in my Grid i want that the field returns a line for every ability and i use this code:



GridCellRenderer<Agent> agentSpecialities = new GridCellRenderer<Agent>()
{

@Override

public Object render(Agent model, String property,
com.extjs.gxt.ui.client.widget.grid.ColumnData config,
int rowIndex, int colIndex, ListStore<Agent> storeAgent, Grid<Agent> gridAgents)
{

if(model.getAbilities() == null)
{
return ("agent without abilities");
}

return model.getAbilities();
}
};

but the result of this code is:
[bareMan, hero] in the same line.
i know that i must use a listStore for saving the abilities, but the listStore doesn't work with String value.
did you have some ideas.

sven
11 Aug 2010, 1:32 AM
You should iterate over the list that model.getAbilities() returns and create your own html formated string with linebreaks.

ghatfan99
12 Aug 2010, 12:04 AM
i write this code:



public class AgentSpecialiteRenderer implements GridCellRenderer<Agent>{
public AgentSpecialiteRenderer(){

}

@Override

public Object render(Agent model, String property, ColumnData config,
int rowIndex, int colIndex, ListStore<Agent> store, Grid<Agent> grid) {
String abilities = new String();
if(model.getAbilities() == null)
{
abilities = " ";
}
for (int i = 0 ; i < model.getAbilities().size() ; i++)
{
abilities = "<span style='font-weight: bold;color:blue; font-size:12px'>" + model.getAbilities().get(i)+ +"<br />" +"</span>" ;
}
return abilities;
}

and i dont know where is tha problem???
thank's

sven
12 Aug 2010, 2:10 AM
You are reassigning "abilities" always. You need to concat the strings

ghatfan99
12 Aug 2010, 2:15 AM
hello
sorry (i am a beginner), but i don't understand what do you mean in your answer, i must do ????
thanks again

sven
12 Aug 2010, 3:15 AM
http://www.google.de/search?q=java+string+concatenation

ghatfan99
12 Aug 2010, 3:55 AM
always no,
i visited this page this morning befor that i posted the subject, but i am still not able to find where is the problem, what i must add to my code to make it works,
i am very sorry for bothering you

sven
12 Aug 2010, 4:00 AM
public Object render(Agent model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<Agent> store, Grid<Agent> grid) {
String abilities = "";
if (model.getAbilities() == null) {
abilities = " ";
} else {
for (int i = 0; i < model.getAbilities().size(); i++) {
abilities += "<span style='font-weight: bold;color:blue; font-size:12px'>" + model.getAbilities().get(i)
+ "<br /></span>";
}
}
return abilities;

}

ghatfan99
12 Aug 2010, 4:40 AM
thank you very much, i am :">