You need to sign in to do that
Don't have an account?
Greg Coogan
Visualforce Checkbox in Custom Controller
I have written a custom controller and Visualforce page that displays records from a custom object, and related records, in a few HTML tables. I have a checkbox on the page and a Save button to display the refined results. Do I need to write a function that returns a modified list of records, basically copying what is in my controller's main class to a "PageReference save()" class? Ideally, the button would result in the controller running again with the updated value of the checkbox. I've seen examples but having trouble. Please help.
I have made some minor changes in your controller class to call the data fetching in both constructor as well as Save() method.
Here is the code.
And, I suggest you use reRender option on the Save button, to rerender your second section.
Line 26 of your VF page would be like this.
And, line 21 would be..
Let me know if this works for you.
All Answers
If yes, you need to reload the data. Otherwise, you can simply save the data and return null from your save() method, so that it will not refresh the screen.
Can you please post your code, if you need help resolving any errors?
I was originally going to have OnClick or OnChange Javascript function but then realized the button made more sense since I'll be adding more criteria options, like data ranges. I have a repeat section on the Visualforce page that has a main table that displays fields of a single record and three small tables below that display related records of that single record. This repeats for all records in a list passed from the Controller. The criteria would affect all of these tables since they are nested in a repeat for each record.
The Save method is basically a "re-run report" function. It never saves data.
Currently, the Save method returns null (does nothing) and refreshes the page.
Here is an anonymized version of my code (cannot post the actual code I'm developing for my company):
Visualforce:
Apex Custom Controller: I might be having the most trouble passing over a value. Line 38 of my controller is where I'd like to be able to use the checkbox value whenever Ioad and refresh the page.
The save function might not be needed if I can get the value of the checkbox to be passed to the main class of the Controller on refresh.
I have made some minor changes in your controller class to call the data fetching in both constructor as well as Save() method.
Here is the code.
And, I suggest you use reRender option on the Save button, to rerender your second section.
Line 26 of your VF page would be like this.
And, line 21 would be..
Let me know if this works for you.
Also, I added on line 34: Without this line, fetchData() kept adding onto the list each time I clicked the button, resulting in duplicate records displayed.