0

I want to inject JSF beans using Spring annotations.

I want my app to use JSF components and also Primefaces (on frontend). But also, on backend I want to have repositories, services and managed beans and to be able to inject a @Repository into a @Servive, and also a @Service into a bean @Named and @ViewScoped.

For example:

Persistence layer:

public interface UserRepository {
  List<User> getAllUsers();
}

@Repository
public class UserRepositoryImpl implements UserRepository{

    @Override
    public List<User> getAllUsers() {
        return entityManager.createQuery("select u from User u").getResultList();
    }
}

Business layer:

public interface UserService {
    List<User> getAllUsers();
}

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserRepository userRepository;

    @Override
    public List<User> getAllUsers() {
        return userRepository.getAllUsers();
    }
}

Presentation layer:

@Named
@ViewScoped
public class UserManagement{

    @Autowired
    protected UserService userService;
    protected List<User> users;

    public List<User> getUsers() {
        if(users.isEmpty()) {
            users = userService.getAllUsers();
        }
        return users;
    }

    public void setUsers(List<User> users) {
        this.users= users;
    }
}

And, as view let say I have an xhtml with jsf components. For example, I have a dataTable in which I'll store all users.

I was reading this post but it is not that clear.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nelly Junior
  • 556
  • 2
  • 10
  • 30

0 Answers0