-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I started to intgrate Java EE 6 CDI/Weld with ZK Richlet. I have seen the new CDI support in zkplus and the thread in Weld Forum started by Henri. Are there plans to support dependency injection also for ZK richlet - like CDI works with Servlets?
Goal should be to get context/scope related business beans injected in richlets or ZK Components.
I started some coding for ZK Scopes:
public abstract class AbstractZkContext<T> implements Context { @Override public abstract Class getScope(); public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) { Bean bean = (Bean) contextual; Map viewMap = getViewMap(); if (viewMap.containsKey(bean.getName())) { return (T) viewMap.get(bean.getName()); } else { T t = (T) bean.create(creationalContext); viewMap.put(bean.getName(), t); return t; } } protected abstract Map getViewMap(); public <T> T get(Contextual<T> contextual) { Bean bean = (Bean) contextual; Map viewMap = getViewMap(); if (viewMap.containsKey(bean.getName())) { return (T) viewMap.get(bean.getName()); } else { return null; } } @Override public boolean isActive() { return true; } }
Where e.g. ZK Dektop context looks like:
public class ZkDesktopContext<T> extends AbstractZkContext<T>{ @Override public Class getScope() { return ZkDesktopScope.class; } @Override protected Map getViewMap() { return Executions.getCurrent().getDesktop().getAttributes(); } }
And the desktop scope:
@Target(value = {METHOD, TYPE, FIELD}) @Retention(value = RUNTIME) @NormalScope @Inherited public @interface ZkDesktopScope { }
As a first aproach. I tried to get this working with glassfish but my Extension class is not triggered from container lifecycle events (something to ask for in Weld forum).
Since lifecycle of ZK Richlet is controled from DHtmlLayoutServelet->UiEngineImpl dependency injection does not happen. I tried some things described in Weld portable extension docs, but no successful injections so far. Anybody here who has already worked with ZK Richlet and Weld?
Weld looks very promising and easy to use. Would be nice to get full integration with ZK!
Yes. We have successfully implemented(experimented) ZK scopes (Desktop, Page, IdSpace, Component, Execution) as CDI scopes. Also tried make ZK components as CDI managed beans in a controller POJO class(still with some limitations).
I wonder what kind of use cases you would like Richlet to be integrated with CDI? I mean how you will use CDI and expect what kind of "convenience" provided along? Can you give us an "imagined" example? Thanks.
That sounds good! So i will stop my activities and wait for your implementation.
I want to renew my CMS application with some new backend technologies (JPA, EJB...).
In the past i instantiate a desktop control in my richlets service routine:
public void service(final Page page) { try { DesktopControl dc = new DesktopControl(); } catch (final Exception e) { // This should never happen! LOG.error("Unhandeled Error in DesktopControl: " + e.getMessage(), e); createErrorPage(page, e); // TODO store Errors for Reporting } }
In my case DesktopControl will be the root bean for all Desktop related beans in my application. All i need for now is to get a DektopControl instance managed by Weld. I'm almost shure this is already possible and easy to do with weld, but didn't manage to get it working until now. I have to read more weld specs ;). The next step would be to use the new ZK weld skopes... looking forward to your implementation. When will it be available for first testing?
/thomas
Asked: 2010-01-28 03:39:08 +0800
Seen: 942 times
Last updated: Jan 29 '10