+ Start a Discussion
Engine ForceEngine Force 

Why side-effect in setter method?

In the example here http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle_example.htm?SearchType=Stem&Highlight=Setter|setter|setters, can someone explain why selectedValue = value; is a side-effect? Why cannot you set selectedValue in its own setter method?

 

public class componentController {

    public String selectedValue {

        get;

        set {

            editMode = (value != null);

          

 // Side effect here - don't do this!     

            selectedValue = value;

        }

    }

    public Boolean editMode {get; private set;}

}

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

I believe I just mentioned this in our last post, but the code doesn't have the "side-effect" that the article claims to divine to its audience. Just ignore this article (or even better, file a complaint on the page), and work with the information I've provided in my prior post.

All Answers

sfdcfoxsfdcfox

I believe I just mentioned this in our last post, but the code doesn't have the "side-effect" that the article claims to divine to its audience. Just ignore this article (or even better, file a complaint on the page), and work with the information I've provided in my prior post.

This was selected as the best answer
Hao Huang 16Hao Huang 16
@sfdcfox could you provide your prior post ? I am new to sf and visualforce, just want to make sure I am writing proper code. thanks