HTML and CSS Reference
In-Depth Information
The execution of #{calc.logFindFactorial} which logs findFactorial operation will be performed before the
actual factorial calculation by #{calc.findFactorial} . Listing 4-8 shows the updates to Calc managed bean which is
shown originally in Listing 4-4.
Listing 4-8. Updated Calc Managed Bean
public class Calc implements Serializable {
private long number;
private long result;
public long getNumber() {
return number;
public void setNumber(long number) {
this.number = number;
public long getResult() {
return result;
public void setResult(long result) {
this.result = result;
public void logFindFactorial(ActionEvent event) {
System.out.println("Getting the factorial for: " + number);
public String findFactorial() {
result = 1;
for (int i = 1; i <= number; i++) {
result = result * i;
System.out.println("Factorial(" + number + ") = " + result);
return null;
After entering a number in the number field and then clicking "Calculate Factorial" command button, the
following lines will be printed in console as follows:
Getting the factorial for: 3
Factorial(3) = 6
Sometimes, you may need to set a value directly in your managed bean property before executing an action
method; if you have this situation then you can use <f:setPropertyActionListener> tag inside your ActionSource2
component. Table 4-1 shows the main attributes of <f:setPropertyActionListener> tag.
Search WWH ::

Custom Search