Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.errai.demo.grocery.client.local;
  
  import java.util.Date;
  import java.util.List;
  
 
 
A form for editing the properties of a new or existing Item object.

Author(s):
Jonathan Fuerth <jfuerth@gmail.com>
 
 public class ItemForm extends Composite {
 
   @Inject private EntityManager em;
   @Inject private User user;
 
   @Inject private Event<ItemnewItemEvent;
   
   // injecting this data binder causes automatic binding between
   // the properties of Item and the like-named @DataField members in this class
   // Example: property "item.name" tracks the value in the TextBox "name"
 
   @Inject @Bound @DataField private SuggestBox name;
   @Inject @Bound @DataField private TextBox comment;
 
   /*
    * Not @Bound because the department name belongs to the nested Department
    * object, not the Item.
    */
 
   @Inject @DataField private Button saveButton;
 
   private Runnable afterSaveAction;
 
   private void setupSuggestions() {
     for (Item i : .createNamedQuery("allItemsByName"Item.class).getResultList()) {
       iso.add(i.getName());
     }
     
     for (Department d : .createNamedQuery("allDepartments"Department.class).getResultList()) {
       dso.add(d.getName());
     }
   }
 
   @SuppressWarnings("unused")
   private void onNewItem(@Observes Item newItem) {
     ..println("ItemForm@" + System.identityHashCode(this) + " got new item event");
   }
  
  
Returns the store instance that is permanently associated with this form. The returned instance is bound to this store's fields: updates to the form fields will cause matching updates in the returned object's state, and vice-versa.

Returns:
the Item instance that is bound to the fields of this form.
 
   public Item getItem() {
     return .getModel();
   }
 
   public void setItem(Item item) {
     if (item.getDepartment() == null) {
       item.setDepartment(new Department());
     }
  }

  
Gives keyboard focus to the appropriate widget in this form.
  public void grabKeyboardFocus() {
    .setFocus(true);
  }
  // TODO (after ERRAI-366): make this method package-private
  @EventHandler("saveButton")
  public void onSaveButtonClicked(ClickEvent event) {
    TypedQuery<DepartmentdeptQuery = .createNamedQuery("departmentByName"Department.class);
    deptQuery.setParameter("name".getText());
    Department resolvedDepartment;
    List<DepartmentresultList = deptQuery.getResultList();
    if (resultList.isEmpty()) {
      resolvedDepartment = new Department();
      resolvedDepartment.setName(.getText());
    }
    else {
      resolvedDepartment = resultList.get(0);
    }
    .getModel().setDepartment(resolvedDepartment);
    .flush();
    
    if ( != null) {
      .run();
    }
  }
  void cleanup() {
  }
  public void setAfterSaveAction(Runnable afterSaveAction) {
    this. = afterSaveAction;
  }
New to GrepCode? Check out our FAQ X