-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
Stephan
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.
Stephan
>> 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.
/Robert
Some examplecode (a variant of Simon's MVC Smalltalk - big thanks)
ZUL-File:
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window id="win" title="To do list" width="640px" border="normal" apply="${toDoControllerV3}">
The controller/composer:
@Repository("toDoControllerV3")
@Scope("prototype")
public class ZkToDoControllerV3 extends GenericForwardComposer {
...
@Autowired
protected ReminderService reminderService; // inject services, Perstenceclasses ...
..
spring-context.xml, partial (autoscan for annotated repositories)
<context:component-scan base-package="org.zkforge.zktodo2"/>
/Robert
@robertpic,
@ziccardi,
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.
txs
Stephan
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 :
Hi,
When execute the application, in tomcat, the indicate the following errors
1. WARNING: Unable to find file (ignored): jndi:/localhost/ZkTodo2/
java.io.FileNotFoundException
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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
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>
<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>
</property>
</bean>
<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>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven />
<!--
Injected properties
-->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/jdbc.properties</value>
</list>
</property>
</bean>
</beans>
@afigueroa
hi. it seems that you have in your configuration file two different bean-ids with identical classes.
Please correct this.
</bean> <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'
regards
Stephan
How would you make a properly view-controller as MVC real pattern requires??? Could you post a solution for this please?
Regards,
IS
> 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
你们的留言也解决了我的疑惑.. thank you
Asked: 2008-11-19 09:23:00 +0800
Seen: 5,776 times
Last updated: Jan 18 '11