You need to sign in to do that
Don't have an account?
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;
}
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:
- 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.
- I changed the onChange event of the apex:actionsupport to an onClick event.
- I added an extra outputpanel for the password input field, this to make sure that the 2nd outputpanel renders correctly.
- I added a rendered attribute to the 2nd outputpanel for the password input field
In your controller you will need to remove the following line of code to get it to work:I hope this helps! Happy coding!
Best regards,
Martijn Schwärzer
All Answers
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:
- 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.
- I changed the onChange event of the apex:actionsupport to an onClick event.
- I added an extra outputpanel for the password input field, this to make sure that the 2nd outputpanel renders correctly.
- I added a rendered attribute to the 2nd outputpanel for the password input field
In your controller you will need to remove the following line of code to get it to work:I hope this helps! Happy coding!
Best regards,
Martijn Schwärzer
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!
<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>