Пример #1
0
  // TODO (after ERRAI-366): make this method package-private
  @EventHandler("saveButton")
  public void onSaveButtonClicked(ClickEvent event) {
    TypedQuery<Department> deptQuery = em.createNamedQuery("departmentByName", Department.class);
    deptQuery.setParameter("name", department.getText());
    Department resolvedDepartment;
    List<Department> resultList = deptQuery.getResultList();
    if (resultList.isEmpty()) {
      resolvedDepartment = new Department();
      resolvedDepartment.setName(department.getText());
    } else {
      resolvedDepartment = resultList.get(0);
    }
    Item item = itemBinder.getModel();
    item.setDepartment(resolvedDepartment);
    item.setAddedBy(user);
    item.setAddedOn(new Date());

    fooList.getItems().add(item);
    em.persist(fooList);
    em.flush();

    if (afterSaveAction != null) {
      afterSaveAction.run();
    }
  }
Пример #2
0
  @PostConstruct
  private void setupSuggestions() {
    MultiWordSuggestOracle iso = (MultiWordSuggestOracle) name.getSuggestOracle();
    for (Item i : em.createNamedQuery("allItemsByName", Item.class).getResultList()) {
      iso.add(i.getName());
    }

    MultiWordSuggestOracle dso = (MultiWordSuggestOracle) department.getSuggestOracle();
    for (Department d : em.createNamedQuery("allDepartments", Department.class).getResultList()) {
      dso.add(d.getName());
    }
  }
Пример #3
0
 public void setItem(Item item) {
   if (item.getDepartment() == null) {
     item.setDepartment(new Department());
   }
   itemBinder.setModel(item, InitialState.FROM_MODEL);
 }
Пример #4
0
 @SuppressWarnings("unused")
 private void onNewItem(@Observes Item newItem) {
   System.out.println("ItemForm@" + System.identityHashCode(this) + " got new item event");
   ((MultiWordSuggestOracle) name.getSuggestOracle()).add(newItem.getName());
 }