You need to sign in to do that
Don't have an account?

Code to dynamically disable button prevents page refresh
I have written a visualforce page that consists of a data table listing a collection of a custom object. I added a button that creates a new custom object which is then added to the list as the page is refreshed.
An additional requirement is that the user should only be allowed to push this button once a month, so, I added a piece of code to the controller to do just that and it's called like so:
<apex:commandButton action="{!NewRecruit}" value="Recruit DD" id="btnRecruitDD" disabled="!DisableRecruitment}"/>
When the form loads, the button is disabled correctly if the most recent object is less than one month old.
Problem: If there is no object of less than one month old, the button is enabled, the user presses the button and a new object is created. At this point, no page refresh takes place, so, the button is still enabled and the new object has not been appended to the list. If I hit refresh, the new object is listed and the button is disabled.
Does anyone have any idea how I can get the page to refresh in this instance?
It might be better to use a trigger or maybe even a custom validation rule to enforce the rule. Just disabling the button is pretty weak as far as security goes. That way even if by some fluke the button is enabled the action won't be permitted.
Scott
That's great :) I didn't know you had a trigger in place. I was just suggesting that it would ensure that if by some fluke people managed to make the button active in the html they still wouldn't be able to perform the action.
You could put the button inside a panel and rerender it after the action is executed. Also the code you posted is missing the opening { in the disabled attribute.
<apex:outputPanel id="myButtons">
<apex:commandButton action="{!NewRecruit}" value="Recruit DD" id="btnRecruitDD" disabled="{!DisableRecruitment}" rerender="mybuttons"/>
</apex:outputPanel>
Scott