hi, i mail to DWR,tell them i want to tring develop a DWR-jsf2(CDI) integration, and get the reply: ----------------------------------------------------- You can do this by creating a new DWR creator. The current JSF creator (JsfCreator) grabs the bean instance from the faces context. It should be straightforward to write a new JSF creator that grabs the CDI managed instance. It looks like you can use the BeanManager (http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html). ----------------------------------------------------- DWR have two developers, cant give me more help on CDI-integration. may be google can help me more .
thanks erveryone!!! At 2013-11-11 05:01:51,"Jason Porter" <[email protected]> wrote: >I've never used DWR either, but this would be my assumption as well. > >Sent from my iPhone > >> On Nov 10, 2013, at 12:14, Christian Kaltepoth <[email protected]> >> wrote: >> >> Hey, >> >> I think that @Inject doesn't work because DWR creates its own instance of >> your class and doesn't use the CDI managed one. You have basically two >> options here. >> >> Your first option is to tell DWR to use the CDI managed instance of you >> class instead of creating a new one. As I'm not familiar with DWR I cannot >> tell you how to do this. But there seems to be a Spring support module for >> DWR, so it should be possible to do something similar for CDI. >> >> Your second option is to use BeanProvider.injectFields(this) somewhere in >> your class. This way DeltaSpike will inject all dependencies into your >> object even if it has been created by DWR. >> >> I hope this helps >> >> Christian >> >> >> >> >> 2013/11/10 十三郎 <[email protected]> >> >>> hi,erveryone. >>> >>> in a DWR RemoteMethod,dwr cant get injected bean automatical. >>> like this: >>> -------------- >>> import javax.inject.Inject; >>> import javax.inject.Named; >>> import org.apache.deltaspike.core.api.provider.BeanProvider; >>> import org.directwebremoting.annotations.RemoteMethod; >>> import org.directwebremoting.annotations.RemoteProxy; >>> @Named("Test") >>> @RemoteProxy //for dwr >>> public class Test >>> { >>> @Inject private User user; >>> @RemoteMethod //for dwr >>> public String test(){ >>> //i find dwr cant get @Inject bean >>> System.out.println("user is null ? "+(user == null)); >>> >>> //fortunately , i can get it in a manual way. but i dont wanna >>> this way >>> user=BeanProvider.getContextualReference(User.class,false); >>> System.out.println("user name is: "+user.getUsername()); >>> return user.getUsername(); >>> } >>> } >>> >>> import java.io.Serializable; >>> import javax.enterprise.context.SessionScoped; >>> import javax.inject.Named; >>> @SessionScoped >>> @Named >>> public class User implements Serializable{ >>> private static final long serialVersionUID = -559381017984772756L; >>> private String username="wuhenge"; >>> public String getUsername(){ >>> return this.username; >>> } >>> public void setUsername(String s){ >>> this.username=s; >>> } >>> } >>> -------- >>> after run this demo,i find dwr can get inject bean in a manual way.but i >>> dont wanna this way >>> >>> i try to add deltaspike servlet module,but that didnt work. >>> >>> the edition of dwr is latest on >>> http://ci.directwebremoting.org/bamboo/browse/DWRTRUNK-ALL-521/artifact. >>> >>> thanks erveryone!!!! >> >> >> -- >> Christian Kaltepoth >> Blog: http://blog.kaltepoth.de/ >> Twitter: http://twitter.com/chkal >> GitHub: https://github.com/chkal
