Re: Dynamic forms....
gbattine wrote:
Hi guys,
i'm a new user of jsf and i have a singolar question for you, i don't
know if a solution exists and i need your help.
I have a form with some fixed input fields.
I want my applications asks me in a menu page the number of forms i
want (3 for example) and dynamically shows me the form i have ,but
replicated for three times, each form as a row of a table for giving
user the possibility to see all the form in the same page before
uploading.
When the upload button is clicked i want all the form values are
inserted in a mysql table....
can someone tell me if a solution to my problem exists?
If it exists, can you help me with simple help...i'm a newbie.
Thanks very much
First of all, I don't think you can send multiple forms without
Javascript. Why do you want to have multiple forms? Anyway, you can
build such a page by creating a binding.
For example, I needed to build a form which had variable input fields.
The class I made looks like this:
public class DynamicForm {
public HtmlPanelGrid getFormElements() {
ReportInfo ri = (ReportInfo) ViewUtils.eval("#{reportInfo}");
Set keys = ri.getParameters().keySet();
HtmlPanelGrid grid = new HtmlPanelGrid();
grid.setColumns(2);
List children = grid.getChildren();
Iterator ix = keys.iterator();
while(ix.hasNext()){
String next = (String) ix.next();
HtmlOutputText ot = new HtmlOutputText();
ot.setValue(next);
children.add(ot);
HtmlInputText hit = new HtmlInputText();
hit.setSize(40);
hit.setTitle(next);
hit.setRequired(true);
hit.setStyleClass("textfield");
String bind = "#{reportInfo.parameters['" + next + "']}";
hit.setValueBinding("value",
ViewUtils.getApplication().createValueBinding(bind));
children.add(hit);
}
return grid;
}
}
Then I declard it in the grs-config.xml:
<managed-bean>
<managed-bean-name>dynamicForm</managed-bean-name>
<managed-bean-class>model.view.DynamicForm</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
And used it in a JSF like this:
<h:panelGrid binding="#{dynamicForm.formElements}" />
I hope you can use this example to find a solution.
Regards,
Moiristo