0

Composer - disadvantages to using.

asked 2009-11-24 00:00:32 +0800

hexbox gravatar image hexbox
6 1

It appears to me that there are disadvantages to using Composer. What is your opinion? Would you use Composer in a design and, if so, when?

My understanding:

When a Composer is added to a page, all events are forwarded to the server. Yet, even unhandled events are forwarded to the server. And events that have a local handler are also forwarded to the server.

One can verify this behavior with the example code below.
Open the page in a browser, then click the client and server buttons. Next, disconnect the server from the client. Clicking either button results in a “The server is temporarily out of service.”

Why is this behavior a disadvantage? IMHO

1.
It pings the server without need, wasting time and bandwidth.

2.
In RIA, it is more efficient to handle many component events locally. It makes no sense to pass a simple text entry from client -> server -> client. This defeats the advantage of distributed computing.

3.
Using Composer does make a cleaner design by separating event handling from the view. Yet, it doesn’t seem to help with MVC separation. The Composer is tied to ZK and can’t be easily reused with a different view technology. It would be better to write a reusable, technology neutral, class. (?)

4.
In the case of intermittent network connectivity, customers would receive popup warnings that they wouldn’t receive if events were handled locally. It is something to consider when trying to create a robust high quality software product, i.e., fewer calls to the help desk = lower maintenance costs.


<example code>

<?page title="index.zul"?>
<zk >
<window apply="MyComposer" >
<button id="button1"
label="Client" onClick='label1.setValue("Client Script");'/>
<button id="button2" label="Server"/>
Event Output:<label id="label1"/>
</window>
</zk>


// MyComposer.java
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Label;
import org.zkoss.zul.Button;

public class MyComposer
extends GenericForwardComposer {
private Button button2;
private Label label1;
public void onClick$button2(Event event) {
label1.setValue("Server Java");
}
}

</code>

delete flag offensive retag edit

3 Replies

Sort by » oldest newest

answered 2009-11-24 17:04:39 +0800

robertpic71 gravatar image robertpic71
1275 1

1.)
There is mistake in your analysis:

Many "greenhorns" think: zscript (code inside the onClick=xxx is also zscript!) is executed on the client
That's wrong! zscript is interpreted on the server by the beanshell or another interpreter (i.e. groovy).

It's the same server-client traffic for composer and zscript. Because zscript is an interpreter it is slower
than compiled java and needs more memory.

2.) ZK is a server-centric (until ZK 5.0) framework for maximum development speed. This means:
You could follow the desktop-programming-model and there is no trouble to access i.e. a JDBC Resultset or Hibernate-Queries.
This works perfect for the most intranet-applications and should work for many internetapplications.

Your example is quite simple: An event is fired to change a fix value to another field. But 90% of my event's need serverinformation,
so there is a must for client-server-client.

Before ZK 5.0, you could include clientsite-code via the attribute action. But: welcome in the painfull world of javascript and Browser-DOM.

With ZK 5.0, Potix offers a Javascript-Client-API for client-side-action. The cross-compile from java to javascript (via GWT) is on the roadmap.
The way is: Do the most code server-centric to maximize the output, speedup some client-side-action - if there is a need.

3.) MVC
First, there is no must to follow the MVC-Pattern.

It is MVC-conform that the controller knows the GUI. In fact, it's always hard to reuse a controller (you could also check Swing MVC applications). The most important point is, that the model doesn't know anything about the view and controll and is full reusable. I know that some people use ZK with zscript without controller to and use their old models.

However MVC is always an issue of dispute.

>> It would be better to write a reusable, technology neutral, class.
You could also use an interface for the composer (i.e. AfterCompose) instead of extend.

4.)
>> receive popup warnings that they wouldn’t receive if events
You could override the timeout box with some own (i.e. own text, own code). However if the session is dead, i prefer "quick" info until the user fills an the formular and the save-button fails.
If you need more offline-functionality the ZK5 Client-API could be a choice for you. But it's a lot more code to offer full client-functionality and merge the data. It could be simple i.e. for
a single notepad and heavy for data with concurrent changes.

I use ZK with the server-centric-approach and 0,2% clientcode (i.e. for mouseover action) and no troubles so far.

/Robert

link publish delete flag offensive edit

answered 2009-11-25 07:30:56 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-11-25 07:31:12 +0800

I agree 100% with Robert.

The discussion of a MVC is along as it exists. I have contacts to e few consulting firms. And in NO case i have heared that a changing of the
view technology of bigger business web apps does NOT need to write the controllers new. In our case ZK is a component and event based
framework. I think these view controllers can only used with zk.

Therefore you have the big advantage to write the whole application from frontend to backend with the same language JAVA. That's great.

best
Stephan

link publish delete flag offensive edit

answered 2009-11-25 21:11:17 +0800

reycat67 gravatar image reycat67
30 1

Good Day Everyone!

Is there a way of disabling the popup message "The server is temporarily out of service. Please try again later." and use variable (or local event) instead to determine the availability of the server?

Thanks for any reply.

Rey

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-11-24 00:00:32 +0800

Seen: 1,465 times

Last updated: Nov 25 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More