@ContextParam"

From Documentation
m ((via JWB))
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
 +
{{Deprecated | url=[http://books.zkoss.org/zk-mvvm-book/8.0/syntax/contextparam.html zk-mvvm-book/8.0/syntax/viewmodel/parameters/contextparam]|}}
  
  
Line 13: Line 14:
 
     BIND_CONTEXT, //BindContext instance
 
     BIND_CONTEXT, //BindContext instance
 
     BINDER, //Binder instance
 
     BINDER, //Binder instance
 +
    TRIGGER_EVENT, //Event that trigger the command (since 6.0.1)
 +
    COMMAND_NAME, //Command name (since 6.0.1)
 
     EXECUTION, //Execution instance
 
     EXECUTION, //Execution instance
 
     COMPONENT, //Component instance of current binding
 
     COMPONENT, //Component instance of current binding
Line 20: Line 23:
 
     DESKTOP, //Desktop instance of current component
 
     DESKTOP, //Desktop instance of current component
 
     SESSION, //Session instance
 
     SESSION, //Session instance
     APPLICATION, //Application instance
+
     APPLICATION //Application instance
 
}
 
}
  
  
 
</source>
 
</source>
 
  
 
= Description =
 
= Description =
Line 39: Line 41:
 
<source lang="java">
 
<source lang="java">
 
     @Init
 
     @Init
     public void init(@ContextParam(ContextType.APPLICATION_SCOPE) Map<?, ?> applicationScope,
+
     public void init(
            @ContextParam(ContextType.SESSION_SCOPE) Map<?, ?> sessionScope,
 
            @ContextParam(ContextType.DESKTOP_SCOPE) Map<?, ?> desktopScope,
 
            @ContextParam(ContextType.PAGE_SCOPE) Map<?, ?> pageScope,
 
            @ContextParam(ContextType.SPACE_SCOPE) Map<?, ?> spaceScope,
 
            @ContextParam(ContextType.REQUEST_SCOPE) Map<?, ?> requestScope,
 
            @ContextParam(ContextType.COMPONENT_SCOPE) Map<?, ?> componentScope,
 
 
 
 
             @ContextParam(ContextType.EXECUTION) Execution execution,
 
             @ContextParam(ContextType.EXECUTION) Execution execution,
 
             @ContextParam(ContextType.COMPONENT) Component component,
 
             @ContextParam(ContextType.COMPONENT) Component component,
 +
            @ContextParam(ContextType.VIEW) Component view,
 
             @ContextParam(ContextType.SPACE_OWNER) IdSpace spaceOwner,  
 
             @ContextParam(ContextType.SPACE_OWNER) IdSpace spaceOwner,  
 
             @ContextParam(ContextType.PAGE) Page page,
 
             @ContextParam(ContextType.PAGE) Page page,
Line 64: Line 60:
  
 
<vbox id="vbox" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('eg.ContextParamVM')">
 
<vbox id="vbox" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('eg.ContextParamVM')">
 
+
    <button id="cmd" label="cmd" onClick="@command('cmd')" />
<button id="cmd" label="cmd" onClick="@command('cmd')" >
 
 
</vbox>
 
</vbox>
  
Line 83: Line 78:
 
*In above example, the variable component is a Button object and view is a Vbox object.
 
*In above example, the variable component is a Button object and view is a Vbox object.
  
 +
=Version History=
  
 
+
{| class='wikitable' | width="100%"
 
 
=Version History=
 
{{LastUpdated}}
 
{| border='1px' | width="100%"
 
 
! Version !! Date !! Content
 
! Version !! Date !! Content
 
|-
 
|-

Latest revision as of 07:36, 8 July 2022

Stop.png This article is out of date, please refer to zk-mvvm-book/8.0/syntax/viewmodel/parameters/contextparam for more up to date information.


Syntax

@ContextParam(ContextType.PAGE)

Enumeration of all context

enum ContextType {
    BIND_CONTEXT,	//BindContext instance
    BINDER,			//Binder instance
    TRIGGER_EVENT,	//Event that trigger the command (since 6.0.1)
    COMMAND_NAME,	//Command name (since 6.0.1)
    EXECUTION,		//Execution instance
    COMPONENT,		//Component instance of current binding
    SPACE_OWNER,	//IdSpance instance of spaceOwner of current component
    VIEW,			//the view component of binder
    PAGE,			//Page instance of current component
    DESKTOP,		//Desktop instance of current component
    SESSION,		//Session instance
    APPLICATION	//Application instance
}

Description

Target: A method's parameter (for initial and command methods)

Purpose: Tell binder to pass the context object with specified type.

The annotation is applied to initial (or command) method's parameter. Methods can get various ZK context object like: Page or Desktop by applying annotation on parameters.

Example

Retrieve various context object in a ViewModel

    @Init
    public void init(
            @ContextParam(ContextType.EXECUTION) Execution execution,
            @ContextParam(ContextType.COMPONENT) Component component,
            @ContextParam(ContextType.VIEW) Component view,
            @ContextParam(ContextType.SPACE_OWNER) IdSpace spaceOwner, 
            @ContextParam(ContextType.PAGE) Page page,
            @ContextParam(ContextType.DESKTOP) Desktop desktop,
            @ContextParam(ContextType.SESSION) Session session,
            @ContextParam(ContextType.APPLICATION) WebApp application,

            @ContextParam(ContextType.BIND_CONTEXT) BindContext bindContext,
            @ContextParam(ContextType.BINDER) Binder binder) {..}

The following is another example.

<vbox id="vbox" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('eg.ContextParamVM')">
    <button id="cmd" label="cmd" onClick="@command('cmd')" />
</vbox>

A ViewModel used by above zul

public class ContextParamVM{
	@Command
	public void cmd(@ContextParam(ContextType.COMPONENT) Component component,
			@ContextParam(ContextType.VIEW) Component view) {
	}
}
  • In above example, the variable component is a Button object and view is a Vbox object.

Version History

Version Date Content
6.0.0 February 2012 The MVVM was introduced.




Last Update : 2022/07/08

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.