Value Bindings for the Report Entry Fields

Besides the elements and attributes for conversion and validation, all JSF component action elements in Example 7-2 have value attributes that bind them to bean properties, in the same way as in the examples in Chapter 6.

The value binding expression for the Title is reportHandler.currentReport.title. The first part, reportHandler, is the variable for the ReportHandler we looked at in Chapter 6. This class has a property named currentReport that holds a reference to an instance of the Report class described in Chapter 5, which in turn has a property named title:

package com.mycompany.expense;
...
public class ReportHandler {
    private Report currentReport;
    ...
    public Report getCurrentReport( ) {
        if (currentReport == null) {
            currentReport = createNewReport( );
        }
        return currentReport; 
    }
    ...
    private Report createNewReport( ) {
        Report report = new Report( );
        report.setOwner(getCurrentUser( ));
        ...
        return report;
    }
    ...
}
package com.mycompany.expense;
...
public class Report implements Serializable {
    private String title;
    ...
    public synchronized String getTitle( ) {
        return title;
    }

    public synchronized void setTitle(String title) {
        this.title = title;
    }
    ...
}

The value binding is used as an lvalue when the submitted form is processed, setting the title property of the current report to the value of the UIInput component. When the response is rendered, it’s used as an rvalue, so the UIInput component reads its value from the title property.

The components ...

Get JavaServer Faces now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.