Class UiEngineImpl
- java.lang.Object
-
- org.zkoss.zk.ui.impl.UiEngineImpl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceUiEngineImpl.ExtensionAn interface used to extend the UI engine.
-
Constructor Summary
Constructors Constructor Description UiEngineImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate(Execution exec)Activates an execution such that you can access a component.booleanactivate(Execution exec, int timeout)Activates an execution such that you can access a component.voidaddInvalidate(Component comp)Invalidates a component to cause redrawing.voidaddInvalidate(Page page)Invalidates the page to cause all of its components to redraw.voidaddMoved(Component comp, Component oldparent, Page oldpg, Page newpg)Called to update (redraw) a component, when a component is moved.voidaddResponse(java.lang.String key, AuResponse response)Adds a response which will be sent to client at the end of the execution.voidaddResponse(java.lang.String key, AuResponse response, int priority)Adds a response with the given priority.voidaddResponse(AuResponse response)Adds a response directly by usingAuResponse.getOverrideKey()as the override key.voidaddSmartUpdate(Component comp, java.lang.String attr, java.lang.Object value, boolean append)Smart-updates a property of the peer widget.voidaddSmartUpdate(Component comp, java.lang.String attr, java.lang.Object value, int priority)Adds a smart update that will be executed at the given priority.voidaddUuidChanged(Component comp)Called before changing the component's UUID.protected voidafterRenderComponents(java.util.Collection<Component> comps)Called when this engine renders the given components.voidbeginUpdate(Execution exec)Activates and prepare for asynchronous updatebooleanceaseSuspendedThread(Desktop desktop, EventProcessingThread evtthd, java.lang.String cause)Ceases the specified event thread.voidclearSmartUpdate(Component comp)Clears all existing smart updates that belong to the given component.voidcloseUpdate(java.lang.Object ctx)Deactivates the execution and cleans up.Component[]createComponents(Execution exec, PageDefinition pagedef, Page page, Component parent, Component insertBefore, org.zkoss.xel.VariableResolver resolver, java.util.Map<?,?> arg)Creates components from the specified page and definition.voiddeactivate(Execution exec)Deactivates an execution, such that other threads could activate and access components.voiddesktopDestroyed(Desktop desktop)Called when a desktop is being removed.booleandisableClientUpdate(Component comp, boolean disable)Sets whether to disable the update of the client widget.voidendUpdate(Execution exec)Executes posted events, deactivate and ends the asynchronous update.voidexecNewPage(Execution exec, PageDefinition pagedef, Page page, java.io.Writer out)Creates components specified in the given page definition.voidexecNewPage(Execution exec, Richlet richlet, Page page, java.io.Writer out)InvokeRichlet.service(org.zkoss.zk.ui.Page), when a new page is creates upon visiting a richlet.voidexecRecover(Execution exec, FailoverManager failover)Executes the recovering.voidexecUpdate(Execution exec, java.util.List<AuRequest> requests, AuWriter out)Executes an asynchronous update to a component (or page).org.zkoss.json.JSONArrayfinishUpdate(java.lang.Object ctx)Finishes the update and returns the result in an array of JSON object.org.zkoss.json.JSONArrayfinishUpdate(java.lang.Object ctx, java.util.List<java.lang.Throwable> errs)Finishes the update and returns the result in an array of JSON object.java.lang.StringgetNativeContent(Component comp, java.util.List<NodeInfo> children, Native.Helper helper)Retrieve the native content for a property of the specified component.java.util.Collection<EventProcessingThread>getSuspendedThreads(Desktop desktop)Returns a collection of suspended event processing threads belonging to the specified desktop, or empty if no suspended thread at all.booleanhasSuspendedThread()Returns if any suspended event processing thread in the whole system.booleanisInvalidated(Component comp)Returns if this component needs to be redrawn.voidnotify(java.lang.Object mutex)Wakes up a single event processing thread that is waiting on the specified object.voidnotify(Desktop desktop, java.lang.Object mutex)Wakes up a single event processing thread for the specified desktop that is waiting on the specified object.voidnotifyAll(java.lang.Object mutex)Wakes up all event processing thread that are waiting on the specified object.voidnotifyAll(Desktop desktop, java.lang.Object mutex)Wakes up all event processing threads for the specified desktop that are waiting on the specified object.voidrecycleDesktop(Execution exec, Page page, java.io.Writer out)Reuse the desktop and generate the output.voidsendRedirect(java.lang.String uri, java.lang.String target)Sends a temporary redirect response to the client using the specified redirect location URL.voidsetAbortingReason(AbortingReason aborting)Aborts the current execution.ComponentsetOwner(Component comp)Called before a component redraws itself if the component might include another page.voidstart(WebApp wapp)Starts the engine.java.lang.ObjectstartUpdate(Execution exec)Activates an execution that will allow developers to update the state of components.voidstop(WebApp wapp)Stops the engine.voidwait(java.lang.Object mutex)Suspends the current processing of an event and wait until the other thread invokesUiEngine.notify(Object),UiEngine.notifyAll(Object),UiEngine.notify(Desktop, Object)orUiEngine.notifyAll(Desktop, Object)for the specified object.
-
-
-
Method Detail
-
start
public void start(WebApp wapp)
Description copied from interface:UiEngineStarts the engine.
-
stop
public void stop(WebApp wapp)
Description copied from interface:UiEngineStops the engine. Called only if the server is about to stop.
-
hasSuspendedThread
public boolean hasSuspendedThread()
Description copied from interface:UiEngineReturns if any suspended event processing thread in the whole system.- Specified by:
hasSuspendedThreadin interfaceUiEngine
-
getSuspendedThreads
public java.util.Collection<EventProcessingThread> getSuspendedThreads(Desktop desktop)
Description copied from interface:UiEngineReturns a collection of suspended event processing threads belonging to the specified desktop, or empty if no suspended thread at all.An event processing thread is an instance of
EventProcessingThread- Specified by:
getSuspendedThreadsin interfaceUiEngine- Parameters:
desktop- the desktop that the suspended event processing threads belong to (never null).
-
ceaseSuspendedThread
public boolean ceaseSuspendedThread(Desktop desktop, EventProcessingThread evtthd, java.lang.String cause)
Description copied from interface:UiEngineCeases the specified event thread.- Specified by:
ceaseSuspendedThreadin interfaceUiEngine- Parameters:
desktop- which desktop the event thread belongs tocause- an arbitrary text to describe the cause. It will be the message of the thrown InterruptedException.- Returns:
- true if the event processing thread is ceased successfully; false if no such thread or it is not suspended.
-
desktopDestroyed
public void desktopDestroyed(Desktop desktop)
Description copied from interface:UiEngineCalled when a desktop is being removed.Application developers don't need to remove pages and desktops. They are removed and cleaned up automatically.
- Specified by:
desktopDestroyedin interfaceUiEngine
-
setOwner
public Component setOwner(Component comp)
Description copied from interface:UiEngineCalled before a component redraws itself if the component might include another page.If a new page is created, the specified component will become the owner of the new page.
It must reset the owner in the finally clause.
old = ue.setOwner(this); try{ ... } finally { ue.setOwner(old); }Since 5.0.6, the owner must implement
Includer.
-
isInvalidated
public boolean isInvalidated(Component comp)
Description copied from interface:UiEngineReturns if this component needs to be redrawn.Note:
- It always returns true if the current execution is not an asynchronous update.
- If its parent is invalidated, this component will be redrawn
too, but this method returns false since
UiEngine.addInvalidate(Component)was not called against this component.
- Specified by:
isInvalidatedin interfaceUiEngine
-
addInvalidate
public void addInvalidate(Page page)
Description copied from interface:UiEngineInvalidates the page to cause all of its components to redraw.- Specified by:
addInvalidatein interfaceUiEngine
-
addInvalidate
public void addInvalidate(Component comp)
Description copied from interface:UiEngineInvalidates a component to cause redrawing. Called whenComponent.invalidate()is called.- Specified by:
addInvalidatein interfaceUiEngine
-
addSmartUpdate
public void addSmartUpdate(Component comp, java.lang.String attr, java.lang.Object value, boolean append)
Description copied from interface:UiEngineSmart-updates a property of the peer widget.- Specified by:
addSmartUpdatein interfaceUiEngineappend- whether to append the updates of properties with the same name. If false, only the last value of the same property will be sent to the client.
-
addSmartUpdate
public void addSmartUpdate(Component comp, java.lang.String attr, java.lang.Object value, int priority)
Description copied from interface:UiEngineAdds a smart update that will be executed at the given priority. The higher priority, the earlier the update is executed. IfUiEngine.addSmartUpdate(Component, String, Object, boolean)is invoked, the priority is assumed to 0.If the priority is the same, the update is executed in the order of first-in-first out. You rarely need to control the sequence, unless the update is used to instantiate client-side widgets that other updates might depend on. In this case, it is suggested to specify the priority as 10000 (and not to use priority higher than 10000 for other situation).
- Specified by:
addSmartUpdatein interfaceUiEngine
-
clearSmartUpdate
public void clearSmartUpdate(Component comp)
Description copied from interface:UiEngineClears all existing smart updates that belong to the given component.- Specified by:
clearSmartUpdatein interfaceUiEngine
-
addResponse
public void addResponse(AuResponse response)
Description copied from interface:UiEngineAdds a response directly by usingAuResponse.getOverrideKey()as the override key. In other words, it is the same asaddResponse(resposne.getOverrideKey(), response)If the response is component-dependent,
AuResponse.getDepends()must return a component. And, if the component is removed, the response is removed, too.- Specified by:
addResponsein interfaceUiEngine- See Also:
UiEngine.addResponse(String, AuResponse)
-
addResponse
public void addResponse(java.lang.String key, AuResponse response)Description copied from interface:UiEngineAdds a response which will be sent to client at the end of the execution. Called byAbstractComponent.response(org.zkoss.zk.au.AuResponse).Note:
Execution.addAuResponse(org.zkoss.zk.au.AuResponse)is a shortcut to this method, and it is used by application developers.If
AuResponse.getDepends()is not null, the response depends on the returned component. In other words, the response is removed if the component is removed. If it is null, the response is component-independent.- Specified by:
addResponsein interfaceUiEngine- Parameters:
key- could be anything. If null, the response is appended. If not null, the second invocation of this method in the same execution with the same key and the same depends (AuResponse.getDepends()) will override the previous one.- See Also:
UiEngine.addResponse(AuResponse)
-
addResponse
public void addResponse(java.lang.String key, AuResponse response, int priority)Description copied from interface:UiEngineAdds a response with the given priority. The higher priority, the earlier the update is executed. The priority ofUiEngine.addResponse(String, AuResponse)andUiEngine.addResponse(AuResponse)is assumed to be 0.If the priority is the same, the update is executed in the order of first-in-first out.
- Specified by:
addResponsein interfaceUiEngine
-
addMoved
public void addMoved(Component comp, Component oldparent, Page oldpg, Page newpg)
Description copied from interface:UiEngineCalled to update (redraw) a component, when a component is moved. If a component's page or parent is changed, this method need to be called only once for the top one.
-
addUuidChanged
public void addUuidChanged(Component comp)
Description copied from interface:UiEngineCalled before changing the component's UUID.- Specified by:
addUuidChangedin interfaceUiEngine
-
disableClientUpdate
public boolean disableClientUpdate(Component comp, boolean disable)
Description copied from interface:UiEngineSets whether to disable the update of the client widget. By default, if a component is attached to a page, modifications that change the visual representation will be sent to the client to ensure the consistency.- Specified by:
disableClientUpdatein interfaceUiEngine- Returns:
- whether it has been disabled before this invocation, i.e., the previous disable status
-
execNewPage
public void execNewPage(Execution exec, Richlet richlet, Page page, java.io.Writer out) throws java.io.IOException
Description copied from interface:UiEngineInvokeRichlet.service(org.zkoss.zk.ui.Page), when a new page is creates upon visiting a richlet.- Specified by:
execNewPagein interfaceUiEngine- Throws:
java.io.IOException
-
execNewPage
public void execNewPage(Execution exec, PageDefinition pagedef, Page page, java.io.Writer out) throws java.io.IOException
Description copied from interface:UiEngineCreates components specified in the given page definition. Called when a new page is creates.- Specified by:
execNewPagein interfaceUiEngine- Throws:
java.io.IOException
-
recycleDesktop
public void recycleDesktop(Execution exec, Page page, java.io.Writer out) throws java.io.IOException
Description copied from interface:UiEngineReuse the desktop and generate the output.- Specified by:
recycleDesktopin interfaceUiEngine- Throws:
java.io.IOException
-
afterRenderComponents
protected void afterRenderComponents(java.util.Collection<Component> comps)
Called when this engine renders the given components.- Parameters:
comps- the collection of components that have been redrawn.
-
createComponents
public Component[] createComponents(Execution exec, PageDefinition pagedef, Page page, Component parent, Component insertBefore, org.zkoss.xel.VariableResolver resolver, java.util.Map<?,?> arg)
Description copied from interface:UiEngineCreates components from the specified page and definition. It can be called whenUiEngine.execNewPage(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.metainfo.PageDefinition, org.zkoss.zk.ui.Page, java.io.Writer)orUiEngine.execUpdate(org.zkoss.zk.ui.Execution, java.util.List<org.zkoss.zk.au.AuRequest>, org.zkoss.zk.au.AuWriter)was called. It assumes the execution is already locked to this desktop.Note: if both page and parent are null, the created components don't belong to any page/parent.
- Specified by:
createComponentsin interfaceUiEngine- Parameters:
exec- the execution (never null).pagedef- the page definition (never null).page- the page. Ignored if parent is specified and parent's page is not null (parent's page will be used). If both page and parent are null, the created components won't belong to any page.parent- the parent component, or null if no parent component. If parent is specified, page is ignored.insertBefore- the sibling component that new components will be inserted before. Ignored if null (i.e., append as last children).resolver- the variable resolver used to resolve variables. Ignored if null.arg- a map of parameters that is accessible by the arg variable in EL, or byExecution.getArg(). Ignored if null.- Returns:
- the components being created.
-
sendRedirect
public void sendRedirect(java.lang.String uri, java.lang.String target)Description copied from interface:UiEngineSends a temporary redirect response to the client using the specified redirect location URL.After calling this method, the caller shall end the processing immediately (by returning). All pending requests and events will be dropped.
- Specified by:
sendRedirectin interfaceUiEngine- Parameters:
uri- the URI to redirect to, or null to reload the same pagetarget- the new target, or null to denote the same browser window
-
setAbortingReason
public void setAbortingReason(AbortingReason aborting)
Description copied from interface:UiEngineAborts the current execution. if not null, it means the current execution is abortingNote: if setAbortingReason is ever set with non-null, you CANNOT set it back to null.
After call this method, you shall not keep processing the page because the rendering is dropped and the client is out-of-sync with the server.
- Specified by:
setAbortingReasonin interfaceUiEngine- Parameters:
aborting- the aborting reason.
-
execRecover
public void execRecover(Execution exec, FailoverManager failover)
Description copied from interface:UiEngineExecutes the recovering.- Specified by:
execRecoverin interfaceUiEngine
-
beginUpdate
public void beginUpdate(Execution exec)
Description copied from interface:UiEngineActivates and prepare for asynchronous update- Specified by:
beginUpdatein interfaceUiEngine
-
endUpdate
public void endUpdate(Execution exec) throws java.io.IOException
Description copied from interface:UiEngineExecutes posted events, deactivate and ends the asynchronous update.
-
execUpdate
public void execUpdate(Execution exec, java.util.List<AuRequest> requests, AuWriter out) throws java.io.IOException
Description copied from interface:UiEngineExecutes an asynchronous update to a component (or page). It is the same as execUpdate(exec, requests, null, out).Note: the output must be XML and UTF-8.
- Specified by:
execUpdatein interfaceUiEnginerequests- a list ofAuRequest.- Throws:
java.io.IOException
-
startUpdate
public java.lang.Object startUpdate(Execution exec) throws java.io.IOException
Description copied from interface:UiEngineActivates an execution that will allow developers to update the state of components.It is designed to implement
Bridge.- Specified by:
startUpdatein interfaceUiEngine- Returns:
- a context that shall be passed to
UiEngine.finishUpdate(java.lang.Object). - Throws:
java.io.IOException- See Also:
UiEngine.finishUpdate(java.lang.Object),UiEngine.closeUpdate(java.lang.Object)
-
finishUpdate
public org.zkoss.json.JSONArray finishUpdate(java.lang.Object ctx) throws java.io.IOExceptionDescription copied from interface:UiEngineFinishes the update and returns the result in an array of JSON object. Notice it does not deactivate the execution. Rather, the caller has to invokeUiEngine.closeUpdate(java.lang.Object).It is designed to implement
Bridge.- Specified by:
finishUpdatein interfaceUiEngine- Parameters:
ctx- the context returned by the previous call toUiEngine.startUpdate(org.zkoss.zk.ui.Execution)- Throws:
java.io.IOException- See Also:
UiEngine.startUpdate(org.zkoss.zk.ui.Execution),UiEngine.closeUpdate(java.lang.Object)
-
finishUpdate
public org.zkoss.json.JSONArray finishUpdate(java.lang.Object ctx, java.util.List<java.lang.Throwable> errs) throws java.io.IOExceptionDescription copied from interface:UiEngineFinishes the update and returns the result in an array of JSON object. Notice it does not deactivate the execution. Rather, the caller has to invokeUiEngine.closeUpdate(java.lang.Object).It is designed to implement
Bridge.- Specified by:
finishUpdatein interfaceUiEngine- Parameters:
ctx- the context returned by the previous call toUiEngine.startUpdate(org.zkoss.zk.ui.Execution)errs- the collection of errors if any.- Throws:
java.io.IOException- See Also:
UiEngine.finishUpdate(Object)
-
closeUpdate
public void closeUpdate(java.lang.Object ctx) throws java.io.IOExceptionDescription copied from interface:UiEngineDeactivates the execution and cleans up.It is designed to implement
Bridge.- Specified by:
closeUpdatein interfaceUiEngine- Throws:
java.io.IOException- See Also:
UiEngine.startUpdate(org.zkoss.zk.ui.Execution),UiEngine.finishUpdate(java.lang.Object)
-
wait
public void wait(java.lang.Object mutex) throws java.lang.InterruptedException, SuspendNotAllowedExceptionDescription copied from interface:UiEngineSuspends the current processing of an event and wait until the other thread invokesUiEngine.notify(Object),UiEngine.notifyAll(Object),UiEngine.notify(Desktop, Object)orUiEngine.notifyAll(Desktop, Object)for the specified object.It can only be called when the current thread is processing an event. And, when called, the current processing is suspended and ZK continues to process the next event and finally render the result.
It is typical use to implement a modal dialog where it won't return until the modal dialog ends.
- Specified by:
waitin interfaceUiEngine- Parameters:
mutex- any non-null object to identify what to wait, such thatUiEngine.notify(Object)andUiEngine.notify(Desktop, Object)knows which object to notify.- Throws:
SuspendNotAllowedException- if there are too many suspended exceptions. Deployers can control the maximal allowed number of suspended exceptions by specifyingmax-suspended-threadinzk.xml, or invokingConfiguration.setMaxSuspendedThreads(int).java.lang.InterruptedException
-
notify
public void notify(java.lang.Object mutex)
Description copied from interface:UiEngineWakes up a single event processing thread that is waiting on the specified object.Unlike
UiEngine.notify(Desktop, Object), this method can be invoked only if the same desktop is locked for processing requests.- Specified by:
notifyin interfaceUiEngine- Parameters:
mutex- any non-null object to identify what to notify. It must be same object passed toUiEngine.wait(java.lang.Object).- See Also:
UiEngine.notify(Desktop, Object),UiEngine.notifyAll(Object)
-
notify
public void notify(Desktop desktop, java.lang.Object mutex)
Description copied from interface:UiEngineWakes up a single event processing thread for the specified desktop that is waiting on the specified object.Unlike
UiEngine.notify(Object), this method can be called any time. It is designed to let working threads resume an event processing thread.Notice: if this method is NOT called in an event processing thread, the resumed thread won't execute until the next request is received. To enforce it happen, you might use the timer component (found in ZUL).
- Specified by:
notifyin interfaceUiEngine- Parameters:
desktop- the desktop which the suspended thread is processing. It must be the same desktop of the suspended thread.mutex- any non-null object to identify what to notify. It must be same object passed toUiEngine.wait(java.lang.Object).- See Also:
UiEngine.notify(Object),UiEngine.notifyAll(Desktop, Object)
-
notifyAll
public void notifyAll(java.lang.Object mutex)
Description copied from interface:UiEngineWakes up all event processing thread that are waiting on the specified object.Unlike
UiEngine.notify(Desktop, Object), this method can be invoked only if the same desktop is locked for processing requests.- Specified by:
notifyAllin interfaceUiEngine- Parameters:
mutex- any non-null object to identify what to notify. It must be same object passed toUiEngine.wait(java.lang.Object).- See Also:
UiEngine.notify(Desktop, Object),UiEngine.notifyAll(Object)
-
notifyAll
public void notifyAll(Desktop desktop, java.lang.Object mutex)
Description copied from interface:UiEngineWakes up all event processing threads for the specified desktop that are waiting on the specified object.Unlike
UiEngine.notifyAll(Object), this method can be called any time. It is designed to let working threads resume an event processing thread.If this method is NOT called in an event processing thread, the resumed thread won't execute until the next request is received. To enforce it happen, you might use the timer component (found in ZUL).
- Specified by:
notifyAllin interfaceUiEngine- Parameters:
desktop- the desktop which the suspended thread is processing. It must be the same desktop of the suspended thread.mutex- any non-null object to identify what to notify. It must be same object passed toUiEngine.wait(java.lang.Object).- See Also:
UiEngine.notify(Object),UiEngine.notifyAll(Desktop, Object)
-
activate
public void activate(Execution exec)
Description copied from interface:UiEngineActivates an execution such that you can access a component. You must callUiEngine.deactivate(org.zkoss.zk.ui.Execution)in the finally clause.Note: you RARELY need to invoke this method because
UiEngine.execNewPage(org.zkoss.zk.ui.Execution, org.zkoss.zk.ui.metainfo.PageDefinition, org.zkoss.zk.ui.Page, java.io.Writer)andUiEngine.execUpdate(org.zkoss.zk.ui.Execution, java.util.List<org.zkoss.zk.au.AuRequest>, org.zkoss.zk.au.AuWriter)will activate and deactivate automatically.Note: this method can be called only when processing a client request (e.g., HTTP) other than creating a new page and processing async-update.
Also, even if you use this method to grant the right to access components of the specified page, don't post events, create, remove, invalidate and do any smart updates. In other words, READ ONLY.
-
activate
public boolean activate(Execution exec, int timeout)
Description copied from interface:UiEngineActivates an execution such that you can access a component. UnlikeUiEngine.activate(Execution), you could specify an amount of time (timeout), and it returns false if it takes longer than the given amount of time before granted.
-
deactivate
public void deactivate(Execution exec)
Description copied from interface:UiEngineDeactivates an execution, such that other threads could activate and access components.- Specified by:
deactivatein interfaceUiEngine
-
getNativeContent
public java.lang.String getNativeContent(Component comp, java.util.List<NodeInfo> children, Native.Helper helper)
Description copied from interface:UiEngineRetrieve the native content for a property of the specified component. The native content is a value of a property that is represented by a XML fragment (actuallyNativeInfo).Example:
<html> <attribute name="content"> <br/> </attribute> </html>- Specified by:
getNativeContentin interfaceUiEngine- Parameters:
comp- the component that the native content will be assigned to. It is the object that the self variable is assigned when evaluating EL expressions.children- a list ofNativeInfo,TextInfoand others. This method evaluates them one-by-one and returns the result which is the value that will be assigned.helper- the helper used to generate the content.- See Also:
Property
-
-