+ Start a Discussion
Mike SummittMike Summitt 

Inputcheckbox actionsupport action not being called

I have a form where I allow the user the option to randomly generate a password, or enter one.  If the user chooses to generate a random password, then I want the password entry field to disappear, and the "must change password on first login" to be checked.  If the user doesn't generate a random password, then I want the password entry field to appear, and the other checkbox to be unchecked.

Unfortunately, no combination of event names or outputpanels will actually cause the function in the controller to run; it steadfastly refuses to execute.  I've put in a deliberate "blow up" statement to make absolutely sure that the function isn't running.  What do I need to do to get this code to execute?

Here is the relevant portion of the page:

            <apex:pageBlockSection columns="2" id="SecuritySection" title="Security Information">
                <apex:pageblocksectionitem >
                    <apex:outputlabel for="generate" value="Generate random password" />
                    <apex:inputCheckbox id="generate" value="{!generatePassword}">
                        <apex:actionSupport event="onchange" action="{!changeGenerate}" reRender="forcePanel, passwordPanel" status="generateChangeStatus" />
                    </apex:inputCheckbox>
                </apex:pageblocksectionitem>
                <apex:pageblocksectionitem >
                    <apex:outputpanel id="forcePanel">
                        <apex:outputlabel for="forcechangepassword" value="Must change password on first login" />
                        <apex:inputcheckbox id="forcechangepassword" value="{!forceChangePassword}" />
                    </apex:outputpanel>
                </apex:pageblocksectionitem>
                <apex:pageblocksectionitem >
                    <apex:outputpanel id="passwordPanel" >
                        <apex:outputlabel for="password" value="Use this password" />
                        <apex:outputpanel >
                            <div class="requiredInput">
                                <div class="requiredBlock"></div>
                                <apex:inputsecret id="password" value="{!password}" required="true" />
                            </div>
                        </apex:outputpanel>
                    </apex:outputpanel>
                </apex:pageblocksectionitem>
                <apex:actionstatus id="generateChangeStatus" starttext="Changing security options..." stoptext="" />
            </apex:pageBlockSection>

And here is the controller function:

    public PageReference changeGenerate() {
        System.assertEquals(1,null);
        forceChangePassword = generatePassword;
        return null;
    }
 

Best Answer chosen by Mike Summitt
Martijn SchwarzerMartijn Schwarzer
Hi Mike,

I've been testing your code and changed a few things to get it working. Please see my version of your page, with some important changes in bold:
  1. I removed the Required="true" attribute from the apex:inputsecret tag. This is the real reason your controller method is not called. Basically, you get an error (which is not shown), because this field does not contain a value. You will see your page working fine if you first add a value to this field.
  2. I changed the onChange event of the apex:actionsupport to an onClick event.
  3. I added an extra outputpanel for the password input field, this to make sure that the 2nd outputpanel renders correctly.
  4. I added a rendered attribute to the 2nd outputpanel for the password input field
<apex:page controller="forumquestioncontroller">
    <apex:pageMessages></apex:pageMessages>
    <apex:form id="theForm">
    	<apex:pageBlock mode="edit">
            
        	<apex:pageBlockSection columns="1" id="SecuritySection" title="Security Information">
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel for="generate" value="Generate random password" />
                    <apex:inputCheckbox id="generate" value="{!generatePassword}">
                        <apex:actionSupport event="onclick" action="{!changeGenerate}" reRender="forcePasswordChange, EnterPassword" status="generateChangeStatus" />
                    </apex:inputCheckbox>
                </apex:pageBlockSectionItem>
                
                <apex:outputPanel id="forcePasswordChange">
                    <apex:pageblocksectionitem >
                        <apex:outputlabel for="forcechangepassword" value="Must change password on first login" />
                        <apex:inputcheckbox id="forcechangepassword" value="{!forceChangePassword}" />
                    </apex:pageblocksectionitem>
                </apex:outputPanel>
                
                
                <apex:outputPanel id="EnterPassword">
                    <apex:outputPanel id="renderPasswordField" rendered="{!NOT(generatePassword)}">
                        <apex:pageblocksectionitem >
                            <apex:outputlabel for="password" value="Use this password" />           
                            <apex:inputsecret id="password" value="{!password}"/>
                        </apex:pageblocksectionitem>
                    </apex:outputPanel>
				</apex:outputPanel>

                <apex:actionstatus id="generateChangeStatus" starttext="Changing security options..." stoptext="" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
In your controller you will need to remove the following line of code to get it to work:
 
System.assertEquals(1,null);

I hope this helps! Happy coding!

Best regards,
Martijn Schwärzer
 

All Answers

Martijn SchwarzerMartijn Schwarzer
Hi Mike,

I've been testing your code and changed a few things to get it working. Please see my version of your page, with some important changes in bold:
  1. I removed the Required="true" attribute from the apex:inputsecret tag. This is the real reason your controller method is not called. Basically, you get an error (which is not shown), because this field does not contain a value. You will see your page working fine if you first add a value to this field.
  2. I changed the onChange event of the apex:actionsupport to an onClick event.
  3. I added an extra outputpanel for the password input field, this to make sure that the 2nd outputpanel renders correctly.
  4. I added a rendered attribute to the 2nd outputpanel for the password input field
<apex:page controller="forumquestioncontroller">
    <apex:pageMessages></apex:pageMessages>
    <apex:form id="theForm">
    	<apex:pageBlock mode="edit">
            
        	<apex:pageBlockSection columns="1" id="SecuritySection" title="Security Information">
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel for="generate" value="Generate random password" />
                    <apex:inputCheckbox id="generate" value="{!generatePassword}">
                        <apex:actionSupport event="onclick" action="{!changeGenerate}" reRender="forcePasswordChange, EnterPassword" status="generateChangeStatus" />
                    </apex:inputCheckbox>
                </apex:pageBlockSectionItem>
                
                <apex:outputPanel id="forcePasswordChange">
                    <apex:pageblocksectionitem >
                        <apex:outputlabel for="forcechangepassword" value="Must change password on first login" />
                        <apex:inputcheckbox id="forcechangepassword" value="{!forceChangePassword}" />
                    </apex:pageblocksectionitem>
                </apex:outputPanel>
                
                
                <apex:outputPanel id="EnterPassword">
                    <apex:outputPanel id="renderPasswordField" rendered="{!NOT(generatePassword)}">
                        <apex:pageblocksectionitem >
                            <apex:outputlabel for="password" value="Use this password" />           
                            <apex:inputsecret id="password" value="{!password}"/>
                        </apex:pageblocksectionitem>
                    </apex:outputPanel>
				</apex:outputPanel>

                <apex:actionstatus id="generateChangeStatus" starttext="Changing security options..." stoptext="" />
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
In your controller you will need to remove the following line of code to get it to work:
 
System.assertEquals(1,null);

I hope this helps! Happy coding!

Best regards,
Martijn Schwärzer
 
This was selected as the best answer
Martijn SchwarzerMartijn Schwarzer
Hi Mike,

I see that the statements in bold do not work. In stead the html tags <b> and </b> are added to the code. You will need to remove that in order to get it to work.

Regarding point 1: That's on line 27 of the page
Regarding point 2: That's on line 11 of the page
Regarding point 3: That's on line 23 of the page
Regarding point 4: That's on line 24 of the page

Good luck!
Mike SummittMike Summitt
Martijn,  thanks for the help.  I finally got the right behavior out of it, after enclosing it all in an actionregion so it quit looking at the rest of the page.  But all these outputpanels and stuff have messed up the styling.  I've tried dozens of combinations of class and styleClass and span and th and everything else I could find or think of, applying labelCol and dataCol and vfLabelColTextWrap all over the place, but I just can't get the customized area to look like the rest of the page - the labels are the wrong font and size, left justified, input fields right up against them, it's a mess.  Any hints?  Here's the working version of the section:

            <apex:actionregion >
                <apex:pageblocksection columns="2" id="SecuritySection" title="Security Information">
                    <apex:outputpanel >
                        <apex:pageblocksectionitem >
                            <apex:outputlabel for="generate" value="Generate random password" />
                            <apex:inputcheckbox id="generate" value="{!generatePassword}" class="dataCol first">
                                <apex:actionsupport event="onclick" action="{!changeGenerate}" rerender="ForcePasswordChange, EnterPassword" status="generateChangeStatus" />
                                <apex:actionsupport event="onClick" action="{!changeGenerate}" rerender="ForcePasswordChange, EnterPassword" status="generateChangeStatus" />
                                <apex:actionsupport event="onchange" action="{!changeGenerate}" rerender="ForcePasswordChange, EnterPassword" status="generateChangeStatus" />
                                <apex:actionsupport event="onChange" action="{!changeGenerate}" rerender="ForcePasswordChange, EnterPassword" status="generateChangeStatus" />
                            </apex:inputcheckbox>
                        </apex:pageblocksectionitem>
                    </apex:outputpanel>
                    <apex:outputpanel id="ForcePasswordChange">
                        <apex:pageblocksectionitem >
                            <apex:outputlabel for="forcechangepassword" value="Must change password on first login" />
                            <apex:inputcheckbox id="forcechangepassword" value="{!forceChangePassword}" class="dataCol first" />
                        </apex:pageblocksectionitem>
                    </apex:outputpanel>
                    <apex:outputpanel id="EnterPassword">
                        <apex:outputpanel id="renderPasswordField" rendered="{!NOT(generatePassword)}">
                            <apex:pageblocksectionitem >
                                <apex:outputlabel for="password" value="Use this password" />
                                <apex:inputsecret id="password" value="{!password}" class="dataCol last" />
                            </apex:pageblocksectionitem>
                        </apex:outputpanel>
                    </apex:outputpanel>
                    <apex:actionstatus id="generateChangeStatus" starttext="Changing security options..." stoptext="" />
                </apex:pageblocksection>
            </apex:actionregion>