I am new to JSF, and am in need of some advice on how to achieve the below requirement. I have a datatable, with input text(which displays a value from the DB) and a checkbox in each row. On checking the checkbox, the input text is enabled for editing, and on typing the new value and hitting the submit button outside the data table, the edited value is not being retained. Kindly let me know how this can be done(i need to be able to select multiple rows and then submit all at the same time). Here is the snippet of the jsf.
My backing bean has the following properties with getters/setters:
private List pBean;
private HtmlDataTable pDataTable;
When my action method in the backing bean gets called I see that the state of the dataTable reflects the state when it was created, not the state when the user clicked the commandButton (after they have edited some of the editable text fields).
What's the best way to get this state back into the backing bean so I can update my model?
I have already tried using immediate attribute. Can anyone give me inputs on how i can use the actionListeners (cmd button )/value change listeners(check box) to handle this? Do we need to implement processAction method for such a requirement.
Welcome to the JavaRanch, Jackie! You can use the "code" button in the editor to wrap Java code and XML with tags that will make your samples more readable.
Binding is something that's overused in JSF. You typically only need to do binding if you're doing advanced manipulation of the UI controls themselves. For a simple dataTable display, it's pretty much a waste of time.
When you submit a form using a submit button external to the table, the entire set of input controls in the table is submitted back to the server. If all of the control values are valid, the table datamodel is updated and the action processor method is fired. The action method can then do what it needs to do, secure in the knowledge that the model has been updated and that all of the data in the model is valid.
You cannot use checkbox controls to restrict what data comes back. HTML doesn't work that way. All of the data will come back. The best you can do is make your table model front your persistent data model and only update the actual persistent data for rows which have their checkbox properties checked "true".
Sometimes the only way things ever got fixed is because people became uncomfortable.
Thanks Tim i got that to work, i had a disable attribute which was reseting the value to the old one inspite of updating, and sorry for pasting the code in the text area. I had a follow up question on what you said about getting all the data at once, is it possible to at least show the selected value outside the datatable in a different output text based on the selection of the check box? If so could you give me a small snippet which would do that.