0

Please Help me !! ZK Best Practice

asked 2012-10-05 11:11:42 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi

I have some questions on Best programming methods using ZK. We are currently working on
one of our existing Project. The project is developed using ZK 5 and MVC Pattern. More than 60 % of
the work is completed by other team. Now we have taken over and continuing the development.
Here are the high level project details.

1. Even though it is developed using ZK 5, but we successfully updated to latest ZK 6 Version.
2. Hibernate is the ORM and we are also using spring.
3. All the master screens are opened in Model window and they have not attached controller for each.
Instead of that, they have bind directly with the Object returned by Hibernate.
4. Almost in all ZUL Files, they have used Zscript tag and contains java code to handle business
requirements.
5. All most all the onclick event contains attribute tag and written the java code.

6. This project will be hosted in the cloud where we can have multiple clients,
users under each clients, etc

I have attached a sample of master file here.

Here are my question.

1. In all the ZK Documents, ZK Team does not recommend the use of ZScript tag. They have this tag
only for POC and prototype work. In this situation, our project contains lot of ZScript tag and
contains java code inside. So what is the impact in the production environment.

2. I am new to Java Based web tech. To my knowledge, nowdays all the tech are taking about
code separation from the UI Presentation layer. But we have java code in the Presentation.
So what is the impact of this ?

3. And also, all the ZUL Files fields are directly binded to the Java POJO Object returned by
Hibernate. One of my friend told that, this will slow down the application, because hibernate
will still hold the session reference in the UI Layer also. He recommend to detach or take
a copy of the object and use that in the UI Layer.
Is that true ? What is the best practice to handle this.

 <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./addModifierWin"?>
<?component name="enumeration" class="com.ecosmos.view.component.EnumerationDropdown"?>
<zk>
	<zscript><![CDATA[
	import com.ecosmos.util.UtilValidator;
	import com.ecosmos.service.common.CommonCrudService;
	;
	import com.ecosmos.util.Infrastructure;
	import com.ecosmos.domain.pms.Modifier;
	Map arguments = Executions.getCurrent().getArg();
	Modifier modifier = UtilValidator.isEmpty(arg) ? new Modifier()
			: (Modifier) arguments.get("entity");
]]></zscript>
	<window mode="modal" title=" " width="60%" border="normal" minimizable="false" maximizable="false"  
		position="center" closable="true" id="addModifierWin">
		<separator />
		<flabeltitle value="Modifier" />
		<separator />
		<panel width="100%" >
			<panelchildren>
				<separator />
				<fgrid width="99.5%">
					<columns>
						<column label="" width="100px" />
						<column label="" />
					</columns>
					<rows>
						<row>
							<hbox>
								<flabel value="Code" />
								<flblreq value="*" />
							</hbox>
							<ftextbox id="txtcode" name="txtcode"
								value="@{modifier.code,save-when='Save.onClick'}"
								constraint="no empty" />
						</row>
						<row>
							<hbox>
								<flabel value="Description" />
							</hbox>
							<ftextbox id="txtdescription"
								value="@{modifier.description,save-when='Save.onClick'}"
								constraint="no empty" />
						</row>
						<row>
							<flabel value="Comments" />
							<ftextbox id="txtcomments"
								value="@{modifier.comments,save-when='Save.onClick'}" rows="4"
								cols="90" />
						</row>
					</rows>
				</fgrid>
			</panelchildren>
		</panel>
		<separator />
		<div align="center">
			<fbutton id="Save" label="Submit">
				<attribute name="onClick">
			<![CDATA[
	try {
		commonCrudService.save(modifier);
		com.ecosmos.util.UtilMessagesAndPopups.showSuccess();
		addModifierWin.detach();
	} catch (org.springframework.dao.DataIntegrityViolationException e) {
		if (e.getCause() != null
				&& e.getCause() instanceof org.hibernate.exception.ConstraintViolationException) {
			int code = org.hibernate.exception.JDBCExceptionHelper
					.extractErrorCode(((org.hibernate.exception.ConstraintViolationException) (e
							.getCause())).getSQLException());
			if (1062 == code) {
				com.ecosmos.util.UtilMessagesAndPopups.showError("Modifier '"
						+ modifier.getCode() + "' already exists.");
			}
		}
	}
]]>
			</attribute>
			</fbutton>
			<fbutton id="cancel" label="Cancel">
				<attribute name="onClick">
				addModifierWin.detach();
				
				</attribute>
				</fbutton>
		</div>
	</window>
</zk>

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2012-10-05 21:06:40 +0800

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

updated 2012-10-05 23:13:19 +0800

Hi Senthilchettyin,

first i have read here and in a few other threads the term 'Model Window' ??? What is a Model Window. ? Does you mean modal window ?

1. ZScript is the possibility to script Java code in zul files. Means you can run Java code on server side without extra writting a java controller.
ZK use the BSH BeanShell interpreter. I personally coding faster with my java controllers than with zscript. Second with java i have the full Eclipse features for type safety and code completion.
ZScript is in MAJOR used to allow making samples that others can easy comprehend by copying and running without loading a few classes.
So these script code must be interpreted, it runs slower than pre-compiled java code controller classes.
Normally scripting is used to make an application customizable. I.e. in well defined places in a application logic like beforeSave(), beforeDelete(), calculateSomething() you can load script code from a database and let them run.
So in my opinion it's better to spend some time in basic java controllers and use these for all of your modules.

2. More than separation does not go!
Means in my opinion that 'something' must be 'between' the ui and the backend. ZUL is not alone the view! you can create the same in java code or in an other language or framework like Vaadin (runs only with java) Technical designs like MVC or MVVM are different but runs both.
In fact: i do not know somebody who has changed a frontend technique without must having written the frontend controllers new !!!!!
If you work with dynamic created components with i.e Listeners ui and controller mixed up more.
So in my eyes it's the same to have zul + Zscript or zul + java controller as long as there is a clear separation to the backend. But for performance and type safety coding it's better to do this without ZScript.

3. Hmmmm, If i look at such an error like the lazy loading .... session is closed.
Means that after a call/action from hibernate it closes the session. For every new query to the database hibernate gets a new Hibernate Session from the SessionManager. I do not work with 'openSessionInView' so i mean that there should be nothing referenced after a call.
If you will drive a rocket fast application than you must code this without any ORM. But it's more comfortable to code it with it. :-)

best
Stephan

link publish delete flag offensive edit

answered 2012-10-06 08:00:08 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Thank you Stephan

Yes it is modal window.

And also, You recommend to use Java controllers.

Java Controllers are not nothing but java class extend GenericForwardComposer utility class and attach in the window using apply ?

am i right ?

link publish delete flag offensive edit

answered 2012-10-07 17:26:39 +0800

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

updated 2012-10-07 20:39:12 +0800

Yes and No.

No: Not all java controllers are extend GenericForwardComposer. You can use the controller/composer which you need or write your own composer. GenericForwardComposer have all in (forwarding and autowireing).
Yes: Yes the controllers should be in Java language and NOT in Zscript.

Use vs. apply:
This is the comment from an other thread

The use, means you want to reimplement the component.
For example, if you write:

<window use="myWinClass">
</window>
Then, when the zul component 'window' of this page is created, an instance of myWinClass will be created instead of a Window.
Obviously, myWinClass should extend Window.

If you use the 'apply', you are just linking a Composer to your component.
In my opinion, you'll need a Composer instead of the 'use' in the 99% of the cases.


You self have add a comment to this smalltalk that shows a bit of the history of the composers. Each of this composers have added new features for handling autowireing or forwarding of events easier. The last 'all in' state in zk5 was the GenericForwardComposer.


In the last years there comes new composers with the several zk versions.
GenericSpringComposer (deprecated since zkspring 3.0+)
SelectorComposer, BindComposer (zk 6+)

In zk6 the GenericForwardComposer work too and can be changed to SelectorComposer for the guys who loves many Annotations in their code.
For working with the new MVVM databinding you need the BindComposer.

--> MVC = GenericForwardComposer ( zk5 / zk6 ).
--> MVC = SelectorComposer ( zk6 ).
--> MVVM = BindComposer ( zk6 )

I hope i have reproduced it right. :-)

Interesting threads: thread; thread;


best
Stephan

PS:

6. This project will be hosted in the cloud where we can have multiple clients, 
users under each clients, etc

For this point perhaps we can work together, interchange code, written new or finish/modify some of our SaaS Infrastructure.
mail: zk(at)forsthaus(dot)de

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: 2012-10-05 11:11:42 +0800

Seen: 221 times

Last updated: Oct 07 '12

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