Difference between use="" and apply=""

asked 2008-11-19 09:23:00 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16

updated 2008-11-19 09:26:27 +0800

Hiho all,

i'm heavily learning ZK. Most time it makes fun. At time i'm figthing with the implementation from my spring/hibernate backend (services/dao/model) from an other project.

Can someonye explain me (in easy words, i.e. with example) what is the difference between use="" and apply="". At time i have problems to access my spring controlled beans in a .zul file.
Sometimes i have only access to methods by using the use="org.myfirm.sampleapp.Class". But with the full qualified packagename it goes around spring, i mean.

Thanks for everybody

delete flag offensive retag edit

20 Replies

Sort by » oldest newest

answered 2011-01-18 00:03:14 +0800

fudan gravatar image fudan

你们的留言也解决了我的疑惑.. thank you

link publish delete flag offensive edit

answered 2010-04-22 15:41:59 +0800

robertpic71 gravatar image robertpic71
1275 1

> I would like to ask if using use="" atribute for classname means that I won't be able to handle object, EL and springinjection in the rest of the zul file?
EL's work for the complete zul-file and of course spring if the variable-resolver is spring.

<windows use="com.at.yourclass"/>
yourclass --> is not under springcontroll, no springinjection inside yourclass - no effect for the rest of the zul file.

<windows apply="${yourclass}"/>
yourlcass --> is under spring controll, springinjection etc. works inside yourclass

link publish delete flag offensive edit

answered 2010-04-22 09:58:36 +0800

is gravatar image is

updated 2010-04-22 10:00:06 +0800

How would you make a properly view-controller as MVC real pattern requires??? Could you post a solution for this please?

link publish delete flag offensive edit

answered 2008-12-15 13:28:11 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16

updated 2008-12-15 13:30:50 +0800


hi. it seems that you have in your configuration file two different bean-ids with identical classes.
Please correct this.

  <bean id="reminderService" class="org.zkforge.zktodo2.ReminderService" p:basicDao-ref="basicDao"/>
  <bean id="reminder" class="org.zkforge.zktodo2.ReminderService" p:basicDao-ref="basicDao" />

Look at the error text. It will save an entity object called 'Reminder'


link publish delete flag offensive edit

answered 2008-12-14 18:08:06 +0800

afigueroa gravatar image afigueroa

Hi, TerryTornado, I am implementing MVC (Spring + hibernate + DAO + Service + ZK). What i am using as a template is http://www.zkoss.org/smalltalks/mvc4/. But my problem is on the Spring Configuration. When i running the application it tell me that :


When execute the application, in tomcat, the indicate the following errors

1. WARNING: Unable to find file (ignored): jndi:/localhost/ZkTodo2/

When i try to execute : entityManager.persist(entity);
2.java.lang.IllegalArgumentException: Unknown entity: org.zkforge.zktodo2.Reminder

include the spring configuration.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<bean id="basicDao" class="org.zkforge.zktodo2.BasicDao" />

<bean id="toDoControllerV2" class="org.zkforge.zktodo2.ZkToDoControllerV2" p:toDoModel-ref="ZkToDoModel" scope="prototype"> </bean>

<bean id="ZkToDoModel" class="org.zkforge.zktodo2.ZkToDoModelImpl" p:reminderService-ref="reminder" scope="session">
// scoped proxy is commented out as only referenced by a prototype bean
// if you wanted to pass this bean to a singleton you need to include
// the following configurration.
<aop:scoped-proxy proxy-target-class="false"/>

<bean id="reminderService" class="org.zkforge.zktodo2.ReminderService" p:basicDao-ref="basicDao" />

<bean id="reminder" class="org.zkforge.zktodo2.ReminderService" p:basicDao-ref="basicDao" />

JPA config
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" p:persistence-xml-location="/META-INF/persistence.xml">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"></property>
<property name="generateDdl" value="true"></property>
<property name="database" value="MYSQL"></property>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>

<tx:annotation-driven />

Injected properties
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">


link publish delete flag offensive edit

answered 2008-11-21 12:45:31 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16


txs for the answers.

Good to know that the use="" must be an full qualified string for the classname and no spring annotation.

At time i totally lost my red line. Doesn't know to de-wire my classes.


link publish delete flag offensive edit

answered 2008-11-21 07:42:07 +0800

ziccardi gravatar image ziccardi
321 7

I agree with Robert.

If you still can't solve your problem, it would be useful if you would post the full ClassCastException stacktrace.

link publish delete flag offensive edit

answered 2008-11-20 20:52:19 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2008-11-20 20:53:31 +0800

Some examplecode (a variant of Simon's MVC Smalltalk - big thanks)

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window id="win" title="To do list" width="640px" border="normal" apply="${toDoControllerV3}">

The controller/composer:


public class ZkToDoControllerV3 extends GenericForwardComposer {
protected ReminderService reminderService; // inject services, Perstenceclasses ...
spring-context.xml, partial (autoscan for annotated repositories)
<context:component-scan base-package="org.zkforge.zktodo2"/>


link publish delete flag offensive edit

answered 2008-11-20 20:41:27 +0800

robertpic71 gravatar image robertpic71
1275 1

>> Difference between use="" and apply=""

>> There is standing use=${kundeListBean}

There is big difference between use and apply: use only accept a classname via String.
Only the apply attribute can handle object, EL and springinjection!

With use you could not inject the controller/gui-element itself. You can get springresources into the GUI-element using the autowired-util and the spring-resolver. But the variablename has to match the
springresourcename - no annotations.

The composer could injected by spring. So you have the full power of Spring inside the composer - including annotations.

I go the use-way until now, because the @binder expect his models in the GUI-Element. Since there is a way to handle the models inside composer - i switch to the composer.


link publish delete flag offensive edit

answered 2008-11-20 16:44:55 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16

updated 2008-11-20 16:48:37 +0800

Hi ziccardi,

yes, the VariableResolver is there.

this error comes when the .zul - file is loaded. There is standing use=${kundeListBean}. I called at no line the casting. This must be done by spring.

I have no error when writing the full qualified package name like use="org.myfirm.bean.KundeListBean" . But this is not correct when using spring managed beans. The error comes than later at an other place.

I don't know what happens. I have now cleared the web.xml/zk-xml so there is nothing additionally.


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




Asked: 2008-11-19 09:23:00 +0800

Seen: 5,759 times

Last updated: Jan 18 '11

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