I have a fieldset with some selectonemenus on my jsf page. I clone the fieldset using jquery on click of a link, similar to 'add another row' (logic similar to: Using jQuery to dynamically add form fields (or fieldsets) based on a dropdown box value), I can add infinite fieldsets, now how do I bind or get the values of this dynamically generated form content on my controller. I use f:ajax to submit the form. I checked this : How do I create form controls dynamically with DHTML and deal all those with JSF?, it says non-trivial, is there any simple way of getting these values on my JSF. Thanks.
Asked
Active
Viewed 1,634 times
1 Answers
1
You need to either "clone" the fieldset by JSF instead of jQuery (<ui:repeat>
or <h:dataTable>
is helpful here), or to drop JSF and use a request based MVC framework instead.
If you don't want to drop JSF and want to stick to the jQuery way for some reason, then you'll have to rewrite a lot of boilerplate code yourself which does basically the same job as JSF is doing under the covers in order to collect the submitted values, converting/validating them, updating the model values and invoking any business actions.
See also:
-
Hi BalusC, Thanks for the response. I have one basic doubt. The html controls I add using jQuery will it be part of the component tree of that view i.e. part of the request? Is it that it will not be identified with any of the JSF UI* components and hence cannot take part in any phases of the component lifecycle rt? But is there some quick dirty way to just get the values for the additional controls, bypassing the lifecycle behaviour, etc or is that too much dirty work. I am sorry if my question is dumb. – Siva VG Jun 19 '12 at 16:39
-
It won't be part of JSF tree in any way. You're just manipulating the HTML DOM tree fully in the client side. JSF is a HTML code generator and all the browser retrieves is plain HTML. Once the HTTP response completes, then JSF has finished its job. Any future client side changes in HTML DOM tree without using JSF's own ajax facilities will not be reflected in JSF component tree. Just use JSF instead of jQuery. See also the last "See also" link to get some insights based on a concrete example. – BalusC Jun 19 '12 at 16:41