0

I have an architecture problem with the following use case.

I have a JSF page for creating JPA entities, for example orders.

The Order entity has two fields: invoiceRecipient and receiver. Both of the type Customer.

There are two fields on the Order form, each with a button that opens a selection list for choosing a customer from the customerSelectionController.

when the customer has been chosen the customerSelectionController bean does something like:

@Inject
@Selected 
Event<Customer> customerSelectedEvent;
public void select(Customer customer) {
    customerSelectedEvent.fire(customer);
}

and the orderFormController reveives the event with

public void customerSelected(@Observes @Selected Customer customer) {

}

and here is the problem ^^ The orderFormController knows the customer has been selected but is it intended to be set as the invoiceRecipient or as the receiver of the order?

I know you could specify more accurate qualifiers like @SelectedAsInvoiceRecipient but is this really the way how to do this?

Should I copy the customerSelectionController bean as an invoiceRecipientSelectionController and a receiverSelectionController and let both of them fire differently qualified Customer entities?

I am also using Apache Deltaspike that supports GroupedConversations and other complex things, but I couldn't find a specified rule how to achive this.

Thanks for your help

hidehawk
  • 81
  • 1
  • 6

1 Answers1

0

You can either use qualifiers or wrap your Customer entity in a more specific event type, e.g.

public class InvoiceRecipientSelected {
    private Customer customer;
    // ... add accessors ...
}

Event<InvoiceRecipientSelected> invoiceRecipientSelected;
Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63