PDA

View Full Version : Change Text in a Dialog (with AdapterField)



shigure
27 Oct 2011, 8:40 AM
Hi,

I'm dealing with a simple custom Dialog to login.. I have the error displayed at the the bottom like through an AdapterField, such as



Text errorText = new Text(errorMessage);
errorText.setStyleName("errortext");
LayoutContainer errorPanel = new LayoutContainer();
errorPanel.add(errorText);
AdapterField errorAdapter = new AdapterField(errorPanel);
this.add(errorAdapter);


This first try went all fine, but problem is, i can get a few different error messages from the RPC, and i need to change the errorMessage string and display it accordingly. How do I do that?

I tried creating a first errorAdapter as before, and then change it and re-render it with the new error message i get from the RPC with something like:


errorText.setText(errorMessage);
errorPanel.removeAll();
errorPanel.add(errorText);
errorAdapter = new AdapterField(errorPanel);
this.add(errorAdapter);


and even add (from random googling..)



doLayout(true);
recalculate();
repaint();


but no luck. Always the same message I set at the very beginning. Any hints?

Is it possible to do want I'm trying to accomplish here?
I found this thread on changing field labels after rendering (http://www.sencha.com/forum/showthread.php?38066-Set-field-labels-after-rendering-a-form-panel) but the question remains unresolved (also, it's not exaclty the same thing..).

Thank you so much

shigure
3 Nov 2011, 1:30 AM
Help anyone? :)

Colin Alworth
3 Nov 2011, 10:17 AM
Unfortunately, you haven't given us enough to even replicate the setup you are currently using - several lines refer to 'this', which means you've subclassed something, but we can't see what, or what else has been changed. It also isn't clear how 'this' is added to the Dialog, or if perhaps it is the dialog itself.

Couple of things to try: First, use firebug, and see if you can see the text you've tried to add. If it is there, but hidden, then there is a style or layout issue. If it isnt there at all, it could still be a layout issue, or one of the fields/local vars you are using isn't actually being drawn.

Then, try to reproduce the issue in a very simple example, and paste the full example here. Reproducing it will make you tear it down until all that is left is the code that should be relevant here. If there happens to be a mistake in your own code, you often find it during this process. We can then look at the full example, and see everything that is going on - and even run it to reproduce your result.

shigure
7 Nov 2011, 7:15 AM
Thanks for you answer, Colin. Sorry, that was dumb of me not specifying what that this was: i subclassed the Dialog itself.

Anyway, your tip sent me in the right direction and I solved. I'm very new to Gxt and it didn't cross my mind to check the layout with Firebug! Thank you very much!

Just for history, brief report...
I gave up all the panel.add and panel.remove and by creating my Adapter field -inside a MyDialog class, that extends Dialog - as:



errorPanel = new LayoutContainer();
errorText = new Text("");
errorPanel.add(errorText);
errorPanel.setVisible(false);
AdapterField adapter = new AdapterField(errorPanel);
adapter.setHideLabel(true);
this.add(adapter);


then replacing the error message with my custom one each time, with



Element errorElement = errorPanel.getElement();
errorElement.setInnerText(errorMessage);
doLayout(true);
recalculate();
repaint();
errorPanel.show();


That works!