0

In the JGoodies Bindings API (Link to API), there is a commitOnFocusLost parameter:

commitOnFocusLost - true to commit text changes on focus lost, false to commit text changes on every character typed

I want the behavior where there is no commit on focus lost and there is no commit while characters are being typed. I only want there to be a commit when I call Bindings.commitImmediatly(). Am I able to do that?

smuggledPancakes
  • 9,881
  • 20
  • 74
  • 113

2 Answers2

0

I am not 100% sure but yes you can do that.

Youll need to use the BasicComponentFactory to create your component And use the BasicComponentFactory.createTextField(ValueModel) with out the bool parameter.

THen you will need to figure out how and when to call a safe on your value model in order to be saved accordingly.

Stelios Philippou
  • 103
  • 1
  • 3
  • 13
0

You're probably looking for BufferedValueModel:

A ValueModel that wraps another ValueModel, the subject, and delays changes of the subject's value. Returns the subject's value until a value has been set. The buffered value is not written to the subject until the trigger channel changes to Boolean.TRUE.

PresentationModel.getBufferedValue() is useful for creating them.


However, generally I would avoid buffered models, because it adds additional complexity to an architectural model that is already fairly complex. Also, it doesn't work well with model validation. I would recommend leaving the auto-commit behavior of the bindings alone, and structure your code around it.

Karsten Lentzsch on buffering:

I personally prefer to buffer by copying the domain object graph. In many applications, the domain objects on the client are copies of back end domain objects. In this case you can operate on the client domain objects without any further buffering. To flush all changes made on the client domain objects you can just reload them from the back end.

Anyway, if you want buffer at the Presentation Model (PM) layer, you should make it available in the PM. Your presentation logic then operates on the buffered state, not on the domain state.

You can find an example in the Binding tutorial. See the BufferedAlbumPresentationModel. It demonstrates how to listen to changes in the buffered "classical" property to update the buffered "composerEnabled" property. Note that the BufferedClassicalChangeHandler copies behavior implemented in Album#setClassical that sets the composer to null if the album is not classical.

You can find the tutorial in the older packages in the JGoodies download archive.

Peter Tseng
  • 13,613
  • 4
  • 67
  • 57