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
SRILAKSHMI BSRILAKSHMI B 

How to pass vaue to a wrapper class variable from visualforce page.

Hi All,

 

 I am populating list of user records on the visualforce page where each record has a selct button.When user clicks on select button the corresponding user record name has to be retreived.

 

To display the list of user records i have used wrapper class which looks like this.

 

 

public class userwrapper
            {
                       public User user{get; set;}
                       public Boolean selected;
                       
                    public userwrapper(User t)
                    {
                        user = t;
                        selected = false;
                       
                    }
            }                   

 

 

when user clicks select button on any of the record I want to make selected value euuals true.So, I can process all the records and check whose selected value euals true and there by get the user associated with it.

 

But I am not able to make the selected value =true when user clicks on select button for any of the record.Can anyone please guide me how can I acheive this.

 

 

Thanks,

Srilakshmi B

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

As your button will be invoking an action method, you'll need to use a nested apex:param value in the commandbutton component to pass the value back to the controller.  I'd suggest you pass back the id of the user.

 

There's an example of doing this on a blog entry that I posted over the weekend: http://bobbuzzard.blogspot.com/2011/03/edit-parent-and-child-records-with.html

 

A couple of points to note:

 

(1) Your commandbutton will need a rerender attribute, or the selected id won't be passed back to the controller

(2) You'll need a way to retrieve the wrapper instance based on the selected id.  My suggestion here would be to store them in a map keyed by the user id.

All Answers

bob_buzzardbob_buzzard

As your button will be invoking an action method, you'll need to use a nested apex:param value in the commandbutton component to pass the value back to the controller.  I'd suggest you pass back the id of the user.

 

There's an example of doing this on a blog entry that I posted over the weekend: http://bobbuzzard.blogspot.com/2011/03/edit-parent-and-child-records-with.html

 

A couple of points to note:

 

(1) Your commandbutton will need a rerender attribute, or the selected id won't be passed back to the controller

(2) You'll need a way to retrieve the wrapper instance based on the selected id.  My suggestion here would be to store them in a map keyed by the user id.

This was selected as the best answer
miteshsuramiteshsura

Bob,

 

I see you have replied to many wrapper class posts. I have 2 wrapper class in single controller, while one works great, other one just does not pass values to the controller. 

 

here is the link to my post: http://boards.developerforce.com/t5/General-Development/2-wrapper-class-in-single-class-not-working/m-p/347953

 

Can you let me know what am I missing here? Appreciate the time.

 

Mitesh