0

I need to know how to get 2 actions to trigger from a single event. I tried using oncomplete but this still seemed to not work.
I am hiding a command button and graphs until a certain event. After a user selects a value from the picklist the command button is made visible and the ID from the Account is stored for use with the graphs. When the command button is selected the graphs are made visible.

Here the Class.

Public with sharing class AccountDealerController {
    public Id selectedAccId{get;set;} 

    public String fieldValue {get; set;}
    public String selectedFields{get;set;}
    public boolean showPanel { get; set; } //to show and hide graph
    public boolean showButton { get; set; } //to show and hide button

    public AccountDealerController()
    {
        showButton = false; // onload don't display button and panelGrid
        showPanel = false;
    }

    public void commandButtonClick() {
        showPanel = true; //on click of button show panel
    }

    public void valueSelectedShowButton() {
        showButton = true;// after selecting value f
    }



    public List<SelectOption> getAccountNames() {
        List<SelectOption> accOptions= new List<SelectOption>();
        system.debug(selectedAccId);
        accOptions.add( new SelectOption('','--Select--'));
        for(Account acc : [select Id,name from Account Where Partner_Type__c='Dealer' AND YTD_Indirect_Sales_Totals__c > 10000 AND OwnerId =:UserInfo.getUserid() ] ) {
            accOptions.add(new SelectOption(acc.Id,acc.name));
        }
        return accOptions;
    }

    public void passValueToController(){
        fieldValue = selectedFields;
    }

}

here is the VF page

<apex:page standardStylesheets="true"  showHeader="True" sidebar="true" Controller="AccountDealerController" >

    <apex:form >
        <apex:pageBlock title="Select an Account">

            <apex:outputpanel id="Outputtext">
                <apex:outputtext value="{!fieldValue}"/>
            </apex:outputpanel>

            <apex:selectList value="{!selectedFields}" size="1">
                <apex:actionSupport event="onchange"  reRender="buttonId" action="{!valueSelectedShowButton}"/>     <!-- after selecting value in picklist set showButton to true. rerender pageBlock "buttonId" so button will be rerendered-->         
                <apex:selectOptions value="{!AccountNames}" />
            </apex:selectList><br/><br/>  
            <apex:outputText value="{!fieldValue}" label="You have selected:" id="values" /> <!--  used to verify Id -->           
        </apex:pageBlock>  
        <apex:pageBlock id ="buttonId">
            <apex:commandButton value="See Charts" rendered="{!showButton}" action = "{!commandButtonClick}" reRender = "chart"/><!--onclick button set  showPanel to true
                                                        and rerender outputPanel(chart) so panelGrid will be rerendered-->
        </apex:pageBlock>

        <apex:outputPanel id="chart">
            <apex:outputPanel rendered="{!fieldValue}">

                <apex:panelGrid columns="3" id="theGrid" rendered = "{!showPanel}">
                    <analytics:reportChart showRefreshButton="false"  reportId="AAAAAA" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="small"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false"  reportId="AAAAAA" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="small"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false"  reportId="AAAAA" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="small"> </analytics:reportChart>
                    <analytics:reportChart showRefreshButton="false"  reportId="AAAAAA" filter="[{column:'ACCOUNT_ID',operator:'equals',value:'{!fieldValue}'}]" size="small"> </analytics:reportChart>
                </apex:panelGrid>

            </apex:panelGrid>
            </apex:outputPanel>
        </apex:outputPanel>   
    </apex:form>
</apex:page>

Would it be better to disable the command button until a value is selected? I just do not want to show the graphs with any data.

  • I'm having a hard time trying to figure out exactly what you're asking here. What is the problem you are trying to solve? What isn't working? – Derek F Aug 3 '17 at 13:02
  • If I run the code as is. The Id of the account that was selected from the picklist is never obtained so the graphs never render. The reason for this is because when a user selects an Account from teh picklist the action associated with this event is action="{!valueSelectedShowButton}". But I also need this action action="{!passValueToController}" to trigger so that the Account Id is available for me to pass into the graphs. Right now I get accounts in the picklist. When an Account is selected the command button appears. When the command button is selected I get no graphs. – Michael Aug 3 '17 at 13:46
1

The simplest solution seems to be to just combine the two methods:

public void valueSelectedShowButton() {
    showButton = true;// after selecting value f
    fieldValue = selectedFields;
}

I'd probably recommend creating a single "handler" method and running your methods from there though, this way you keep the logic in the methods separate and reusable:

Updated Apex:

public void accountNameChanged(){
    valueSelectedShowButton();
    passValueToController();
}

Updated Visualforce:

<apex:selectList value="{!selectedFields}" size="1">
    <apex:actionSupport event="onchange"  reRender="buttonId" action="{!accountNameChanged}"/>   
    <apex:selectOptions value="{!AccountNames}
</apex:selectList>
  • Thank you for the reply. I modified where some of the code was in the VF page because I was using reRender to show the Block. So reRender="buttonId" would allow the Command Button to show but the AccountId was never getting populated in my field. But on clicking the button the reports do not show. Do I need to put the reports in a pageblock instead of a panel? – Michael Aug 3 '17 at 16:41

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.