Skip to content
gabor-farkas edited this page May 27, 2014 · 3 revisions

The JSF-Builder framework has two main motivations:

  • The XHTML based templating works fine for html intensive layouts. Although it supports creating reusable composite components, it's much easier to create and maintain them in Java code. If you work with Java classes with the common OO techniques you already know and your IDE already supports. Creating the views in Java code will feel strange the first times, but discoverability and maintainability will pay off on the long term. If your application has many similar screens (admin / crud screens for example), it's also easier in Java code to properly arrange reusable parts.
  • Bindings can be also created with Java code thus making it compile-time checked and typesafe. There are quite good IDE toolings for JSF, but when you start using complex template structures, they won't catch up.

Doctusoft Ltd. generally doesn't advice using JSF. But once you have to use it, you can address these two main points by using JSF-Builder. With JSF-Builder, you still create your page frames and html heavy parts in xhtml, but when it turns to reusable content, you insert the imperatively created parts.

A quick example, you create the View as a ViewScoped managed bean:

@ViewScoped
@ManagedBean(name="TestView")
public class TestView extends AbstractBackingView<TestBacking> {

	public TestView() {
		super(TestBacking.class, "TestBacking", "test");
		JsfForm form = new JsfForm("mainform").appendTo(container);
		new JsfLabel("headerLabel", "Component showcase")
		    .withStyleClasses("heading").appendTo(form);
		new JsfInputText("messageInput")
		    .bind(bindOnPresenter().get(TestBacking_._input)).appendTo(form);
		new JsfLabel("messageLabel")
		    .bind(bindOnPresenter().get(TestBacking_._message)).appendTo(form);
		new JsfButton("mainButton", "clickme")
		    .action(presenterMethod(TestBacking_.__testMethod)).appendTo(form);
    }
}

You always try to keep the view creation as simple as possible. Any view logic still belongs to the backing, which is here referred as the Presenter. You can notice two 'magic methods' bindOnPresenter and presenterMethod. The typesafe binding is supported by the ds-bean framework.

And the backing as a SessionScoped one:

@SessionScoped
@ManagedBean(name="TestBacking")
@Getter @Setter
public class TestBacking {
	
	@Property
	private String message = "hello world";
	
	@Property
	private String input = "";
	
	@MethodRef
	public void testMethod() {
		setMessage("you typed: " + input);
	}
}

So the Backing remains the ViewModel (in some terms) or the Presenter (in other terms).

And finally you use the view part in your existing xhtml page:

   		<h:panelGroup binding="#{TestView.instance}"></h:panelGroup>
Clone this wiki locally