Hi everyone ,
this is related to ManyToOne-Relation in AutoGrid. I have two simple Entities called Order
and Customer
. An Order
has exactly one Customer
(and a Customer
can have 0 or more Orders
). The entities are defined like this:
@Entity
@Table(name = "orders")
public class Order {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
Long id;
@NotNull
private String number;
@NotNull
private LocalDate created;
@NotNull
@ManyToOne(targetEntity = Customer.class, optional = false)
private Customer customer;
// Getters and Setters omitted
}
@Entity
@Table(name = "customers")
public class Customer {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
Long id;
@NotBlank
String name;
@NotBlank
@Email
String mail;
// Getters and Setters omitted
}
I would like to use AutoForm
to add and edit an order. The corresponding OrderService
is implemented like this:
@BrowserCallable
@AnonymousAllowed
public class OrderService extends CrudRepositoryService<Order, Long, OrderRepository> {}
If I use AutoForm
like this:
<AutoForm model={OrderModel} service={OrderService} item={order} />
I see the following result:
The field for Customer
is rendered as a TextArea
. That really surprised me and I’m not sure if that’s what is intended?
It is easy to change AutoForm
using as custom renderer for Customer
like this:
fieldOptions={{
customer: {
renderer: ({ field }) => <ComboBox {...field} items={customers} itemLabelPath='name' />,
},
}}
This is fine and works as expected. However, I would like to know if there is another or easier way to support the ManyToOne-Relation? The default behavior of AutoForm
seems strange to me.