O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required