maandag 8 april 2013

PrimeFaces DynaForm

DynaForm is a PrimeFaces extention and can be used to build forms dynamically. You can define the display of the elements based on element types (e.g. input field, checkbox, paragraph, h2, etc.). If for example you want to display an input field you define in your .xhtml file:



TEXT_INPUT is the name I gave to all input fields.

Between the dynaFormControl elements you can define how the element should be rendered. In this example there's no label defined in the xhtml, but DynaForm renders it for you.


In the model you can define the label, elementType, value, whether a field is required and anything else you might need. The model is added to the form control and by adding value="#{elem.value}" DynaForm will assign any filled in value to the value field of the model.



In the bean is where you tie everything together. Here you create the DynaFormModel, -Rows, -Labels and -Controls.



The DynaFormModel contains all rows. In the rows you can add as many labels and controls as you want.