0

Data binding

asked 2010-09-29 09:58:46 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

Hi all,

I have a slight issue with data binding in a modal dialog. I have a main page using the <?init ... AnnotateDataBinderInit root="./winMain"> directive.
Pressing a button opens another ZUL in a modal dialog using the <?init ... AnnotateDataBinderInit root="./winModal">.
Everything works fine and the components of the modal window are saving values automatically to the model. The problem is that when i try to save the values manually - using the binder.saveAll() method - nothing happens.
Maybe i am a little bit dizzy but i think there was an older similar issue in the forum.

thanks

delete flag offensive retag edit

12 Replies

Sort by ยป oldest newest

answered 2010-09-29 15:52:49 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-09-29 15:53:07 +0800

. . . using the binder.saveAll() method - nothing happens. . . .

Which binder you mean?? The binder from the winMain or the binder from the winModal

link publish delete flag offensive edit

answered 2010-09-30 03:04:48 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

hi terry,

No. The binder in the winMain works fine. The "problematic" binder is the one in the winModal.

thx

link publish delete flag offensive edit

answered 2010-09-30 06:07:15 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

hard to see something without codes. Which zk version?

link publish delete flag offensive edit

answered 2010-09-30 06:15:40 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

@terrytornado

In case you have the time to reply.. I have examined your sample code (ArticleListCtrl / ArticleDetailCtrl) and i am not doing something different. The only difference is that in the detail form controller (in your sample ArticleDetailCtrl) i am using the binder.SaveAll() method (which doesn't work). From what i see you are using the binder only to load the data and not to save them.

link publish delete flag offensive edit

answered 2010-09-30 06:16:17 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

zk 5.0.4

link publish delete flag offensive edit

answered 2010-09-30 07:39:02 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

ok. i started doing a simple example with a master/detail form to post here. after finishing i realized everything works fine :)

I need vacation....

anyway, thanks terry

link publish delete flag offensive edit

answered 2010-09-30 07:47:40 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-09-30 08:28:21 +0800

Hmmmmm,

have a deeper look at the WHOLE module.

The Binder is not a component, so it has no ID.
It's a helper class from zk who manage the binding of data to some dataBinding enabled components.
Therefore it's hard to share the binder over all composers that depends to ONE module.

In our case as we have changed the zk version from 3.6.x to 5.0.x we have done some modules with the automatically databinding.
We see that it reduce the lines of code dramatically instead of the manually databinding.
After a few tries we have seen that it's a best practice to share the models and not the binder.

For a clean concept of this, we have in all of this modules( all ready automatically databinded migrated modules) a mainController. This mainController
holds the Instances for all dependend subControllers and so the subControllers databinders. Therefore the lot of getters/setters.

Anyway have an exactly look in the setters/getters of the subControllers, from 'which controller' they get the objects. So a few of them
are created manually and not per Eclipse generated.

Have a look in the mainController's doSave() method. Their you will find your searched binder.saveAll() call.

public class ArticleMainCtrl extends GFCBaseCtrl implements Serializable {

   . . .

	/**
	 * Saves all involved Beans to the DB.
	 * 
	 * @param event
	 * @throws InterruptedException
	 */
	private void doSave(Event event) throws InterruptedException {
		// logger.debug(event.toString());

		// save all components data in the several tabs to the bean
		getArticleDetailCtrl().getBinder().saveAll();
                . . .


Next who can fail is that we have changed the subControllers to work NOT in ModalWindows, either in TabPanels.
So you does not to forget to overhanded the mainController to the subController and vice versa to have acces to it.
So you can adapt it to your needs.



A little bit of confusing can be by a look in a subController like ArticleDetailCtrl , you will find this setters/getters:
	
        public Article getArticle() {
		// STORED IN THE module's MainController
		return getArticleMainCtrl().getArticle();
	}

	public void setArticle(Article article) {
		// STORED IN THE module's MainController
		getArticleMainCtrl().setArticle(article);
	}


but you will find NO InstanceVariable like this:

 
public class ArticleDetailCtrl extends GFCBaseCtrl implements Serializable {
  .  .  .
  private Article article;

because, we don't need this setters/getters in this controller B U T the databinding Manager needs it if we use the 'article' var in the zul files like this:

articleDetail.zul

	<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./windowArticleDetail" ?>

	<window id="windowArticleDetail" apply="${articleDetailCtrl}"
		border="none" width="100%">
        .  .  .

              <textbox	id="txtb_artLangbezeichnung" value="@{controller.article.artLangbezeichnung}" . . .										
                                readonly="true" multiline="true" rows="10" width="98%" />

--> value="@{controller.article.artLangbezeichnung}"


best
Stephan

PS: I know, the zksample2 documentation is not up to date. I will have a look on it. But it's not far from them to write a book as all times extend the documentation :-)

link publish delete flag offensive edit

answered 2010-09-30 08:52:19 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

I see... Not bad at all! Especially if you have a multi-tab editor and you want to apply changes from various tabs to the same model. But what happens if you have to edit some information in a modal dialog opened from one of this tabs referring to the same model? Then it is necessary to save this info before closing the modal dialog. Otherwise you will loose the information entered. At some point the model may be partially updated. Just thoughts...

Thank you Stephan.

link publish delete flag offensive edit

answered 2010-09-30 09:17:35 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-09-30 09:22:47 +0800

In all that scenarios my friend would say "Think in Objects".

Means. If you open a modal dialog from such a tab you can and must overhanded the parentController and vice versa. That's all.
mainWin --> Executions.crea..... ,paramMap);
DialogWin --> afterCompose(){ // readBack the paramMap}
DialogWin --> afterCompose(){ // set DialogController to MainController}


in the modal window you call:

only basic code:

 void doSave()

      this.binder.saveAll();

      getMainController().getSubController2.getBinder().loadAll();
      getMainController().getSubController3.getBinder().loadAll();
      getMainController().getSubController4.getBinder().loadAll();
      
       // after saving close the modal dialog 
       this.onClose();

best
Stephan

link publish delete flag offensive edit

answered 2010-09-30 10:30:54 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

And your friend is right :)

Your approach is clear. Just a question:
Keeping all these references in the main controller doesn't makes the life of the garbage collector a little bit harder? I am not a zk expert but i am wondering what happens when you close a dialog? The memory is freed or remains allocated until the main controller is finalized?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-09-29 09:58:46 +0800

Seen: 879 times

Last updated: Oct 01 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More