I’m refreshing my JSF knowledge since I’ve been working with spring mvc instead for a while. In fact a lot is similar to spring or can be done using a similar approach.
JavaBean: Interconnection between front- and backend are the javabeans. These you should know, having a no args ctor, properties with accessors (getters and setters), binding of these properties in frontend, …
public class JavaBean {
private String myProperty;
public JavaBean() {};
public void setMyProperty(String property) {
this.myProperty = property;
}
public String getMyProperty() {
return this.myProperty;
}
}
Using javabeans as controllers: In JSF javabeans can be configured using the faces-config.xml (or any custom named xml configuration file when it’s pointed correctly). The properties can be easily set by providing setters and getters in the javabean class and databinding in the JSF page. You can use these managed beans as controllers by just creating some extra methods and the commandButton or commandLink jsf-component bound to these methods.
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
template="/WEB-INF/template/default.xhtml">
<h:selectBooleanCheckbox title="#{file.selected}"
value="#{file.selected}">
<h:commandButton id="refresh" action="#{StatsController.refresh}"
value="#{bundle.refresh}">
Bean dependencies: Service and other dependencies between beans can also be configured in this xml. Therefore create managed beans with no scope and then reference these in the actual javabean.
fileservice
FileService
group.project.services.FileServiceImpl
none
The controller for the list of files, select and process
FilesController
group.project.web.FilesController
request
service
#{FileService}