0

Website examples + code

asked 2012-07-03 15:04:38 +0800

myZKBG gravatar image myZKBG
87

Hello,

I'm completly new to ZK framework and i want to start making a website with it, but to be honest, I fail already there.
I've looked through the component example collection (zk sandbox) provided by ZK. There were also some layout examples, but which one do I use when?

E.g. I want to create following layout: http://img62.imageshack.us/img62/434/examplejj.png

Which way of creating a layout should I use?
I'm coming from HTML websites, so my first thought was about vertical-layout-component and adding like 3 HTML-divs under it. That would be an appropriate way in HTML, but not in ZK, is it?
It could be also a borderlayout with north and middle containment, but for the menu I have to use divs again.

Is it normal (like sandbox index.zul) to mix up ZK components with html?
Should I define little popup windows (like login layer) in a separate zul file or create it in my composer with java code?
Would you split e.g. my index page in separat zul-files? Like an composer for the menu and one for the content? (would this even be possible to access from the menu composer the content element, when it has it's own composer?)

Refering to the title: You/ZK has provided many examples on every component, but it's lacking a bit about starting with a website, or did I miss some sites?

If I want to load all the content via Ajax requests, so that I have only one site my security check instead of in every component header (which way would you prefer?), do I have to start my project in a different way?

So many questions, but it's a bit hard to begin for me, so sorry for that!

Thanks in advance,

myZKBG

delete flag offensive retag edit

12 Replies

Sort by ยป oldest newest

answered 2012-07-03 20:28:12 +0800

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

updated 2012-07-03 20:29:20 +0800

Hi myZKBG and welcome.

As a hint: You can stick together several borderlayouts to your needs.

As an inspiration look here.

best
Stephan

link publish delete flag offensive edit

answered 2012-07-05 09:58:58 +0800

myZKBG gravatar image myZKBG
87

Hey terrytornado,

thanks for the welcome and especially for your example. I've downloaded

Another question of mine: Is there something like a global scope for the Composers?
I will try to explain it a little bit more in detail, because I'm not really sure, if it's a "ZK problem" or in general with Java WebApps.

I'm coming from PHP (regarding websites) and started with regular Java Desktop Apps without frameworks a while ago.
Starting with ZK and trying to use Spring Beans, I thought about how do you combines this with different .zul-Files and different composern.

Let's say I have 5 DAOs and 2 Controller handling these DAOs. To create these beans in combination with data source access, I want to use Spring.
Trying to encapsulate every component with an own .zul and composer, how do I access these beans from every composer?
Normally you use AppContext.getBeans only once when starting the application, don't you? But I can't define all composers as a bean in order to get the controllers inside of the composers defined. So instead of calling getBeans only once, I would have to create an AppContext and call "getBeans" it in every composer, wouldn't I?

If I design my page completly with ajax requests, your approach of a HashMap transfering the indexController object to it's "child" objects, looks like a good idea, but calling getBeans() for the controllers is still needed.

Is there somewhere a mistake in the explaination?
How to handle this ZUl - Composer - Controller - DAO reasonable?

Thanks in advance! :)

best regards.
myZKBG

link publish delete flag offensive edit

answered 2012-07-05 12:19:52 +0800

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

updated 2012-07-05 12:33:16 +0800

I work in two ways.

1. Dependency Injection from spring for 'normal' copmposers with their zul's.

applicationContext-DAO.xml

. . .
	<bean id="myDAO" class="org.myfirm.myapp.dao.impl.MyDAOImpl" scope="singleton" ></bean>
. . .

applicationContext-GUI.xml

. . .
	<bean id="myCustomerController" class="org.myfirm.myapp.web.customer.CustomerMainCtrl" scope="prototype" >
		<property name="myDAO" ref="myDAO" ></property>
</bean>
. . .


myCustomer.zul

. . .
<window  apply="${myCustomerController}" . . .
. . .

Composer

public class CustomerMainCtrl extends GenericForwardComposer {
   . . .
   private MyDAO myDAO;   
   . . .
   // your stuff here
   . . .
  // getter/setter
	public MyDAO getMyDAO() {
		return myDAO ;
	}
}


2. getting the DAO bean with SpringUtil for pure servlets. Means GUI's that are created completely in java.
Most of my SearchAndSelect Dialogs work with SpringUtil.

Therefore the zk guys have written a small util class. SpringUtil.java

you can get every spring bean with the following code:

MyDAO md = (MyDAO) org.zkoss.spring.SpringUtil.getBean("myDAO");


applicationContext-DAO.xml

. . .
	<bean id="myDAO" class="org.myfirm.myapp.dao.impl.MyDAOImpl" scope="singleton" ></bean>
. . .

applicationContext-GUI.xml

. . .
	<bean id="myCustomerController" class="org.myfirm.myapp.web.customer.CustomerMainCtrl" scope="prototype" ></bean>
. . .


myCustomer.zul

. . .
<window  apply="${myCustomerController}" . . .
. . .

Composer

public class CustomerMainCtrl extends GenericForwardComposer {
   . . .
   private MyDAO myDAO;   
   . . .
   // your stuff here
   . . .

  // getter/setter
	public MyDAO getMyDAO() {
		if (myDAO  == null) {
			myDAO = (MyDAO) SpringUtil.getBean("myDAO");
		}

		return myDAO ;
	}
}


best
Stephan

PS: have a look on the Zksample2 documentation too.

link publish delete flag offensive edit

answered 2012-07-06 12:25:07 +0800

myZKBG gravatar image myZKBG
87

Hey,

thank you really much! Your example files in zkSample and your short introduction here helped me really much!
For everybody else who is still asking, how to do this with maven:

1) ZK maven project is already defined
2) add Spring dependencies: org.springframework.spring-webmvc < This should include nearly everything is needed: http://books.zkoss.org/wiki/ZK%20Developer%27s%20Reference/Integration/Spring#Copy_Spring_binaries_into_your_Web_library
Do steps "Configure web.xml" and "Create Spring Configuration File" of Spring-integration page.
4) create Zul-File & apply controller like mentioned from TerryTornado. Add Variable Resolver from Spring!!!!!

That should be it.

@TerryTornado / anybody:
>Here< I read, that you should use this way, which you explained and works for me. I only used zkoss & spring web mvc dependencies, so currently no ZK Spring dependencies. Should I install ZK Spring? Do I have to change something afterwards like ContextloaderListener -> CoreContextListener, or are there just other scopes avaiable and I should use scope="component" instead of prototype?

Perhaps another question: I just skimed through the explaination of an MVVM approach, so perhaps my question is silly and not useful, but anyway:
Would it be possible to use this dependency injection also in MVVM approach? Can I still use the {bean} notation ?
Something like:

viewModel="@id('vm') @init('{bean}')">

This is nonsense because bean would have already bean initiated, but I hope you know what I mean.
I got this question by asking myself, which composer you should use in which case, so if you have a link for that too, I would really appreciate that!

best regards,
myZKBG

link publish delete flag offensive edit

answered 2012-07-06 14:34:48 +0800

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

updated 2012-07-06 14:37:52 +0800

You don't need the zk spring util. I only show two ways for working with spring beans.

springUtil is written for an easier working with spring in a non Dependency Injection way.

To your link: A spring developer will say NO! Spring have to manage the application and not the application manage spring.
In case of zk it's a bit more complicate because zk is AJAX. Means there are many request beside the 'normal' request for an address.
Such multithreaded things are not spring best friends, so that's the reason for such helpers like synchronizing the threadlocal between spring and zk.

For the MVVM question i hope that others can answer, beacuse i don't use it.

best
Stephan

link publish delete flag offensive edit

answered 2012-07-10 08:47:18 +0800

myZKBG gravatar image myZKBG
87

Thanks again terrytornado,

i didn't mean "Spring Utils" but "ZK Spring" (the addon from zkoss), aber anyway, it worked now in a good way.
Your second way with SpringUtils should also be the solution for MVVM, so on @Init(), call it and fill in your beans manually - that should work fine.

Perhaps my last question: In your example, you don't use "SelectorComposer". What's the reason to you to use only GenericForwardComposers? Does SelectorComposer have anything disadvantages (for you)?

best regards
myZKBG

link publish delete flag offensive edit

answered 2012-07-10 08:53:51 +0800

myZKBG gravatar image myZKBG
87

Hey,

because I can't edit my post due to a small textarea window which isn't scrollable, I had to produce this new entry:

During my tests in Tomcat, I always get the info:

org.zkoss.zkex.init.WebAppInit init:-1
Problem: This is an evaluation copy of ZK EE and will terminate after sixty days from the first date of installation. Should you require an open source license or commercial license for ZK EE please contact us at [email protected] for more information. Alternatively you can download ZK CE which is licensed under the LGPL.

I used the ZK EE before, but I removed the 2 jar-files zkex and .. don't know the other one anymore to get back to CE, like another topic here sugggested. Did I miss something?

Thanks in advance!

best regards
myZKBG

link publish delete flag offensive edit

answered 2012-07-10 13:24:13 +0800

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

'only GenericComposers' That's not 'only', that's a great evolution in the zk history of composers. :-)

I like it and it fit absolute my needs. I prefer the clean java coding way where i can work with more complicated UIs. That's all.

A comparison is at the end of the smalltalk in this link.
http://books.zkoss.org/wiki/Small%20Talks/2011/December/MVVM%20in%20ZK6:in%20Contrast%20to%20MVC

best
Stephan

link publish delete flag offensive edit

answered 2012-07-11 11:08:14 +0800

myZKBG gravatar image myZKBG
87

Hey,

no no, not "GenericComposers" but GenericForwardComposers :). Because you "only" used GFComposers in zksample2 and no SelectorComposers. That's what I meant :)

Regarding your example: In your webapp/index.zul, your window & borderlayout have height: 100%;
If you only do a small example:

<zk>
<borderlayout>
<north>Test></north>
<center>Center</center>
<south>South</south>
</borderlayout>
</zk>

Why doesn't it work without height specification? height="100%" like your index.zul doesn't work either?!

And last question:
Is it possible if I have <div id="myDiv"> to access #myDiv in Css?

Thanks in advance!

Best regards,
myZKBG

link publish delete flag offensive edit

answered 2012-07-11 22:12:17 +0800

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

Please make a new thread for the 'height' question

thanks.

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-07-03 15:04:38 +0800

Seen: 523 times

Last updated: Jul 13 '12

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