|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Page
A page. A desktop consists of a set of pages.
When a ZK request is asking to render a new page, a new page is created and components that are created duing this request all belong to this page.
If a ZK requst is asking an update, it must have at lease one UUID of
a component (Component.getUuid()
.
From this UUID, we know which page it belongs and activate it
to process the update.
By activation, the system guarantees no concurrent access to pages and components (so you don't need use synchronized for them).
In portal and some environments, a client request (e.g., ServletRequest)
might consists of several ZK requests (AuRequest
).
While each ZK request might ask to create an independent page,
all these pages are grouped as a desktop, such that they are activated
and removed at the same time.
Moreover, pages in the same desktop could communicate to eath other
(see Inter-page communication).
A session, Session
, might have multiple desktops of pages,
Page
, while a page belongs to exactly one session.
A page, Page
, might have many components, Component
, while
a component belongs to exactly one page.
All components of the same desktop of pages are removed at the same time if a page become 'obsolete'.
During each execution (${link Execution}), exactly one desktop of
pages are locked (aka., activated). Though an execution serves
a client request (e.g., ServletRequest), a client request might consist
of multiple ZK request (AuRequest
).
Each ZK request might target to a different page (of the same desktop).
To do inter-page communication, you could do:
Execution.postEvent(org.zkoss.zk.ui.event.Event)
to post events to components from
another page.They are the same as handling components from the same page.
However, invoking method directly for components from another page has
one restriction:
It cannot create component.
Field Summary | |
---|---|
static int |
APPLICATION_SCOPE
Used with getAttribute(String, int) and related to denote
custom attributes shared by the whole application. |
static int |
DESKTOP_SCOPE
Used with getAttribute(String, int) and related to denote
custom attributes shared by the same desktop. |
static int |
PAGE_SCOPE
Used with getAttribute(String, int) and related to denote
custom attributes shared by the same page. |
static int |
REQUEST_SCOPE
Used with getAttribute(String, int) and related to denote
custom attributes shared by the same request. |
static int |
SESSION_SCOPE
Used with getAttribute(String, int) and related to denote
custom attributes shared by the same session. |
Method Summary | |
---|---|
boolean |
addClassResolver(ClassResolver resolver)
Adds a class resolver to this page. |
boolean |
addEventListener(java.lang.String evtnm,
EventListener<? extends Event> listener)
Adds an event listener to specified event for all components in this page. |
boolean |
addFunctionMapper(FunctionMapper mapper)
Adds the function mapper in addition to the current one. |
boolean |
addVariableResolver(VariableResolver resolver)
Adds a variable resolver that will be used to resolve a variable by getXelVariable(java.lang.String) . |
java.lang.Object |
getAttribute(java.lang.String name)
Returns the value of the specified attribute associated with this page. |
java.lang.Object |
getAttribute(java.lang.String name,
int scope)
Returns the value of the specified custom attribute in the specified scope. |
java.lang.Object |
getAttributeOrFellow(java.lang.String name,
boolean recurse)
Returns the custom attribute associated with this page, or the fellow of this page; or null if no found. |
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes()
Returns all custom attributes associated with this page. |
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes(int scope)
Returns all custom attributes of the specified scope. |
ComponentDefinition |
getComponentDefinition(java.lang.Class<? extends Component> cls,
boolean recurse)
Returns the component definition of the specified class, or null if not found. |
ComponentDefinition |
getComponentDefinition(java.lang.String name,
boolean recurse)
Returns the component definition of the specified name, or null if not found. |
ComponentDefinitionMap |
getComponentDefinitionMap()
Returns the map of component definitions (never null). |
Desktop |
getDesktop()
Returns the desktop that this page belongs to. |
java.lang.Iterable<EventListener<? extends Event>> |
getEventListeners(java.lang.String evtnm)
Returns an iterable collection of the event listeners for the given event. |
java.lang.Class<? extends ExpressionFactory> |
getExpressionFactoryClass()
Returns the implementation of the expression factory that is used by this page, or null if Configuration.getExpressionFactoryClass()
is used. |
Component |
getFirstRoot()
Returns the first root component. |
FunctionMapper |
getFunctionMapper()
Returns the function mapper for resolving XEL functions, or null if not available. |
java.lang.String |
getId()
Returns ID which is unique in the request (never null). |
Interpreter |
getInterpreter(java.lang.String zslang)
Returns the interpreter of the specified scripting language. |
LanguageDefinition |
getLanguageDefinition()
Returns the language definition that this page belongs to (never null). |
Component |
getLastRoot()
Returns the last root component. |
java.util.Iterator<EventListener<? extends Event>> |
getListenerIterator(java.lang.String evtnm)
Deprecated. As of release 6.0, replaced with getEventListeners(java.lang.String) .
Returns an iterator for iterating the event listeners for the given event. |
java.util.Collection<Interpreter> |
getLoadedInterpreters()
Returns all loaded interpreters. |
java.lang.String |
getRequestPath()
Returns the request path of this page, or "" if not available. |
java.util.Collection<Component> |
getRoots()
Returns a readonly list of the root components. |
java.lang.String |
getStyle()
Returns the CSS style of this page, or empty if not specified. |
java.lang.String |
getTitle()
Returns the title of the desktop this page belongs to (and evaluate it if it contains an expression). |
java.lang.String |
getUuid()
Returns UUID (universal unique ID) which is unquie in the whole session. |
java.lang.Object |
getXelVariable(java.lang.String name)
Returns a variable that is visible to XEL expressions. |
java.lang.Object |
getXelVariable(XelContext ctx,
java.lang.Object base,
java.lang.Object name,
boolean ignoreExec)
Returns a vairable that is visible to XEL expressions. |
java.lang.Class<?> |
getZScriptClass(java.lang.String clsnm)
Returns the class of the specified name by searching the classes defined in the loaded interpreters ( getLoadedInterpreters() ). |
Function |
getZScriptFunction(Component comp,
java.lang.String name,
java.lang.Class[] argTypes)
Returns the function of the specified name by searching the logical scope of the specified component in all the loaded interpreters. |
Function |
getZScriptFunction(java.lang.String name,
java.lang.Class[] argTypes)
Returns the function of the specified name by searching the loaded interpreters. |
java.lang.String |
getZScriptLanguage()
Returns the default scripting language which is assumed when a zscript element doesn't specify any language. |
java.lang.Object |
getZScriptVariable(Component comp,
java.lang.String name)
Returns the value of the variable of the specified name by searching the logical scope of the specified component in all the loaded interpreters, if any. |
java.lang.Object |
getZScriptVariable(java.lang.String name)
Returns the value of the variable of the specified name by searching the loaded interpreters, if any. |
boolean |
hasAttribute(java.lang.String name)
Returns if an attribute exists. |
boolean |
hasAttribute(java.lang.String name,
int scope)
Returns if an attribute exists. |
boolean |
hasAttributeOrFellow(java.lang.String name,
boolean recurse)
Returns if a custom attribute is associated with this page, or a fellow of this page. |
boolean |
hasFunctionMapper(FunctionMapper mapper)
Returns if the specified function mapper has been registered |
boolean |
hasVariableResolver(VariableResolver resolver)
Returns if the specified variable resolver has been registered |
void |
interpret(java.lang.String zslang,
java.lang.String script,
Scope scope)
Interprets a script in the sepcified scripting language in the context of the specified scope. |
void |
invalidate()
Invalidates this page to cause all components to redraw. |
boolean |
isAlive()
Returns whether the desktop is still alive. |
boolean |
isComplete()
Returns if this page is a complete page. |
boolean |
isListenerAvailable(java.lang.String evtnm)
Returns whether the event listener is available. |
java.lang.Object |
removeAttribute(java.lang.String name)
Removes the specified attribute custom associated with the page. |
java.lang.Object |
removeAttribute(java.lang.String name,
int scope)
Removes the specified custom attribute in the specified scope. |
void |
removeComponents()
Removes all components in this page. |
boolean |
removeEventListener(java.lang.String evtnm,
EventListener<? extends Event> listener)
Removes an event listener. |
boolean |
removeFunctionMapper(FunctionMapper mapper)
Removes a function mapper that was added by addFunctionMapper(org.zkoss.xel.FunctionMapper) . |
boolean |
removeVariableResolver(VariableResolver resolver)
Removes a variable resolver that was added by addVariableResolver(org.zkoss.xel.VariableResolver) . |
java.lang.Class<?> |
resolveClass(java.lang.String clsnm)
Resolves the class of the specified name. |
java.lang.Object |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets the value of the specified custom attribute associated with this page. |
java.lang.Object |
setAttribute(java.lang.String name,
java.lang.Object value,
int scope)
Sets the value of the specified custom attribute in the specified scope. |
void |
setComplete(boolean complete)
Sets if the page is a complete page. |
void |
setExpressionFactoryClass(java.lang.Class<? extends ExpressionFactory> expfcls)
Sets the implementation of the expression factory that is used by this page. |
void |
setId(java.lang.String id)
Sets the identifier of this page. |
void |
setStyle(java.lang.String style)
Sets the CSS style of this page. |
void |
setTitle(java.lang.String title)
Sets the title of the desktop this page belongs to (it might contain an expression). |
void |
setZScriptLanguage(java.lang.String zslang)
Sets the defafult scripting language which will be assumed if a zscript element doesn't specify any language. |
Methods inherited from interface org.zkoss.zk.ui.IdSpace |
---|
getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, hasFellow, hasFellow |
Methods inherited from interface org.zkoss.zk.ui.ext.Scope |
---|
addScopeListener, getAttribute, hasAttribute, removeAttribute, removeScopeListener, setAttribute |
Field Detail |
---|
static final int PAGE_SCOPE
getAttribute(String, int)
and related to denote
custom attributes shared by the same page.
It is also known as the page attributes.
It is the same as getAttributes(int)
.
static final int DESKTOP_SCOPE
getAttribute(String, int)
and related to denote
custom attributes shared by the same desktop.
It is also known as the desktop attributes.
It is the same as Desktop.getAttributes()
.
static final int SESSION_SCOPE
getAttribute(String, int)
and related to denote
custom attributes shared by the same session.
It is also known as the session attributes.
It is the same as Session.getAttributes()
.
static final int APPLICATION_SCOPE
getAttribute(String, int)
and related to denote
custom attributes shared by the whole application.
It is also known as the application attributes.
It is the same as WebApp.getAttributes()
.
static final int REQUEST_SCOPE
getAttribute(String, int)
and related to denote
custom attributes shared by the same request.
It is also known as the request attributes, or execution attributes.
It is the same as Execution.getAttributes()
.
Method Detail |
---|
java.lang.String getId()
Note: it returns null when
Initiator.doInit(org.zkoss.zk.ui.Page, java.util.Map
is called.
void setId(java.lang.String id)
Note: you can change the page's ID only in
Initiator.doInit(org.zkoss.zk.ui.Page, java.util.Map
or ExecutionInit.init(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.Execution)
.
Once the page is initialized (by PageCtrl.init(org.zkoss.zk.ui.sys.PageConfig)
),
calling this
method will cause an exception.
UiException
- if the page is initialized, i.e.,
PageCtrl.init(org.zkoss.zk.ui.sys.PageConfig)
is called.java.lang.String getUuid()
It is mainly used for communication between client and server and you rarely need to access it.
java.lang.String getTitle()
Default: "".
void setTitle(java.lang.String title)
java.lang.String getStyle()
void setStyle(java.lang.String style)
Note: Unlike setTitle(java.lang.String)
, you can change the style only in
the lifecycle of the loading page.
java.lang.String getRequestPath()
It is the same as the servlet path (javax.servlet.http.HttpServletRequest's getServletPath), if ZK is running at a servlet container.
Note: Desktop.getRequestPath()
returns the request path
that causes the desktop to create. And, there might be multiple
pages in the same desktop.
Execution.getContextPath()
,
Desktop.getRequestPath()
boolean isAlive()
PageCtrl.destroy()
Desktop getDesktop()
Note: it returns null when
Initiator.doInit(org.zkoss.zk.ui.Page, java.util.Map
is called.
java.util.Collection<Component> getRoots()
Component getFirstRoot()
Component getLastRoot()
java.util.Map<java.lang.String,java.lang.Object> getAttributes(int scope)
If scope is PAGE_SCOPE
, it means custom attributes shared
by components from the same page as this one's.
If scope is DESKTOP_SCOPE
, it means custom attributes shared
by components from the same desktopas this one's.
scope
- one of APPLICATION_SCOPE
, SESSION_SCOPE
,
PAGE_SCOPE
, REQUEST_SCOPE
or DESKTOP_SCOPE
.java.lang.Object getAttribute(java.lang.String name, int scope)
If scope is PAGE_SCOPE
, it means custom attributes shared
by components from the same page as this one's.
If scope is DESKTOP_SCOPE
, it means custom attributes shared
by components from the same desktopas this one's.
scope
- one of APPLICATION_SCOPE
, SESSION_SCOPE
,
PAGE_SCOPE
, REQUEST_SCOPE
or DESKTOP_SCOPE
.boolean hasAttribute(java.lang.String name, int scope)
Notice that null
is a valid value, so you need this
method to really know if an atribute is defined.
java.lang.Object setAttribute(java.lang.String name, java.lang.Object value, int scope)
If scope is PAGE_SCOPE
, it means custom attributes shared
by components from the same page as this one's.
If scope is DESKTOP_SCOPE
, it means custom attributes shared
by components from the same desktopas this one's.
scope
- one of APPLICATION_SCOPE
, SESSION_SCOPE
,
PAGE_SCOPE
, REQUEST_SCOPE
or DESKTOP_SCOPE
.java.lang.Object removeAttribute(java.lang.String name, int scope)
If scope is PAGE_SCOPE
, it means custom attributes shared
by components from the same page as this one's.
If scope is DESKTOP_SCOPE
, it means custom attributes shared
by components from the same desktopas this one's.
scope
- one of APPLICATION_SCOPE
, SESSION_SCOPE
,
PAGE_SCOPE
, REQUEST_SCOPE
or DESKTOP_SCOPE
.java.util.Map<java.lang.String,java.lang.Object> getAttributes()
getAttributes
in interface Scope
java.lang.Object getAttribute(java.lang.String name)
getAttribute
in interface Scope
boolean hasAttribute(java.lang.String name)
Notice that null
is a valid value, so you need this
method to really know if an atribute is defined.
hasAttribute
in interface Scope
java.lang.Object setAttribute(java.lang.String name, java.lang.Object value)
setAttribute
in interface Scope
value
- the value.
java.lang.Object removeAttribute(java.lang.String name)
removeAttribute
in interface Scope
java.lang.Object getAttributeOrFellow(java.lang.String name, boolean recurse)
Notice that this method will NOT check for any variable defined in
the variable resolver (addVariableResolver(org.zkoss.xel.VariableResolver)
).
You have to invoke getXelVariable(XelContext,Object,Object,boolean)
or getXelVariable(String)
manually.
recurse
- whether to look up the desktop/session for the
existence of the attribute.boolean hasAttributeOrFellow(java.lang.String name, boolean recurse)
Notice that this method will NOT check for any variable defined in
the variable resolver (addVariableResolver(org.zkoss.xel.VariableResolver)
).
You have to invoke getXelVariable(XelContext,Object,Object,boolean)
or getXelVariable(String)
manually.
recurse
- whether to look up the desktop/session for the
existence of the attribute.java.lang.Class<?> resolveClass(java.lang.String clsnm) throws java.lang.ClassNotFoundException
ClassResolver
(registered with
addClassResolver(org.zkoss.lang.ClassResolver)
). If not found, it looks at the current
thread's class loader. And then, it looks for classes defined
in any loaded interpreters (getLoadedInterpreters()
).
resolveClass
in interface ClassResolver
clsnm
- the class name. It does not have to be a fully qualified name
(i.e., it could have no package name), if the class is imported by
use of the import directive (such as <?import class="com.foo.*"?>).
java.lang.ClassNotFoundException
- if the class is not found.boolean addClassResolver(ClassResolver resolver)
resolver
- the class resolver to be added.
Currently it supports only ImportedClassResolver
.resolveClass(java.lang.String)
java.lang.Class<?> getZScriptClass(java.lang.String clsnm)
getLoadedInterpreters()
).
Note that: since ZK 6, this method will not search
the current thread's class loader.
In other words, you'd like to look for a class from a given page, use resolveClass(java.lang.String)
instead.
Also notice that it won't throw an exception if not found. Rather, it returns null.
clsnm
- the fully qualified class name. Unlike resolveClass(java.lang.String)
,
this method does not support the imported class (by addClassResolver(org.zkoss.lang.ClassResolver)
).
resolveClass(java.lang.String)
,
getLoadedInterpreters()
Function getZScriptFunction(java.lang.String name, java.lang.Class[] argTypes)
getLoadedInterpreters()
Function getZScriptFunction(Component comp, java.lang.String name, java.lang.Class[] argTypes)
comp
- the component to start the search. If null, this
method searches only the page's attributes.
In other words, if comp is null, this method is the same as
getZScriptFunction(String, Class[])
.java.lang.Object getZScriptVariable(java.lang.String name)
getLoadedInterpreters()
java.lang.Object getZScriptVariable(Component comp, java.lang.String name)
comp
- the component as the context to look for the variable
defined in an interpreter. If null, the context is assumed to
be this page.java.lang.Object getXelVariable(java.lang.String name)
getXelVariable(null, null, name, false)
.
This method is mainly used to access special variable, such as request parameters (if this page is requested by HTTP).
getXelVariable(XelContext, Object, Object, boolean)
java.lang.Object getXelVariable(XelContext ctx, java.lang.Object base, java.lang.Object name, boolean ignoreExec)
Unlike getXelVariable(String)
, this method
can utilitize VariableResolverX
if you'd like
to retrieve a property of another object.
ctx
- the XEL contextbase
- the base object. If null, it looks for a top-level variable.
If not null, it looks for a member of the base object (such as getter).name
- the property to retrieve.ignoreExec
- whether to ignore the current execution
(Execution.getVariableResolver()
.
If true, it invokes only the variable resolvers define in this page
(addVariableResolver(org.zkoss.xel.VariableResolver)
).
If false, it will first check the execution, so the implicit objects
such as page
and desktop
will be resolved.getXelVariable(String)
boolean addVariableResolver(VariableResolver resolver)
getXelVariable(java.lang.String)
.
The new added variable resolver has the higher priority.
Note: the variables resolver by the specified resolver are accessible to both zscript and EL expressions.
boolean removeVariableResolver(VariableResolver resolver)
addVariableResolver(org.zkoss.xel.VariableResolver)
.
boolean hasVariableResolver(VariableResolver resolver)
addVariableResolver(org.zkoss.xel.VariableResolver)
boolean addEventListener(java.lang.String evtnm, EventListener<? extends Event> listener)
Due to performance consideration, unlike Component.addEventListener(int, java.lang.String, org.zkoss.zk.ui.event.EventListener extends org.zkoss.zk.ui.event.Event>)
,
all event listeners for the page are deferrable, no matter
Deferrable
is implemented or not.
ZK 5.0 and earlier, the second registration is ignored if an event listener has been registered twice. However, since 6.0.0 and later, it won't be ignored. If a listener has been registered multiple times, it will be invoked multiple times.
If you prefer to ignore the second registration, you could specify a library property called "org.zkoss.zk.ui.EventListener.duplicateIgnored" to true.
evtnm
- what event to listen (never null)
Component.addEventListener(int, java.lang.String, org.zkoss.zk.ui.event.EventListener extends org.zkoss.zk.ui.event.Event>)
boolean removeEventListener(java.lang.String evtnm, EventListener<? extends Event> listener)
boolean isListenerAvailable(java.lang.String evtnm)
java.util.Iterator<EventListener<? extends Event>> getListenerIterator(java.lang.String evtnm)
getEventListeners(java.lang.String)
.
Returns an iterator for iterating the event listeners for the given event.
java.lang.Iterable<EventListener<? extends Event>> getEventListeners(java.lang.String evtnm)
Note: it is OK to invoke addEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener extends org.zkoss.zk.ui.event.Event>)
or removeEventListener(java.lang.String, org.zkoss.zk.ui.event.EventListener extends org.zkoss.zk.ui.event.Event>)
when iterating through the event listeners with the returned collection.
To remove an event listener from the returned iterable collection,
you could invoke Iterable.iterator()
's Iterator.remove()
.
void removeComponents()
Execution.createComponents(String,Component,Map)
void invalidate()
void interpret(java.lang.String zslang, java.lang.String script, Scope scope)
zslang
- the scripting language. If null, getZScriptLanguage()
is assumed.scope
- the scope used as the context.
Since a component is a scope, you can pass a component as the context.
By context we mean the attribute of the scope, its space owner,
spacer owner's space owner, page and desktop will be searched.
If null, this page is assumed.Interpreter getInterpreter(java.lang.String zslang)
The interpreter will be loaded and initialized, if it is not loaded yet.
zslang
- the scripting language. If null, getZScriptLanguage()
is assumed.
InterpreterNotFoundException
- if not found.java.util.Collection<Interpreter> getLoadedInterpreters()
java.lang.String getZScriptLanguage()
void setZScriptLanguage(java.lang.String zslang) throws InterpreterNotFoundException
InterpreterNotFoundException
- if no such languagejava.lang.Class<? extends ExpressionFactory> getExpressionFactoryClass()
Configuration.getExpressionFactoryClass()
is used.
Default: null.
setExpressionFactoryClass(java.lang.Class extends org.zkoss.xel.ExpressionFactory>)
void setExpressionFactoryClass(java.lang.Class<? extends ExpressionFactory> expfcls)
expfcls
- the class that implements
ExpressionFactory
,
If null, Configuration.getExpressionFactoryClass()
is used.getExpressionFactoryClass()
boolean isComplete()
It is meaningful only if it is the top-level page (i.e.,
not included by the include
component).
Default: false. It means ZK loader will enclose the page content with HTML/HEAD/BODY if necessary (such as not included by other Servlet).
If you have a page that has a complete HTML page and it is included by other page, you have to specify the complete flag to be true.
void setComplete(boolean complete)
Default: false. It means a page is complete if and only if it is not included by other page.
complete
- whether the page is complete.
If true, this page is assumed to be complete no matter it is included
or not. If false, this page is assumed to be complete if it is
not included by other page.isComplete()
FunctionMapper getFunctionMapper()
boolean addFunctionMapper(FunctionMapper mapper)
The new added function mapper has the higher priority.
getFunctionMapper()
will return the new
mapper
- the new function mapper (null to ignore).boolean removeFunctionMapper(FunctionMapper mapper)
addFunctionMapper(org.zkoss.xel.FunctionMapper)
.
boolean hasFunctionMapper(FunctionMapper mapper)
addFunctionMapper(org.zkoss.xel.FunctionMapper)
LanguageDefinition getLanguageDefinition()
ComponentDefinitionMap getComponentDefinitionMap()
Note: the map is shared among all instance of the same page definition.
Any component definition added (by ComponentDefinitionMap.add(org.zkoss.zk.ui.metainfo.ComponentDefinition)
)
are visible to all other instances of the same page definition.
Thus, it is NOT a good idea to change its content.
ComponentDefinition getComponentDefinition(java.lang.String name, boolean recurse)
Note: unlike LanguageDefinition.getComponentDefinition(java.lang.String)
,
this method doesn't throw ComponentNotFoundException if not found.
It just returns null.
recurse
- whether to look up the component from getLanguageDefinition()
ComponentDefinition getComponentDefinition(java.lang.Class<? extends Component> cls, boolean recurse)
Note: unlike LanguageDefinition.getComponentDefinition(java.lang.String)
,
this method doesn't throw ComponentNotFoundException if not found.
It just returns null.
recurse
- whether to look up the component from getLanguageDefinition()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |