Use Piggyback"

From Documentation
m (remove empty version history (via JWB))
 
(6 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
Sometimes there is no hurry to update the result to a client. Rather, the UI update could be sent back when the user, say, clicks a button or triggers some request to the server. This technique is called ''piggyback''.
 
Sometimes there is no hurry to update the result to a client. Rather, the UI update could be sent back when the user, say, clicks a button or triggers some request to the server. This technique is called ''piggyback''.
  
In piggyback, all you need to do is to register an event listener for the <tt>onPiggyback</tt> event to one of the root components. Then, the listener will be invoked each time ZK Update Engine has processed an AU request.
+
In piggyback, all you need to do is to register an event listener for the <code>onPiggyback</code> event to one of the '''root components'''. Then, the listener will be invoked each time ZK Update Engine has processed an AU request.
  
For example, suppose we have a long operation which is processed in a working thread, then:
+
For example, suppose we have a long operation that is processed in a working thread, then:
  
<source lang="xml" high="1">
+
<source lang="xml" highlight="1">
 
<window id="main" title="Working Thread" onPiggyback="checkResult()">
 
<window id="main" title="Working Thread" onPiggyback="checkResult()">
 
     <zscript>
 
     <zscript>
Line 27: Line 27:
 
</source>
 
</source>
  
The advantage of the piggyback is no extra traffic between the client and the server. However, the user sees no updates if he doesn't have any activity, such as clicking. Whether it is proper is really up to the application requirements.
+
The advantage of the piggyback is no extra traffic between the client and the server. However, the user sees no updates if they don't have any activity, such as clicking. Whether it is proper is really up to the application requirements.
  
 
<blockquote>
 
<blockquote>
 
----
 
----
'''Note''': A deferrable event won't be sent to the client immediately, so the <tt>onPiggyback</tt> event is triggered only if a non-deferrable event is fired. For more information, please refer to the [[ZK_Developer's_Reference/Event_Handling/Event_Listening#Deferrable_Event_Listeners|Deferrable Event Listeners]] section.
+
'''Note''': A deferrable event won't be sent to the client immediately, so the <code>onPiggyback</code> event is triggered only if a non-deferrable event is fired. For more information, please refer to the [[ZK_Developer's_Reference/Event_Handling/Event_Listening#Deferrable_Event_Listeners|Deferrable Event Listeners]] section.
 
</blockquote>
 
</blockquote>
  
=Version History=
+
 
{{LastUpdated}}
 
{| border='1px' | width="100%"
 
! Version !! Date !! Content
 
|-
 
| &nbsp;
 
| &nbsp;
 
| &nbsp;
 
|}
 
  
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 05:54, 6 February 2024

Sometimes there is no hurry to update the result to a client. Rather, the UI update could be sent back when the user, say, clicks a button or triggers some request to the server. This technique is called piggyback.

In piggyback, all you need to do is to register an event listener for the onPiggyback event to one of the root components. Then, the listener will be invoked each time ZK Update Engine has processed an AU request.

For example, suppose we have a long operation that is processed in a working thread, then:

<window id="main" title="Working Thread" onPiggyback="checkResult()">
    <zscript>
     List result = Collections.synchronizedList(new LinkedList());
 
     void checkResult() {
         while (!result.isEmpty())
             main.appendChild(result.remove(0));
     }
    </zscript>
    <timer id="timer" />
    <button label="Start Working Thread">
        <attribute name="onClick">
     		timer.start();
     		new test.WorkingThread(desktop, result).start();
        </attribute>
    </button>
</window>

The advantage of the piggyback is no extra traffic between the client and the server. However, the user sees no updates if they don't have any activity, such as clicking. Whether it is proper is really up to the application requirements.


Note: A deferrable event won't be sent to the client immediately, so the onPiggyback event is triggered only if a non-deferrable event is fired. For more information, please refer to the Deferrable Event Listeners section.




Last Update : 2024/02/06

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