Formatted field doesn't update at blurr

5 views
Skip to first unread message

dorel

unread,
Jul 26, 2010, 3:53:19 AM7/26/10
to GWT Pectin
Hey Andrew. First of all thanks for the nice model binding solution,
I've been waiting too long for a similar solution to JGoodies binding
for GWT. I'm using pecting since 0.5, everything works nice, still I
have encountered a minor issue lately, when using formatted fields. I
am using this code to format a money field:

public FormattedFieldModel<Double> fldPrice =
formattedFieldOfType(Double.class).using(new
MoneyAmountFormat()).boundTo(bindings, "price");

However, after editing it with the value '2.2' and leaving (blurring)
the field the value should change to '$2.2' due to the formatter.
However the field remains '2.2' BUT, if I am adding a blurr handler
like this:

txtPrice.addBlurHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
/*
* WARNING force formatting ! shouldn't it take place
* whenever the value changes ?!
*/
itemModel.fldPrice.setFormat(new MoneyAmountFormat());
}
});

the value appears as expected after editing the field.
Is there something wrong that I am doing, is there something more I
should do to have this formatted properly when I am leaving the
field ?
BTW, the field also displays correctly when first displayed in the
page, if there is a proper value in the backing model

Thanks a ton again for a great lib,
Dorel

Andrew

unread,
Jul 26, 2010, 4:17:21 AM7/26/10
to GWT Pectin
Hi Dorel,

On Jul 26, 5:53 pm, dorel <dorel.va...@gmail.com> wrote:
> Hey Andrew. First of all thanks for the nice model binding solution,
> I've been waiting too long for a similar solution to JGoodies binding
> for GWT. I'm using pecting since 0.5, everything works nice,

Yep, I seriously missed a ValueModel style framework when I started
using GWT. Once you've used one it's hard to go back.

> still I
> have encountered a minor issue lately, when using formatted fields. I
> am using this code to format a money field:
>
> public FormattedFieldModel<Double> fldPrice =
> formattedFieldOfType(Double.class).using(new
> MoneyAmountFormat()).boundTo(bindings, "price");
>
> However, after editing it with the value '2.2' and leaving (blurring)
> the field the value should change to '$2.2' due to the formatter.
> However the field remains '2.2'


Yep this is a bug, can you raise an issue for it?

The problem is the binding doesn't do a round trip so when the process
of text->parse->value->format->text produces a different text value
the widget doesn't get udpated. Hopefully I should be able to just re-
format the value in the binding and push it back to the widget.

Version 0.8 still has a little bit of work to do on nested properties
so I should be able to get it in for the next release.

Cheers
Andrew

dorel

unread,
Jul 26, 2010, 4:28:41 AM7/26/10
to GWT Pectin
Whee, that was a fast reply, thanks man. Here's the issue:

http://code.google.com/p/gwt-pectin/issues/detail?id=29

Andrew

unread,
Jul 26, 2010, 4:51:11 AM7/26/10
to GWT Pectin
Your timing was impecable, you caught me working on it (c:

Andrew

unread,
Jul 26, 2010, 6:13:57 AM7/26/10
to GWT Pectin
This is actually a little more difficult that I thought. The main
problem is that pushing the value back into the widget after value
change events buggers things if the HasValue fires changes on key
events (i.e. like EnhancedTextBox). In this case the widget updates
and kills the users edit. It works fine for onBlur value change
events but I really need to solve it for both cases (as it has
implications for the validation plugin as well).

Andrew

unread,
Jul 27, 2010, 2:14:58 AM7/27/10
to GWT Pectin
I've updated this in svn now, basically I've added a `sanitiseText()`
to `FormattedFieldModel` that will reformat the text value. The
method doesn't affect the actual value and won't change anything if
the format barfs (so text validators can still have a crack at it).

You can trigger this from the view bindings using
`binder.bind(formattedModel).to(widget).sanitiseTextOnBlur()`

There is no automatic sanitisation since there's no one way to do it
that won't bugger things up in other cases.

The exact mechanism may change in the future if I start support
triggering commands from events i.e.
binder.onBlurOf(someWidget).invoke(someCommand).

Cheers
Andrew

dorel

unread,
Jul 27, 2010, 2:24:55 AM7/27/10
to GWT Pectin
Cool man, looks like just enough to make things rolling, also it's
good that the user needs to make a conscious decision to have it
working. Thanks a lot :-)
Reply all
Reply to author
Forward
0 new messages