Problem Updating View Programmatically

27 views
Skip to first unread message

gcr

unread,
Sep 19, 2011, 1:38:29 AM9/19/11
to Google Web Toolkit
All,

I am attempting to do something that must be very common, but I can't
get it to work. I place either a canvas or a TextBox on the screen
and change it programmatically and my changes don't show up on the
screen.

I am using uibinder. If I give say, my TextBox an initial value
<g:TextBox>XXX</g:TextBox> this value is displayed on the screen when
I run the app. But if I attempt to change the value by calling
textBox.setText("YYY") from the program. The display continues to
show the original XXX. It's as if I need to do some kind of refresh.

A similar thing is happening with Canvas. I create the Canvas in the
program, add it to a SimpleLayoutPanel, and draw on it--nothing
appears.

All this is consistent throughout my app. Any data values I declare
in the uibinder file. appear just fine, but any values is set from the
program have no effect.

Clearly, I am doing something wrong, but what? Do I need to repaint
somehow?

Thanks

Y2i

unread,
Sep 19, 2011, 2:27:57 AM9/19/11
to google-we...@googlegroups.com
May be you are missing ui:field="textBox" attribute?

<g:TextBox ui:field="textBox">XXX</g:TextBox>


Alexandre Dupriez

unread,
Sep 19, 2011, 6:26:42 AM9/19/11
to Google Web Toolkit
You do not need to invalidate or refresh your components to make them
updated with your last change.
There must be something wrong with your UI binding indeed. Could you
please post us a snippet of your xml? Which widget do you use to bing
the ui?

gcr

unread,
Sep 20, 2011, 1:57:00 AM9/20/11
to Google Web Toolkit
Thanks for responding.

Thanks in advance for any help.

Since I have posed two questions at once, if it's all the same to
everyone, I'd like to focus on my issue with canvas first.

What's goes wrong when I try to make a Canvas part of a view using
uibinder?

If I code something like this, I see a Canvas with the appropriate
stuff drawn on it. But (see below)...

public void onModuleLoad() {
SimpleLayoutPanel pnl = new SimpleLayoutPanel();
Canvas cvs = Canvas.createIfSupported();
pnl.add(cvs);
RootLayoutPanel.get().add(pnl);
Context2d ctx = cvs.getContext2d();
int w = cvs.getCoordinateSpaceWidth();
int h = cvs.getCoordinateSpaceHeight();
ctx.setFillStyle("#d53747");
ctx.moveTo(0, 0);
ctx.lineTo(w, h);
ctx.beginPath();
ctx.arc(w/2, h/2, 9, 0, Math.PI * 2.0, true);
ctx.closePath();
ctx.fillText("Yay!!", w/2, h/2 + 20);
ctx.fill();
}

if I code something like this:

(1) Here's the uibinder declaration.

<g:SimpleLayoutPanel addStyleNames="{style.pnl}" ui:field="pnl">
<c:Canvas ui:field="cvs" />
</g:SimpleLayoutPanel>

(2) Here's the corresponding field in the view class:

@UiField
Canvas cvs;

(3) And of course, Canvas needs this:

@UiFactory public Canvas getCvs() {
return Canvas.createIfSupported();
}

Then do the same drawing, nothing appears on the Canvas. It remains
blank. It has size. Nothing is null. No errors are thrown.

Context2d ctx = vw.getCtx();
int w = vw.getCvs().getCoordinateSpaceWidth();
int h = vw.getCvs().getCoordinateSpaceHeight();
ctx.setFillStyle("#d53747");
ctx.beginPath();
ctx.arc(10, 10, 9, 0, Math.PI * 2.0, true);
ctx.closePath();
ctx.fillText("Yay!!", w/2, h/2 + 10);
ctx.fill();


On Sep 19, 3:26 am, Alexandre Dupriez <alexandre.dupr...@gmail.com>
wrote:

Y2i

unread,
Sep 20, 2011, 2:12:35 AM9/20/11
to google-we...@googlegroups.com
Try replacing
------------------------------------
Context2d ctx = vw.getCtx(); 
int w = vw.getCvs().getCoordinateSpaceWidth(); 
int h = vw.getCvs().getCoordinateSpaceHeight(); 
------------------------------------

with
------------------------------------
Context2d ctx = cvs.getContext2d(); 
int w = 
cvs.getCoordinateSpaceWidth(); 
int h = 
cvs.getCoordinateSpaceHeight(); 
------------------------------------

vw.getCvs() always creates a new instance which you don't want to do.
And I suspect vw.getCtx() also calls vw.getCvs()
 
Reply all
Reply to author
Forward
0 new messages