I am implementing a visualforce page with a customized 'cancel' button and 'cancel' function in the controller extension

Here is the sample code

    <apex:commandButton action="{!save}" value="Save"/>
    <apex:commandButton action="{!cancel}" value="Cancel"/>
     <apex:inputText value='{!isChecked}' styleClass="check-box">

And the controller code for cancel is like below

public boolean isChecked{get;set;}
public PageReference cancel(){
    system.debug('is checked:'+isChecked);
    return null;

On the page I have javascript programmatically update the isCheck inputbox. code like below:

function toggleSubView(isToggle){

Here is the issue: After I update isCheck to 'true' and trigger 'Cancel'. On browser console I can see the web request I can see the form is senting 'true' as isCheck to the server. However, the console log print 'false' if isCheck value.

Any ideas on what may cause this issue?

  • 2
    Can you share the JavaScript which sets the checked state of the isChecked member in your controller? Are you expecting to see the string true in the apex:inputText field? Is there a reason you have not used apex:inputCheckbox? – Mark Pond Jun 25 '13 at 22:02
  • if I trigger 'Save' the value will be updated correctly – bluecat Jun 25 '13 at 22:38
  • It seems like the on the page <apex:commandButton action="{!cancel}" value="Cancel"/> this is calling 'cancel' which is a standard function come from the standard controller. Even though I override this function in the extension class, it prevent the data binding inside the form to update. <apex:commandButton action="{!doCancel}" value="Cancel"/> Once I change the cancel function to another name: The value is updated accordingly. :D – bluecat Jun 25 '13 at 22:47
  • FYI, your controller method cancel() should not return null but should return standardController.cancel() . That method returns a pageReference to, I believe, the value of the retURL parm. – cropredy Jun 25 '13 at 23:34
  • Did you change the markup from apex:inputCheckbox to apex:inputText accidentally or intentionally when you posted the example for this question or is it your code exactly? apex:inputText does not render a checkbox and your JavaScript will simply insert the string 'true' and 'false' into the text box based on the parameter. Is that your intent? If it is not, try changing your markup from apex:inputText to apex:inputCheckbox and you will have more success. – Mark Pond Jun 26 '13 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.