HTML and CSS Reference
In-Depth Information
Listing 5-27 is the managed bean that contains the logic that is used in the navigation rule. It is also the backing
bean for the Facelets view being accessed.
Listing 5-27. Action Method Used to Load the Record and Signal If the Record Was Loaded
@ManagedBean
@RequestScoped
public class RecordDisplay {
@EJB private RecordService recordService;
private Long id;
private Record record;
public Long getId() {
return id;
}
/**
* Used by f:viewParam to set the ID of the record to load.
*
* @param id Unique identifier of the record to load
*/
public void setId(Long id) {
this.id = id;
}
/**
* Loads the record with the ID specified in the viewParam.
*
* @return true if the record was loaded successfully, otherwise false if it wasn't found
*/
public boolean load() {
try {
record = recordService.findById(this.id);
return true;
} catch (EntityNotFoundException ex) {
return false;
}
}
}
The feature is very similar to <f:event type="preRenderView" /> with a couple of differences:
<f:event type="preRenderView" /> , it is the responsibility of the developer to redirect
the navigation in case the preconditions fail.
<f:event type="preRenderView" /> is executed after the component tree has been
generated (i.e., in the Render Response phase), whereas <f:viewAction /> is executed before
the component tree has been generated (i.e. in the Application phase).
Using
Search WWH ::




Custom Search