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
Patrick Mayer 4Patrick Mayer 4 

Saving VF checkbox value back to controller

Why does this only save the value of a boolean back if I call an empty function? I have tried it with the alternative second line that I have commented out and this does not update the controller as I would like. Is there a better way to do this? My solution seems hacky.
 
public class DemoController {
	public boolean activated { get; set; }

	public DemoController() {
		activated = false;
	}

	public void doNothing() {}
}


<apex:page controller="DemoController">
    <apex:form id="form">
        <apex:inputCheckbox value="{!activated}" >
            <apex:actionSupport event="onclick" action="{!doNothing}"/>
            <!--<apex:actionSupport event="onclick" rerender="test"/>-->
        </apex:inputCheckbox>
    </apex:form>

    <apex:outputText id="test" value="test" rendered="{!activated}"/>
</apex:page>



 
pconpcon
Your "hacky" way is the correct way to this in Visualforce.  You will however want it to be onChange instead of onClick.  How are you testing that it updated in the controller?  Are you look at this by seeing that the outputText is updated?