function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
raj161raj161 

Get the values from visualforce to apex.

Hi,

I am building a visualforce page for a survey which creates several questions using the <apex:repeat>.

The question info is pulled from DB and each question is having a radio button list.

 

Once the user selects his answers I want to get the result to apex class? Having hard time  in getting the values of the radio button as they were created dynamically using the <apex:repeat>.

 

Any ideas how to to get the values?

 

Thanks

Raj

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This sounds like a case for our old friend the wrapper class.

 

I'm assuming your questions are a custom object, but they don't contain a field that can back the radio button - essentially this is metadata about the question for use by the page.

 

1. Create a custom class inside your controller that holds the question object and a string to back the radio button. 

2. When you retrieve the list of questions to be displayed, convert this to a list of the custom class.

3. Back your repeat tag with the list of custom class instances rather than questions

 

Then when the user makes their selections, your custom class instances will be updated via the viewstate and available to your code.

 

 

All Answers

bob_buzzardbob_buzzard

This sounds like a case for our old friend the wrapper class.

 

I'm assuming your questions are a custom object, but they don't contain a field that can back the radio button - essentially this is metadata about the question for use by the page.

 

1. Create a custom class inside your controller that holds the question object and a string to back the radio button. 

2. When you retrieve the list of questions to be displayed, convert this to a list of the custom class.

3. Back your repeat tag with the list of custom class instances rather than questions

 

Then when the user makes their selections, your custom class instances will be updated via the viewstate and available to your code.

 

 

This was selected as the best answer
raj161raj161

Thanks Bob for your reply.

Yes, I successfully implement using what you have said above and also with the help of this post.

http://wiki.developerforce.com/index.php/Wrapper_Class

 

Thanks for your help.

 

Raj

 

ZathZath

I know this is an old thread, but do you have example code of the solution by any chance, I seem to be stuck in the exact same situation.