Java Reference
In-Depth Information
<h:outputLabel value="Options:" for="opt"/>
<h:selectOneRadio id="opt"
value="#{paymentBean.paymentOption}">
<f:selectItem id="debit" itemLabel="Debit Card"
itemValue="1"/>
<f:selectItem id="credit" itemLabel="Credit Card"
itemValue="2" />
</h:selectOneRadio>
<p><h:commandButton id="submit" value="Pay"
action="#{paymentBean.pay}" /></p>
<p><h:commandButton value="Reset"
action="#{paymentBean.reset}" /></p>
</h:form>
...
</h:body>
The input text field takes a payment amount, passed to paymentBean.value . Two ra-
dio buttons ask the user to select a Debit Card or Credit Card payment, passing the integer
value to paymentBean.paymentOption . Finally, the Pay command button's action
is set to the method paymentBean.pay , while the Reset button's action is set to the
paymentBean.reset method.
The payment.PaymentBean managed bean uses qualifiers to differentiate between
the two kinds of payment event:
Click here to view code image
@Named
@SessionScoped
public class PaymentBean implements Serializable {
...
@Inject
@Credit
Event<PaymentEvent> creditEvent;
@Inject
@Debit
Event<PaymentEvent> debitEvent;
The qualifiers, @Credit and @Debit , are defined in the payment package along with
PaymentBean .
Next, the PaymentBean defines the properties it obtains from the Facelets page and will
pass on to the event:
Search WWH ::




Custom Search