Revision history [back]

click to hide/show revision 1
initial version

answered 2015-01-29 00:57:56 +0800

cor3000 gravatar image cor3000

ZK Team

The problem with using an "inline" macro is that there is no component for it in the resulting component tree, that's why the @bind() is never actually evaluated. (derived explanation based on http://books.zkoss.org/wiki/ZKDeveloper%27sReference/UIComposing/MacroComponent/InlineMacros#InlineversusRegularMacro)

However you can access includer and read attributes of it. http://books.zkoss.org/wiki/ZKDeveloper%27sReference/UIComposing/MacroComponent/Inline_Macros#arg.includer Still it cannot help with your usage.

Second problem even if using a "non-inline" macro is that the annotation @bind() will evaluate too late (after the components have been created inside). So the value is not available during component creation inside. And it requires at least a custom component class with MVVM annotations to trigger the @save for a specific event, you need to define as well. (http://books.zkoss.org/wiki/ZKDeveloper%27sReference/MVVM/Advanced/BindingAnnotationforaCustom_Component)

So an easy solution for some cases (maybe yours - wasn't too clear from your example) is to use a @ref(vm.field) to your macro and @load/@save/@bind to that reference inside your macro. The reference will delegate load and save operations to your vm.field.

I created this running example for your you to try. Maybe add what is missing in your macro so I can try to adjust the solution or suggest something different.

http://zkfiddle.org/sample/6sleo1/1-macro-with-MVVM-binding

Robert

The problem with using an "inline" macro is that there is no component for it in the resulting component tree, that's why the @bind() is never actually evaluated. (derived explanation based on http://books.zkoss.org/wiki/ZKDeveloper%27sReference/UIComposing/MacroComponent/InlineMacros#InlineversusRegularMacro)

However with an inline macro you can could access includer the arg.includer and read attributes of it. http://books.zkoss.org/wiki/ZKDeveloper%27sReference/UIComposing/MacroComponent/Inline_Macros#arg.includer Still it cannot help with your usage.

Second problem even if using a "non-inline" macro is that the annotation @bind() will evaluate too late (after the components have been created inside). So the value is not available during component creation inside. And it requires at least a custom component class with MVVM annotations to trigger the @save for a specific event, you need to define as well. (http://books.zkoss.org/wiki/ZKDeveloper%27sReference/MVVM/Advanced/BindingAnnotationforaCustom_Component)

So an easy solution for some cases (maybe yours - wasn't too clear from your example) is to use a @ref(vm.field) to your macro and @load/@save/@bind to that reference inside your macro. The reference will delegate load and save operations to your vm.field.

I created this running example for your you to try. Maybe add what is missing in your macro so I can try to adjust the solution or suggest something different.

http://zkfiddle.org/sample/6sleo1/1-macro-with-MVVM-binding

Robert

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