Java Reference
In-Depth Information
public static final int DEBIT = 1;
public static final int CREDIT = 2;
private int paymentOption = DEBIT;
@Digits(integer = 10, fraction = 2, message = "Invalid value")
private BigDecimal value;
private Date datetime;
The
paymentOption
value is an integer passed in from the radio button component;
the default value is
DEBIT
. The
value
is a
BigDecimal
with a Bean Validation con-
straint that enforces a currency value with a maximum number of digits. The timestamp
for the event,
datetime
, is a
Date
object initialized when the
pay
method is called.
The
pay
method of the bean first sets the timestamp for this payment event. It then creates
and populates the event payload, using the constructor for the
PaymentEvent
and call-
ing the event's setter methods using the bean properties as arguments. It then fires the
event.
@Logged
public String pay() {
this.setDatetime(Calendar.getInstance().getTime());
switch (paymentOption) {
case DEBIT:
PaymentEvent debitPayload = new PaymentEvent();
debitPayload.setPaymentType("Debit");
debitPayload.setValue(value);
debitPayload.setDatetime(datetime);
debitEvent.fire(debitPayload);
break;
case CREDIT:
PaymentEvent creditPayload = new PaymentEvent();
creditPayload.setPaymentType("Credit");
creditPayload.setValue(value);
creditPayload.setDatetime(datetime);
creditEvent.fire(creditPayload);
break;
default:
logger.severe("Invalid payment option!");
}
return "/response.xhtml";
}