0

I've got a JSF datatable with an "add one" button below it. When pressed I add a new table row with input fields and a "save" button. This is all done by cloning an invisible template element and appending it to the table in JavaScript. The problem is that that new cloned form has no connection to JSF.

How can I make the row/table a JSF form that interacts with a backing bean? The cloning and appending can happen multiple times so copying a server-side generated JSF form (with unique IDs) won't work. Also I don't want to create the form in Java.

Hubert Grzeskowiak
  • 15,137
  • 5
  • 57
  • 74
  • Sorry, but I don't think the linked question is a duplicate. I don't want to simply add another row to a datatable, but generate a JSF form from within JS. – Hubert Grzeskowiak May 02 '16 at 21:41
  • It looks like you're missing the point of JSF. For your purpose, JSF is the wrong tool. Look for a request based MVC framework instead of a component based one. Here's your starting point: http://stackoverflow.com/q/4421839 – BalusC May 02 '16 at 22:12
  • Thanks for the answer but I won't change the whole project's toolset for one missing feature. – Hubert Grzeskowiak May 02 '16 at 23:03
  • I guess I have two choices: 1) make the page process request params + post a plain old HTML form action at it + rerender the table or 2) have only one form for a new item at a time that is hidden by default and shown on "add one". Since it's only one it can be generated by JSF. After saving (pressing save button) I would persist the entity and reset the backing bean so a new form is generated at form rerendering. – Hubert Grzeskowiak May 02 '16 at 23:09
  • 1
    All can be done with basic JSF as demonstrated in duplicate without the need to write any line of JavaScript code. – BalusC May 03 '16 at 06:32
  • @HubertGrzeskowiak: working for 1WS btw? – Kukeltje May 03 '16 at 06:35
  • @BalusC Thanks. The duplicate is basically my second method – Hubert Grzeskowiak May 03 '16 at 07:38

0 Answers0