0

How to inject ZK components as Spring beans?

asked 2008-06-12 15:41:42 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5026619

By: sdswamy10

At the end of the recent MVC small talk, Henri mentioned that ZK components can now be injected as spring beans.
For example: <bean id="myWindow" class="com.mycompany.myapp.MyWindow"/>. However, this does not seem to be working with ZK 3.0.5. I am wondering whether this is a new feature in 3.0.6 or 3.1.0, or am I not configuring it correctly. I get a Java classcastexception when I try this with 3.0.5

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2008-06-13 00:46:53 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5027793

By: robbiecheng

Would you like to post your example code, and the full stacktrace?

thx!

/robbie

link publish delete flag offensive edit

answered 2008-06-13 17:43:57 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5029797

By: sdswamy10

Here is an example sourcecode:

applicationContext.xml
----------------------------------------------------------------
<bean id="myDao" class="com.mycompany.myapp.dao.impl.MyDaoImpl">
<constructor-arg ref="jdbcMySQLTemplate"></constructor-arg>
</bean>
<bean id="myWindow" class="com.mycompany.myapp.web.window.MyWindow">
<constructor-arg ref="myDao"></constructor-arg>
</bean>

MyWindow.java
-----------------------------------------
public class MyWindow extends Window{

public MyWindow(MyDao _myDao){
myDao = _myDao;
}

}

index.zul
--------------------------------------------
<?variable-resolver
class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window use="${myWindow}">
Hello ZK
</window>

Here is the error message that I get:
java.lang.ClassCastException: com.mycompany.myapp.web.window.MyWindow cannot be cast to java.lang.String
org.zkoss.zk.ui.metainfo.ComponentInfo.newInstance(ComponentInfo.java:474)
org.zkoss.zk.ui.impl.AbstractUiFactory.newComponent(AbstractUiFactory.java:90)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:519)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:501)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:461)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:444)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:528)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:501)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:461)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:444)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:528)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:501)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:461)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:444)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:341)
org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:276)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:227)
org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:167)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



link publish delete flag offensive edit

answered 2008-06-13 23:22:12 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5030277

By: robertpic71

Henri wrote:
>> With EL expression on apply-attribute... <<

Your controller should be a Composer (extend GenericComposer instead of Window) and use the apply-attribute.

/Robert

link publish delete flag offensive edit

answered 2008-06-14 10:32:26 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5031070

By: henrichen

Looks I shall write an article regarding this :)

/henri

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: 2008-06-12 15:41:42 +0800

Seen: 181 times

Last updated: Jun 14 '08

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