@Table(name = "t_users")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;
@NotNull
@Size(min = 2, max = 100)
private String name;
....
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
Set actionList = new HashSet(0);
//getters, setters}
@Entity
@Table(name = "t_actions")
public class Action implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private int id;
@NotNull
@Size(min = 2, max = 1000)
private String action_description;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "action_initiator", nullable = false)
private User user;
//getters, setters}
< /code>
И у меня есть форма, которая создает новое действие, где я должен выбрать пользователя.
Вопрос: как я могу выбрать пользователя в форме? Как реализовать выбор пользователя? < /P>
Код моей формы: < /p>
......
Action bean = new Action();
final BeanFieldGroup binder = new BeanFieldGroup(Action.class);
binder.setItemDataSource(bean);
binder.setBuffered(true);
fields.addComponent(binder.buildAndBind(((MyUI) "action.description", "action_description", TextField.class));
//Here must be a code of user selection
.....
< /code>
Я могу сделать это так, как это сделано здесь Vaadin Combobox со значениями и идентификаторами < /p>
// Set the caption mode to read the caption directly
// from the 'name' property of the item
contactNameCombo.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY);
contactNameCombo.setItemCaptionPropertyId("name");
// Add all organization contacts to the drop-down
for (Contact contact : organizationContacts) {
contactName = contact.getName();
contactId = contact.getId();
_logger.debug("Adding contactName=" + contactName + " contactId=" + contactId + " to person with id=" + personId);
// Note : the itemId of the item is the contactId
Item item = contactNameCombo.addItem(contactId);
item.getProperty("name").setValue(contactName)
}
// Add the contact of this person, and select it in the drop-down
contactName = person.getContact().getName();
contactId = person.getContact().getId();
Item item = contactNameCombo.addItem(contactId);
item.getProperty("name").setValue(contactName)
// Using the itemId (which = contactId) to select the given contact
contactNameCombo.setValue(contactId);
Но здесь я выбираю целочисленное значение, и мне нужно описать новое поле в моем классе, но мне нужно выбрать «сущность», когда это возможно.>
[code]@Table(name = "t_users") public class User implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") private int id; @NotNull @Size(min = 2, max = 100) private String name; .... @OneToMany(fetch = FetchType.LAZY, mappedBy = "user") Set actionList = new HashSet(0); //getters, setters}
@Entity @Table(name = "t_actions") public class Action implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") private int id; @NotNull @Size(min = 2, max = 1000) private String action_description; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "action_initiator", nullable = false) private User user; //getters, setters} < /code> И у меня есть форма, которая создает новое действие, где я должен выбрать пользователя. Вопрос: как я могу выбрать пользователя в форме? Как реализовать выбор пользователя? < /P> Код моей формы: < /p> ...... Action bean = new Action(); final BeanFieldGroup binder = new BeanFieldGroup(Action.class); binder.setItemDataSource(bean); binder.setBuffered(true); fields.addComponent(binder.buildAndBind(((MyUI) "action.description", "action_description", TextField.class)); //Here must be a code of user selection ..... < /code> Я могу сделать это так, как это сделано здесь Vaadin Combobox со значениями и идентификаторами < /p> // Set the caption mode to read the caption directly // from the 'name' property of the item contactNameCombo.setItemCaptionMode(Select.ITEM_CAPTION_MODE_PROPERTY); contactNameCombo.setItemCaptionPropertyId("name");
// Add all organization contacts to the drop-down for (Contact contact : organizationContacts) { contactName = contact.getName(); contactId = contact.getId(); _logger.debug("Adding contactName=" + contactName + " contactId=" + contactId + " to person with id=" + personId);
// Note : the itemId of the item is the contactId Item item = contactNameCombo.addItem(contactId); item.getProperty("name").setValue(contactName) } // Add the contact of this person, and select it in the drop-down contactName = person.getContact().getName(); contactId = person.getContact().getId(); Item item = contactNameCombo.addItem(contactId); item.getProperty("name").setValue(contactName)
// Using the itemId (which = contactId) to select the given contact contactNameCombo.setValue(contactId); [/code] Но здесь я выбираю целочисленное значение, и мне нужно описать новое поле в моем классе, но мне нужно выбрать «сущность», когда это возможно.>
@Table(name = t_users )
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = ID )
private int id;
@NotNull
@Size(min = 2, max = 100)
private...
Я подключил базу данных db2 из весенней загрузки и вызвал хранимые процедуры с помощью диспетчера объектов. В моем приложении не было никаких классов сущностей. Я только что вызвал хранимые процедуры, используя ссылку Entity Manager.
Здесь...
Для ясности продолжу здесь обсуждение, начатое здесь.
Внутри прослушивателя сущности Doctrine, в методе preUpdate (где у меня есть доступ как к старому, так и к новому значению любого поля сущности) я пытаюсь сохранить объект, не связанный с...