0

我正在尝试通过从 SelectOneMenu 中选择客户名称来创建新订单。我收到“空转换器”的转换错误设置值。

订单.java

@Entity
@Table(name = "order")

public class Order
{

    @Id
    @Column(name = "ORDER_ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long orderId;

    @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "PRODUCT_ID")
    private Product product;

    @Column(name = "QUANTITY")
    private int quantity;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "ORDER_DATE")
    private Date orderDate;

    @ManyToOne(optional = false)
    @JoinColumn(name = "CUSTOMER_ID", referencedColumnName = "CUSTOMER_ID")
    private Customer customer;

    // Getters & Setters

}

新订单.xhtml

<h:outputLabel value="Customer: "/>
<h:selectOneMenu id="customer" value="#{solController.order.customer}" >         
    <f:selectItem itemLabel="" itemDisabled="true"/>
    <f:selectItems value="#{solController.customerList}" var="customer" id="customerID" itemLabel="#{customer.customerName}" itemValue="#{customer.customerId}" />
</h:selectOneMenu>

SolController.java

@ManagedBean(name = "solController")
@SessionScoped
public class SolController implements Serializable
{
    @EJB
    private SolEJB solEJB;

    private Order order = new Order();
    private List<Order> orderList = new ArrayList<Order>();

    public String doCreateOrder()
    {
        order = solEJB.createOrder(order);
        orderList = solEJB.findOrders();
        return "listOrders.xhtml";
    }

    // Getters & Setters
}

SolEJB.java

@Stateless
public class SolEJB
{
    @PersistenceContext(unitName = "myPU")
    private EntityManager em;

    public Order createOrder(Order order)
    {
        em.persist(order);
        return order;
    }
}
4

0 回答 0