Внедрить контроллер в представлении Vaadin Spring Boot

Я разрабатываю веб-приложение с Spring Boot и Vaadin для интерфейса приложения.

Моя проблема в том, что я не могу ввести контроллер для просмотра, приложение запускается нормально, но bean-компонент имеет значение null при выполнении.

Мой контроллер:

@Component
public class ViewController {

/** Inyección de Spring para poder acceder a la capa de datos.*/
@Autowired
private CommonSetup commonSetup;

/**
 * This method gets the user from db.
 */
public Temployee getUser(String username, String password) {
    Temployee empl = null;
    // get from db the user
    empl = commonSetup.getUserByUsernameAndPass(username, password);

    // return the employee found.
    return empl;
}

... ...

Мой вид:

@Theme("login")
@SpringUI
public class LoginView extends CustomComponent implements View ,Button.ClickListener {

/** The view controller. */
@Autowired
private ViewController   vContr;

public LoginView() {
    setSizeFull();

   ...
   ...

   // Check if the username and the password are correct.
   Temployee empleado = vContr.getUser(username, password);

В LoginView bean ViewController равно нулю.

Как я могу добавить bean в представление?

Спасибо.


person Daniel    schedule 29.12.2015    source источник


Ответы (1)


Вы не можете получить доступ к автосвязанному полю в конструкторе, потому что в этот момент инъекция еще не выполнена. Добавьте метод с аннотацией @PostConstruct, который будет выполняться после ввода полей:

@PostConstruct
public void init() {
  // Check if the username and the password are correct.
  Temployee empleado = vContr.getUser(username, password);
}

В этом нет ничего особенного для vaadin4spring, так работает Spring.

person Henri Kerola    schedule 29.12.2015