Проблема с инъекцией JSF 2, поэтому приложение не будет развернуто на сервере Glassfish - PullRequest
0 голосов
/ 02 июня 2019

Я внедряю List<Reception> в класс ReceptionService, но все, что я получаю, это ошибка, и проект не будет развернут: Ошибка, которую я получаю:

Unsatisfied dependencies for type List<Reception> with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject com.github.adminfaces.starter.service.ReceptionService.selectedPatients
  at com.github.adminfaces.starter.service.ReceptionService.selectedPatients(ReceptionService.java:0)

Я установил bean-discovery-mode="all" к beans.xml уже

Класс PatientList, где List<Reception> selectedPatients имеет свои методы получения и установки

import com.github.adminfaces.starter.model.Reception;
import com.github.adminfaces.starter.service.ReceptionService;
import org.omnifaces.cdi.ViewScoped;

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

@Named
@ViewScoped
public class PatientListMB implements Serializable {


    @Inject
    ReceptionService receptionService;

    Integer id;

    LazyDataModel<Reception> patients;

    Filter<Reception> filter = new Filter<>(new Reception());

    List<Reception> selectedPatients; //patients selected in checkbox column

    List<Reception> filteredValue;// datatable filteredValue attribute (column filters)

Класс ReceptionService, в который я делаю инъекцию List<Reception> selectedPatients

package com.github.adminfaces.starter.service;

import com.github.adminfaces.starter.infra.model.Filter;
import com.github.adminfaces.starter.infra.model.SortOrder;
import com.github.adminfaces.starter.model.Reception;
import com.github.adminfaces.template.exception.BusinessException;

import javax.ejb.Stateless;
import javax.inject.Inject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static com.github.adminfaces.template.util.Assert.has;

/**
 * @author rmpestano
 *         Reception Business logic
 */
@Stateless
public class ReceptionService implements Serializable {

    @Inject
    List<Reception> selectedPatients;

1 Ответ

1 голос
/ 03 июня 2019

Полагаю, вы используете admin-starter в качестве эталонного проекта, если вы посмотрите на код, вы увидите, что в Utils.java есть метод producer, который отвечает за создание списка автомобилей.

Чтобы добавить его в свой проект, вам просто нужно создать метод продюсера, который возвращает список o List, или вместо использования Injection вы можете просто удалить @Inject и создать список и добавить объекты вручную.

...