PDA

View Full Version : Cannot recovery a textfield's value



aurelie
13 Aug 2009, 12:42 AM
Hi,

I have a grid with a gridCellRenderer which contains a textfield.
A user can modify its value and my problem is that I don't know how to recovery this value.

here is my code :


public class GestionIndicateurProjet extends LayoutContainer {
private ProjetBean projet; //projet pour lequel on veut visualiser les indicateurs
private IndicateurServiceAsync indicateurService = (IndicateurServiceAsync)GWT.create(IndicateurService.class);
private IndicateurProjetServiceAsync indicateurProjetService = (IndicateurProjetServiceAsync)GWT.create(IndicateurProjetService.class);
private QualityConstants constants = GWT.create(QualityConstants.class);

public GestionIndicateurProjet(ProjetBean projet){
this.projet = projet;
}

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);

//Champ représentant la valeur du seuil 1 de l'indicateur
GridCellRenderer<ModelData> valeurSeuil1 = new GridCellRenderer<ModelData>(){
public Object render(final ModelData model, final String property, ColumnData config, final int rowIndex,
final int colIndex, ListStore<ModelData> store, final Grid<ModelData> grid)
{
final TextField<Long> valeur1 = new TextField<Long>();
valeur1.setWidth(40);

indicateurService.findByPK((String)model.get(property), new AsyncCallback<IndicateurBean>(){

@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}

@Override
public void onSuccess(final IndicateurBean indicateur) {
indicateurProjetService.getIndicateurProjetByProjetAndByIndicateur(indicateur, projet, new AsyncCallback<IndicateurProjetBean>(){

@Override
public void onFailure(Throwable caught) {
caught.printStackTrace();
}

@Override
public void onSuccess(IndicateurProjetBean indicateurProjet) {
if(indicateurProjet == null) //si l'indicateur n'est pas rattaché à ce projet
{
//on affiche la valeur par défaut qu'il a été attribué à cet indicateur
valeur1.setValue(indicateur.getValeurSeuil1ParDefaut());
}

else //cet indicateur est rattaché à ce projet
{
//on affiche la valeur du seuil1 qui lui a été attribué pour ce projet
valeur1.setValue(indicateurProjet.getValeurSeuil1());
}
}
});
}
});
return valeur1;
}
};

//chargement de tous les indicateurs existants dans la base
RpcProxy<List<IndicateurBean>> proxy = new RpcProxy<List<IndicateurBean>>() {
@Override
public void load(Object loadConfig, AsyncCallback<List<IndicateurBean>> callback) {
indicateurService.getListIndicateurs(callback);
}
};

BeanModelReader reader = new BeanModelReader();

// loader and store
ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, reader);
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);
loader.load();

final List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

//colonne des noms des indicateurs
ColumnConfig column = new ColumnConfig("nom", constants.indicator_name(), 100);
configs.add(column);

//colonne du seuil1 de l'indicateur
column = new ColumnConfig("code", constants.indicator_threshold1(), 50);
column.setRenderer(valeurSeuil1);
configs.add(column);

ColumnModel cm = new ColumnModel(configs);

final Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);
grid.setAutoHeight(true);
grid.setAutoWidth(true);
add(grid);
}
}

aurelie
13 Aug 2009, 6:58 AM
Can someone help me please?
I really need to solve this problem!!

Arno.Nyhm
13 Aug 2009, 7:41 AM
1.) pls dont bump your question after some hours - every question is urgent! (also think about different timezones where the user lives)
2.) i dont understand why you need to recover it? i dont see any savings?
3.) you can make the field readonly. so nobody can change it.
4.) you can get the first value with

Field.html#getOriginalValue()
http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/widget/form/Field.html#getOriginalValue() (http://extjs.com/forum/../deploy/gxtdocs/com/extjs/gxt/ui/client/widget/form/Field.html#getOriginalValue%28%29)

5.) if this is not set properly you can additional also set this value in your renderer:
Field.html#setOriginalValue(D)
http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/widget/form/Field.html#setOriginalValue(D) (http://extjs.com/forum/../deploy/gxtdocs/com/extjs/gxt/ui/client/widget/form/Field.html#setOriginalValue%28D%29)

6.) for performance i think its not the best to make for every cell you make two additional rpc calls to the server.
better ist to create a "backpacker" model for your grid where you collect the needed data in one call and then transfer it only once to the client and display it poperly. i think this speed up your grid!

aurelie
13 Aug 2009, 11:27 PM
I need an user can change values of textfields cause I want register them in an entity which is different of the entity of the store.
When the grid appears, values of textfields which appears are values loaded from a bean "IndicateurBean" and after the change of the user, i want to register new values in a bean "IndicateurProjetBean".
It's why I need to recovery values of the textfield.
I can't change values in bean "IndicateurBean".

for your "6)", i think that i can't do otherwise.

Arno.Nyhm
14 Aug 2009, 8:41 AM
is 4 & 5 working for you?

aurelie
16 Aug 2009, 11:13 PM
I want to recovery new value (entered by the user), not the original value.
And if I change the originalValue with "setOriginalValue", how can I recovery the new value?

Arno.Nyhm
19 Aug 2009, 1:15 AM
I want to recovery new value (entered by the user), not the original value.
And if I change the originalValue with "setOriginalValue", how can I recovery the new value?

sorry. but this is not called "recover". recover means to get previous values back.
( see also http://en.wikipedia.org/wiki/Data_loss#Data_Recovery )


if i look at your first posting i see the problem is then, that you have no reference to your own created textfield by your gridcellcenderer. thats a completly different question.

one solution is to remember the references to this textfields in a List/map.
or use other methods to find these textfields in a GridCell.

Arno.Nyhm
19 Aug 2009, 1:20 AM
but the next question is:

why you use a textfield instead the functionality which is already included in the grid, where you can edit a value?

http://extjs.com/examples/explorer.html#editablegrid


then you just need to fill the store with values instead of generating and filling the textfield.

the changed values are saved in the connected store:

look at this methods:
http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/store/Store.html#getModifiedRecords() (http://extjs.com/forum/../deploy/gxtdocs/com/extjs/gxt/ui/client/store/Store.html#getModifiedRecords%28%29)
http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/store/Store.html#getModels() (http://extjs.com/forum/../deploy/gxtdocs/com/extjs/gxt/ui/client/store/Store.html#getModels%28%29)

and:
http://extjs.com/deploy/gxtdocs/com/extjs/gxt/ui/client/store/Record.html (http://extjs.com/forum/../deploy/gxtdocs/com/extjs/gxt/ui/client/store/Record.html)

aurelie
19 Aug 2009, 6:31 AM
I want to use a textfield because the value that i want to edit is not necessarily the value of the bean which is loaded in the store.