vrijdag 23 januari 2009

JSF controllers and bean dependencies

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"

<!-- ... -->

<!-- example of property binding with a checkbox -->
<h:selectBooleanCheckbox title="#{file.selected}"

<!-- example of method binding with commandButton -->
<h:commandButton id="refresh" action="#{StatsController.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.
<!-- an example of a service -->

<!-- and this service being referenced in another bean -->
The controller for the list of files, select and process

Geen opmerkingen:

Een reactie plaatsen