-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I am planning to port (at least to try) an existing application to ZK6.
What I am missing in all the sample code I've seen until now, is an example how to get typical context information like
* arg - from Executions.createComponents(...)
* param - from an HTTP request
* session - the HTTP session
into the ViewModel.
Of course there is Executions.getCurrent(), but there are also some subtle issues with that.
For example, it may contain wrong information if it is called in an event/command handler.
I guess it would be best to retrieve all that needed information in the constructor.
In the good ol' composer world, I've never had to take care about that. The instance variables arg, param, etc. always contained the correct values.
ViewModel is now a POJO, so different approaches are needed.
So are there some best practices how to achieve that?
I post a feature here, http://tracker.zkoss.org/browse/ZK-667
Currently, annotate @Init on a method of viewmodel with one parameter which type is BindContext
@Init public void myinit(BindContext ctx){ .. }
it is the correct time to get value from Executions.getCurrent()
===
Supports after 12/21
@BindingParam (same as @Param, @Param was deprecated) to get binding arg
@ExecutionParam to get current execution attribute
@ExecutionArgParam to get current execution arg attribute
@ScopeParam to get attribute from scopes
@ContextParam to get special context object (ex, execution, desktop, session...)
@SelectorParam to get components by selector.
can use @*Param both in @Init and @Command, for example
@Init
public void myinit(@ExecutionArgParam("mode") String mode){
..
}
Thanks for tracking it and for the "workaround".
Hi,
I am also currently struggling with passing arguments between composers. I used put them into the args using Exceutions.createComponents(String, Component, Map). As I understand, the execution pushes the arg map into a list which it must be popped from lateron. Sometime ZK takes care about popping it, sometimes not. Now what I need to do is
I have a form in which I can edit resources that are displayed in a tree. When the user clicks save / apply I want to update the view of the resource in the tree. Therefore, I must tell the view model which tree item(s) to update when the data was successfully updated. The form displaying the resource is opened by clicking on a tree item. In the listener I push the arguments into the execution:
Executions.getCurrent().pushArg( new ScreenModel.Args() .selectedItems(item.getTree().getSelectedItems()) .getArgMap());
mRootComponent = Executions.createComponents(content.getSubscreen().getZul(), mWest, null);
Regards,
David
Asked: 2011-12-09 07:49:33 +0800
Seen: 942 times
Last updated: Dec 15 '11