Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto generation form issue vaadin with many to one field --- Select field shows objects hash code
    primarykey
    data
    text
    <p>I tried to auto generate a form using the JPA container. For a many to one entity, it fills the select box with hash code as shown -</p> <p><img src="https://i.imgur.com/AgzvcSs.png?1" alt=""> Is it possible to have some other parameter of the mapped entity to be displayed.</p> <p>These are my entities</p> <pre><code>@Entity @Table(name = "state") public class State { private String id; private String name; private Country country; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "country_id", nullable = false) public Country getCountry() { return country; } public void setCountry(Country country) { this.country = country; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Id public String getId() { return id; } public void setId(String id) { this.id = id; } } @Entity @Table(name="country") public class Country { private String id; private String name; private List&lt;State&gt; states; @OneToMany(targetEntity=State.class, mappedBy="country", fetch=FetchType.EAGER) public List&lt;State&gt; getStates() { return states; } public void setStates(List&lt;State&gt; states) { this.states = states; } @Id public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } </code></pre> <p>And this is my init method -</p> <pre><code>@Override protected void init(VaadinRequest request) { setupEntityManager(); FormLayout layout = new FormLayout(); setContent(layout); final JPAContainer&lt;State&gt; states = JPAContainerFactory.make(State.class, "test1"); final Form stateForm = new Form(); stateForm.setCaption("State Editor"); stateForm.addStyleName("bordered"); // Custom style stateForm.setWidth("420px"); stateForm.setBuffered(true); stateForm.setEnabled(false); final FieldFactory fieldFactory = new FieldFactory(); stateForm.setFormFieldFactory(fieldFactory); stateForm.setItemDataSource(states.getItem("k")); stateForm.setEnabled(true); final Button save = new Button("Save"); stateForm.getFooter().removeAllComponents(); stateForm.getFooter().addComponent(save); layout.addComponent(stateForm); save.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { System.out.println("----------------commiting"); stateForm.commit(); stateForm.setEnabled(false); } catch (Validator.InvalidValueException e) { } } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload