deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Porter <lightguard...@gmail.com>
Subject Re: how to make DWR and CDI work together ?
Date Sun, 10 Nov 2013 21:01:51 GMT
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 <christian@kaltepoth.de> 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 εδΈ‰ιƒŽ <mihaisheng@163.com>
> 
>> 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

Mime
View raw message