Second try with Gwt, Errai and CDI ...fail again...
n3k0 Nov 6, 2011 8:50 AMHi again.
In my free time, i decided to modify my example application, and give it an view like a tradicional
MVC application, i modified like this:
Config file:
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.6//EN" "http://google-web-toolkit.googlecode.com/svn/releases/1.6/distro-source/core/src/gwt-module.dtd"> <module rename-to='Login'> <inherits name="com.google.gwt.user.User"/> <inherits name="com.google.web.bindery.event.Event"/> <inherits name="com.google.gwt.user.theme.standard.Standard"/> <inherits name="org.jboss.errai.bus.ErraiBus"/> <inherits name="org.jboss.errai.ioc.Container"/> <inherits name="org.jboss.errai.enterprise.CDI"/> </module>
View (in client side):
package com.service.errai.login.client.local;
import javax.annotation.PostConstruct;
import javax.enterprise.inject.Typed;
import javax.inject.Inject;
import org.jboss.errai.bus.client.api.RemoteCallback;
import org.jboss.errai.bus.client.api.base.MessageBuilder;
import com.google.gwt.user.client.Window;
import com.service.errai.login.client.shared.TheRemoteService;
import org.jboss.errai.bus.client.framework.ClientMessageBus;
import org.jboss.errai.bus.client.framework.MessageBus;
import org.jboss.errai.ioc.client.api.EntryPoint;
@EntryPoint
public class Login {
private MessageBus bus;
@Inject
public Login(MessageBus bus) {
this.setBus(bus);
}
@PostConstruct
public void onModuleLoad(){
((ClientMessageBus) bus).addPostInitTask(new Runnable() {
public void run() {
MessageBuilder.createCall(new RemoteCallback<Boolean>() {
public void callback(Boolean isHappy) {
if (isHappy) Window.alert("Everyone is happy!");
}
}, TheRemoteService.class).isEveryoneHappy();
}
});
}
public MessageBus getBus() {
return bus;
}
public void setBus(MessageBus bus) {
this.bus = bus;
}
}
Control (shared folder, client and server can make references in this interface):
package com.service.errai.login.client.shared;
import org.jboss.errai.bus.server.annotations.Remote;
@Remote
public interface TheRemoteService {
public boolean isEveryoneHappy();
}
Control (implementation in server side):
package com.service.errai.login.server;
import javax.inject.Inject;
import org.jboss.errai.bus.client.framework.MessageBus;
import org.jboss.errai.bus.server.annotations.Service;
import com.service.errai.login.client.shared.TheRemoteService;
import com.service.errai.login.server.dao.TheDao;
@Service
public class TheRemoteServiceImpl implements TheRemoteService {
private MessageBus bus;
@Inject //THIS IS THE NEW REFERENCE
private TheDao theDao; //TO A DAO
@Inject
public TheRemoteServiceImpl( MessageBus bus ){
this.setBus(bus);
}
public boolean isEveryoneHappy() {
return theDao.isEveryoneHappy();//THIS IS A METHOD THAT USE THE DAO
}
public MessageBus getBus() {
return bus;
}
public void setBus(MessageBus bus) {
this.bus = bus;
}
public TheDao getTheDao() {
return theDao;
}
public void setTheDao(TheDao theDao) {
this.theDao = theDao;
}
}
Model (interface in server side):
package com.service.errai.login.server.dao;
public interface TheDao {
public boolean isEveryoneHappy();
}
Model (implementation in server side):
package com.service.errai.login.server.dao.impl;
import javax.inject.Inject;
import org.jboss.errai.bus.client.framework.MessageBus;
import com.service.errai.login.server.dao.TheDao;
public class TheDaoImpl implements TheDao {
private MessageBus bus;
@Inject
public TheDaoImpl( MessageBus bus ){
this.setBus(bus);
}
@Override
public boolean isEveryoneHappy() {
return true;
}
public MessageBus getBus() {
return bus;
}
public void setBus(MessageBus bus) {
this.bus = bus;
}
}
I have a beans.xml in WEB-INF folder with no content.
When i deploy my application, this exception appears:
1)No implementation for com.service.errai.login.server.dao.TheDao was bound. while locating com.service.errai.login.server.dao.TheDao for field at com.service.errai.login.server.TheRemoteServiceImpl.theDao(TheRemoteServiceImpl.java:47) while locating com.service.errai.login.server.TheRemoteServiceImpl
Well, i read some articles about CDI, and (like the examples in errai) it's enough to
add an @Inject annotation in the constructor/setter/field desired to get the default implementation
of a service (it's no neccesary the @Default annotation when you just have one implementation
of a service, in this case TheDao interface)
Could someone give me some guidance to make this works?
I tested adding the annotations @Default, @Named @Typed ...a but non of these works neither.
Thanks in advance.