1

I have a two command buttons that are able to save a record. One button fully submits the record and sends it to the edit view. The other save button will update the record if there is anything the user would like to change. I want to make it so the update button only appears in the edit view page, and the submit button shows in the initial creation of the new record to be submitted.

Page

    <apex:pageBlockSection id="buttonSection">
        <apex:pageBlockSectionItem >
            <apex:outputPanel id="buttonPanel">
                <div align="right">
                    <apex:commandButton value="UPDATE" action="{!pageUpdate}" />
                    <apex:commandButton value="Save & Submit Request" action="{!SaveAndSubmit}" reRender="msgs, buttonPanel" status="AjaxStatus" id="btnSubmit" rendered="{!not(inSubmissionProcess)}"/>
                    <apex:actionStatus id="AjaxStatus" onstart="DisableButton()" onstop="EnableButton()"></apex:actionStatus>
                    <apex:commandButton value="Cancel" immediate="true" html-formnovalidate="formnovalidate" action="{!Cancel}"/>  
                </div>
            </apex:outputPanel>
        </apex:pageBlockSectionItem>
    </apex:pageBlockSection>

Controller

public Boolean getInSubmissionProcess() {

        if(inSubmissionProcess == null) {

            if(cardRequest.ID == null) {

                inSubmissionProcess = false;

            }

            else {

                inSubmissionProcess = true;

            }

        }

        return inSubmissionProcess;

    }

What must I do differently to have the update button show on the edit page, and the submit button show on the record creation page?

0

Your lazy load of the boolean is causing it to not update if cardRequest.ID changes. One it is set to false it will never update to true cause it is no longer null

Maybe the solution is simply changing to:

public Boolean getInSubmissionProcess() {

            if(cardRequest.ID == null) {
                inSubmissionProcess = true;
            }
            else {
                inSubmissionProcess = false;
            }
        return inSubmissionProcess;
    }

Modified return value based on your comments below

Here is a full example for you to give a try:

Class

public class myExample{

    public boolean iHaveRan = false;
    public boolean shouldIRender;

    public boolean getshouldIRender(){

        if(iHaveRan == false)
            shouldIRender = true;
        else
            shouldIRender = false;

        return shouldIRender;


    }

    public void IHaveBeenClicked(){
        iHaveRan = true;
    }


}

You technically do not even need the additional properties and is can be shortened to

public class myExample{

    public boolean iHaveRan = false;

    public boolean getshouldIRender(){

        return !iHaveRan; //In your case it would be cardRequest.Id != null


    }

    public void IHaveBeenClicked(){
        iHaveRan = true;
    }


}

Page

<apex:page controller="myExample">


    <apex:form id="theForm">

        <apex:commandButton action="{!iHaveBeenClicked}" rerender="theForm" rendered="{!shouldIRender}" value="ClickMe"/>

        <apex:outPutText value="I Have Been Clicked" rendered="{!!shouldIRender}"/>

    </apex:form>



</apex:page>
  • According to your code you are basing the true or false off of the fact that cardRequest.ID is null or not. I cannot say what your logic should be as I do not know what you are trying to do other than that. if the cardRequest.ID is null InSubmissionProcess will be false otherwise it will be true. Maybe you should switch them if you want it to be true when cardRequest.ID is null – Eric Apr 12 '17 at 19:53
  • @Mr.HelpMe - Well if you have rendered={!inSubmissionProcess} and it is not rendering then the value if FALSE. If you want it to be TRUE then change the way you set the value of the variable. seems to me you want it to be TRUE when the Id is Null which means your getter is set up to return the incorrect values so flip the true and false returns around. This is in addition to the lazy loading issue – Eric Apr 12 '17 at 20:42
  • 1
    Remember when we talked about asking a good question? Since the question relates to what the definition of inSubmissionProcess is a paragraph about how you want to determine if it should be true or not would have been helpful and prevented this discussion. As it stands all we have to go by is what is in your code when it relates to what you wanted returned – Eric Apr 12 '17 at 20:44
  • Ok, I am going to work up and example to show you it is working, then you can adapt as needed. Maybe that will help. give me a few minutes – Eric Apr 12 '17 at 20:46
  • @Mr.HelpMe - full working example for you to see that it is working as expected. And don't post code in comments as it is completely unreadable – Eric Apr 12 '17 at 20:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.