I am having a select option within a pageblocktable
How do i get the value of each select option into a controller?
If there are ten rows then we would need the value of the select from the 10 rows. What do we set the value for the select option
On the onchange event in the select option i need to autopopulate other fields in the row. Any pointers on how we can achieve this?
Thanks
Best Answer
You'll need to provide a different value parameter for each selectlist, otherwise they will all write into the same variable and the last to do it will become the value for all of them.
This is a great use case for a wrapper class, as that way you colocate the selected value with the rest of the information being presented in the datatable. For example, if you have a list of account sobjects, you'd have a wrapper class that holds the account and the selected value:
Then you'd build a list of these for display:
Then in the page, you'd use this collection to back the pageblocktable:
With regard to the onchange, you'd need to add an actionsupport to the selectlist to execute an action method when the onchange event happens. This would traverse the list of wrappers and populate any additional fields based on the value of 'selVal'.