function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jamz_2010Jamz_2010 

CommandButton not refresh

Hi all,

 

Is there any way of making a commandbutton run some apex code but not refresh on button click?

 

Cheers

 

James 

Best Answer chosen by Admin (Salesforce Developers) 
WesNolte__cWesNolte__c

Hey

 

You might want to do something like this,

 

<apex:selectlist...>

 <apex:selectOptions.../>

</apex:selectlist>

 

 <apex:outputPanel id="selected"> <!-- I use this to wrap any rerendered areas, mostly for readability -->

 

<apex:selectlist...>

 <apex:selectOptions.../>

</apex:selectlist>

 

</apex:outputPanel>

 

<apex:commandButton action="{!myAction}" rerender="selected" ... /> <!-- calls my action method then rerenders the second selectlist -->

 

Does this help at all?

 

Wes

 

 

All Answers

bob_buzzardbob_buzzard

If you want to execute apex code, the page will have to be submitted back to the controller. You can restrict how much of the page is refreshed using the rerender attribute.   You can also limit the information sent back to the controller using action regions.

 

If you post a bit more detail on what you are trying to achieve we'll be able offer more help. 

Jamz_2010Jamz_2010

Sure, sorry for providing so little info.

 

Basically, I have a page that gets passed some record ids in the url which are then retrieved when the constructor is ran. I then have a selectList that shows the current options, a button to add the options and another selectList that contains the options that have been selected. What I want to do is be able to click the button to add a selected option to the list but not refresh the entire page when I do this (just rerender the selectList).

 

Is this possible?

 

Thanks for the help

 

James 

WesNolte__cWesNolte__c

Hey

 

You might want to do something like this,

 

<apex:selectlist...>

 <apex:selectOptions.../>

</apex:selectlist>

 

 <apex:outputPanel id="selected"> <!-- I use this to wrap any rerendered areas, mostly for readability -->

 

<apex:selectlist...>

 <apex:selectOptions.../>

</apex:selectlist>

 

</apex:outputPanel>

 

<apex:commandButton action="{!myAction}" rerender="selected" ... /> <!-- calls my action method then rerenders the second selectlist -->

 

Does this help at all?

 

Wes

 

 

This was selected as the best answer
Jamz_2010Jamz_2010

Thanks, that did the job :) 

salesforcemicky125salesforcemicky125
Hi Bob,

My requirement is When i click on the command button, a new page block will got opened , but the thing before i click on the command button i have selected few records using the search button and i have selected all the records which are displayed through the search button.

When i click on the Continue button as per my requirement a new  pageblock will get opened , but at the same time it is refreshing the whole page because of refreshing the whole page the records that i have selected before the continue button click will all get lost ,Which should not happen.

The records are getting from the Contact object and we are using the action support for this , could you please help me by making few change by looking into my code.

it would be great help ful for me.

This is my VF Page

<apex:page standardController="Recruiting_Event__c" extensions="MassEmailEvent" id="pageid" sidebar="true" showHeader="true" tabStyle="Contact">

<style>
.mmSubheader {
background-color= #E2E3E5;
font size: 1em;
margin: 18px 0 7px;
padding: 4px 9px;
color: black;
font-weight:bold;
}
.label{
padding:3px;
color: #222222;font-family: Arial,Helvetica,sans-serif;
}
.he1 {

     font-weight: bold;
     -moz-user-select: text;
    font-family: 'Arial','Helvetica',sans-serif;
    font-size: 100%;
    line-height: normal;
    border-style: none solid none none;
    border-width: 0 1px 0 0;
    padding: 2px 0 3px;
    vertical-align: baseline;
     border-left-color: #EEEEEE;
    border-right-color: #D0D0D0;
    border-left: 1px solid;
    border-right: 1px solid;
    -moz-user-focus: normal;
    outline: medium none;
    text-align: left;
}
</style>
<script type="text/javascript">
document.getElementsByTagName("input").checked;
    function checkAll(cb,cbid)
        {
            var inputElem = document.getElementsByTagName("input");                   
            for(var i=0; i<inputElem.length; i++)
            {           
                 if(inputElem[i].id.indexOf(cbid)!=-1){                                      
                    inputElem[i].checked = cb.checked;
                }
            }
        }
</script>
<script language="javascript" type="text/javascript">
var pickListArray=[];
var campaignPickListArray=[];
function popUpLookUpWindow(url,col,val) {
      var colValue=document.getElementById(col).value;
      if(colValue!='None'){
      url=url+'&column='+colValue+'&val='+val;
    newwindow=window.open(url,'name','height=430,width=620,toolbar=no,resizable=yes,scrollbars=yes');
    if (window.focus) {newwindow.focus()}
    }
}
function closePopUp(){
   if (null!=newwindow)
    {
      newwindow.close();
    }
}
</script>
  <apex:form >
<apex:repeat value="{!pickListCol}" var="request">
        <script>
            pickListArray.push('{!request}');
        </script>
    </apex:repeat>
     <apex:repeat value="{!pickListCampaignCol}" var="list">
        <script>
            campaignPickListArray.push('{!list}');
        </script>
    </apex:repeat>
    <script>
   
function isPickList(selectedId,lookupId){

var val=document.getElementById(selectedId).value;
for (var i = 0; i < pickListArray.length; i++) {
// alert('pickListArray === ' + pickListArray[i]);
        if (pickListArray[i] ===val){
            document.getElementById(lookupId).style.display = "block";
            break;
            }else{
            document.getElementById(lookupId).style.display = "none";
            }
    }
}

function isCampaignPickList(selectedId,lookupId){
var val=document.getElementById(selectedId).value;
for (var i = 0; i < campaignPickListArray.length; i++) {
  // alert('campaignPickListArray=== ' + campaignPickListArray[i]);
        if (campaignPickListArray[i] ===val){
            document.getElementById(lookupId).style.display = "block";
            break;
            }else{
            document.getElementById(lookupId).style.display = "none";
            }
    }

}
  </script> <apex:sectionHeader subtitle="Mass Email"/>
<apex:pageBlock title="Step 1: Select email recipients">
<div class="mmSubheader">Select Event Name <apex:inputField value="{!eropty.Recruiting_Event__c}" id="crmcmpid">
  </apex:inputfield>
  
  <br></br>
  Attended <apex:inputField value="{!eropty.Attended__c}" id="crmcmpid1">
  </apex:inputfield>
  Attending <apex:inputField value="{!eropty.Attending__c}" id="crmcmpid2">
  </apex:inputfield>
Invited <apex:inputField value="{!eropty.Invited__c}" id="crmcmpid3">
  </apex:inputfield>
No Show <apex:inputField value="{!eropty.No_Show__c}" id="crmcmpid5">
  </apex:inputfield>
Not Attending <apex:inputField value="{!eropty.Not_Attending__c}" id="crmcmpid6">
  </apex:inputfield>
  No Response  <apex:inputCheckbox value="{!eropty.No_Response__c}" id="crmcmp1d7"/>

 
  <br></br>

</div> 

      <div class="mmSubheader" style="display:none">Choose Member Type to Search          </div>   
<div class="mmSubheader"></div>
 
    <apex:outputPanel id="criteria">
          <apex:actionstatus id="status" startText="Loading...">
             <apex:facet name="stop">
           
               <apex:outputPanel >
              
            
            <apex:commandButton action="{!go}" value="Search" reRender="searchProgress,results1,dTable" status="searchProgress" />
            <br/>
            <apex:actionStatus id="searchProgress">
                        <apex:facet name="start">
                            <table align="center" border="0">
                                <tr>
                                    <td style="vertical-align:middle;" align="center">
                                        <img src="{!$Resource.saveStatus}"/>
                                    </td>
                                </tr>
                            </table>
                        </apex:facet>
</apex:actionStatus>
              </apex:outputPanel>
         
            </apex:facet>
          </apex:actionstatus>
     </apex:outputPanel>
      <br/>
     <apex:pageBlockSection columns="1" >
     <script type="text/javascript">new MenuButton('MyMenu', false);</script>

    <apex:pageBlockTable id="dTable" value="{!contactList}" var="dat"  border="1" cellspacing="2px" width="100%" headerClass="he1" cellpadding="4px" columnsWidth="60px,150px,150px,150px,170px" >
     <apex:column ><apex:facet name="header">
<apex:inputCheckbox onclick="checkAll(this,'checkedone')"/>
</apex:facet>
<apex:inputCheckbox value="{!dat.selected}" id="checkedone"/></apex:column>
   <apex:column headerValue="First Name"  ><apex:outputField value="{!dat.con.FirstName}" rendered="{!IF(ISBLANK(dat.con.FirstName), 'false', 'true')}"/>
   </apex:column>
     <apex:column headerValue="Last Name" ><apex:outputField value="{!dat.con.LastName}" rendered="{!IF(ISBLANK(dat.con.LastName), 'false', 'true')}"/> 
      </apex:column>
     <apex:column headerValue="Title" ><apex:outputField value="{!dat.con.Title}" rendered="{!IF(ISBLANK(dat.con.Title), 'false', 'true')}"/>
     </apex:column>
     <apex:column headerValue="Account Name" ><apex:outputField value="{!dat.con.AccountId}" rendered="{!IF(ISBLANK(dat.con.AccountId), 'false', 'true')}"/> </apex:column>
     <apex:column headerValue="Email"  ><apex:outputField value="{!dat.con.Email}" rendered="{!IF(ISBLANK(dat.con.Email), 'false', 'true')}"/>
     </apex:column>
          </apex:pageBlockTable>
          </apex:pageBlockSection>
    
     &nbsp; &nbsp; <apex:commandLink action="{!previousResults}" value="Previous" reRender="emailTemplateBlock"/> &nbsp; | &nbsp; <apex:commandLink action="{!nextResults}" value="Next" reRender="dTable" />   
           
   <br></br><br></br>
</apex:pageBlock>
<apex:pageblock ><apex:commandButton action="{!Save}" value="Continue..." /></apex:pageblock>

        <apex:pageBlock title="Step 2: Select an email template" id="emailTemplateBlock" rendered="{!displaypblock}">
                Select Email Template Folder:
            <apex:selectList value="{!selectedEmailTemplateFolder}" multiselect="false" size="1">
                <apex:selectOptions value="{!emailTemplateFolderOpts}" />
                <apex:actionSupport event="onchange" action="{!refreshEmailTemplateSection}" rerender="emailTemplateBlock" />
            </apex:selectList>
            <br/><br></br>
            Select Email Template:
            <apex:selectList value="{!selectedEmailTemplate}" multiselect="false" size="1" >
                <apex:selectOptions value="{!emailTemplateOpts}" />
<apex:actionSupport event="onchange" action="{!refreshEmailTemplateSectionid}" rerender="emailTemplateBlock" />               
                            </apex:selectList>
             <apex:outputLink target="_blank" value="{!emailTemplateId}">   Preview</apex:outputLink>            <br/><br></br>
                      
<apex:commandButton action="{!SendEmail}" value="Send Email" rendered="{!if(emailTemplateOpts.size > 0, true, false)}"/>
    </apex:pageBlock>  </apex:form>
</apex:page>


Regards
Micky