user2471366
user2471366

Reputation: 73

Generate dynamic forms that change based on form input in jSF

I need to create a form that takes some data from the server and generate a form based on the type of the data. For example, if I have a String, I need the form to have an input box. If I have a List, I need the corresponding form field to have a group of checkboxes. Is there anyway to create this type of auto-generating form? I have been playing with data tables, and I can figure out how to generate a table that dynamically changes. But I can't find a way to generate a form that dynamically changes. I can probably figure out a way to create this in javascript/jquery, but is there a way using JSF/PrimeFaces/RichFaces?

Upvotes: 1

Views: 1485

Answers (2)

Akheloes
Akheloes

Reputation: 1372

This feature might interest you, it's a primefaces extension that handles creation of dynamic forms (on runtime). The form receives fields (or controls) by wish from a bean and adds them.

It's called DynaForm ; hope that helps your cause.

Upvotes: 2

Makhiel
Makhiel

Reputation: 3884

You can take advantage of the rendered attribute, doing something like this:

<h:inputText rendered="#{bean.doIHaveAString}" />

<h:selectManyCheckbox rendered="#{bean.doIHaveAList}" />

those elements will only appear if the condition is met

Upvotes: 0

Related Questions