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
Prasanthi BPrasanthi B 

Command button execution not happening for the second time

Hi,

 

I have a search button in my visual force page. When a dropdown value is selected and clicked on search button, query will be executed and results are displayed. But for the second time dropdown value is changed and search button is clicked, the result set is not getting changed. Whatever is returned in the first click action is only getting displayed.

 

Can anyone please clarify on this thing.

 

Thanks,

Santhi.

bob_buzzardbob_buzzard

Can you post your code?

Prasanthi BPrasanthi B

VFPAGE:

 

<apex:page StandardController="User" Extensions="UserData" tabstyle="User" sidebar="false">
  <apex:form >
  <apex:pageBlock title="Select Users" id="USERSLIST" mode="edit">
    <h1>Update Sales Co-ordinator for the users in Particular Region</h1>
  <br></br>
  <br></br>
   Select Region of the user:     
   <apex:inputField id="startMode" value="{!User.Region__c}" />
   <br></br>

 <!--THIS SEARCH BUTTON IS NTO GETTING EXECUTED FOR THE SECOND TIME-->        
   <apex:commandButton action="{!doSearch}" value="Search"/>          <br></br> 
   <apex:pageBlockTable value="{!results}" var="t" id="table">
        <apex:column >
          <apex:inputCheckbox value="{!User.ManagerId}" id="checkedone">
          </apex:inputCheckbox>
        </apex:column>
        <apex:column value="{!t.Name}"/>
        <apex:column value="{!t.Email}"/>
        <apex:column value="{!t.Region__c}"/>
        <apex:column value="{!t.Manager__c}"/>      
  </apex:pageBlockTable>
 

       
    </apex:pageblock>    
  </apex:form>
  </apex:page>

 

CONTROLLER:

 

public class UserData {
List<Userwrapper> userList {get;set;}
PUBLIC String usr{get;set;}
PUBLIC List<selectOption> usrs;
List<User> results=new List<User>();
List<User> results1=new List<User>();
public User user;
public UserData(ApexPages.StandardController controller)
   {
     this.user = (User)controller.getrecord();
   }
       
  public Pagereference doSearch()
     {
      results = [select Name,Region__c,Email,LanguageLocaleKey,Manager__c from User Where Region__c =:User.Region__c];
      system.debug('USERSLISTFOR REGION$$$$'+results);
      return null;
     }
  public List<Userwrapper> XXX() 
  {
     if(userList == null) {
      userList = new List<Userwrapper>();

     for(User u:results1)
      {
        userList.add(new Userwrapper(u));
      }
      system.debug('****ADDEDUSERS****'+userlist);
       }
       return userList;

  }
    
   Public PageReference getSelected()
   { 
         system.debug('ENTERED INTO SELECTED');
        List<User> selectedUsers = new List<User>();
        for(userwrapper usrwrapper : XXX())
        {
          if(usrwrapper.selected == true)
          {
           selectedusers.add(usrwrapper.wuser);
          }
        }
        system.debug('@@@SELECTEDUSERs@@@:'+selectedusers); 
        return null;
  }
  
   Public Pagereference UpdateManager()
   {
        return null;
   }
      
   public List<User> getResults()
    {
        return results;
    }
 
 }

bob_buzzardbob_buzzard

Do you see the debug in the action method - i.e. does the method get called, but the results don't change?

bob_buzzardbob_buzzard

Actually, I think I've seen something like this before.  I seem to recall that if I created a reference to the record from the standard controller, that seemed to become decoupled when the value on the page changed.  Essentially I had a snapshot.

 

I ended up changing my code to the following:

 

ApexPages.StandardController stdCtrl;

public UserData(ApexPages.StandardController controller)
{
    stdCtrl=controller;
}

public Pagereference doSearch()
{
   User u=(User)controller.getrecord();
   results = [select Name,Region__c,Email,LanguageLocaleKey,Manager__c from User Where Region__c =:u.Region__c];
   system.debug('USERSLISTFOR REGION$$$$'+results);
   return null;
}

 

Prasanthi BPrasanthi B

Hi,

 

Thanks for the reply.

 

But unfortunately, still the page is not getting refreshed.

Prasanthi BPrasanthi B

Updated the code. Pls check.

 

VFPAGE:

 

<apex:page StandardController="User" Extensions="UserData" tabstyle="User" sidebar="false">
  <apex:form >
  <apex:pageBlock title="Select Users" id="USERSLIST" mode="edit">
    <h1>Update Sales Co-ordinator for the users in Particular Region</h1>
  <br></br>
  <br></br>
   Select Region of the user:    
   <apex:outputLabel value="Select Region: " for="viewlist" />
<apex:inputField id="startMode" value="{!User.Region__c}">
<apex:actionsupport event="onchange" immediate="false" action="{!doSearch}" rerender="theTable" />
</apex:inputfield><br></br><br></br>  
  
           <br></br>
   <apex:pageBlockTable value="{!results}" var="t" id="theTable">
        <apex:column >
          <apex:inputCheckbox value="{!User.ManagerId}" id="checkedone">
          </apex:inputCheckbox>
        </apex:column>
        <apex:column value="{!t.Name}"/>
        <apex:column value="{!t.Email}"/>
        <apex:column value="{!t.Region__c}"/>
        <apex:column value="{!t.Manager__c}"/>     
  </apex:pageBlockTable>
 

      
    </apex:pageblock>   
  </apex:form>
  </apex:page>

 

Controller:

 

public class UserData {
List<Userwrapper> userList {get;set;}
PUBLIC String usr{get;set;}
List<User> results=new List<User>();
public User user;
public ApexPages.StandardController stdCtrl;
public UserData(ApexPages.StandardController controller)
   {
     //this.user = (User)controller.getrecord();
     stdCtrl=controller;

   }  
    
        
  public Pagereference doSearch()
     {
      //results = [select Name,Region__c,Email,LanguageLocaleKey,Manager__c from User Where Region__c =:User.Region__c];
      User u=(User)stdCtrl.getrecord();
      results = [select Name,Region__c,Email,LanguageLocaleKey,Manager__c from User Where Region__c =:u.Region__c];

      system.debug('USERSLISTFOR REGION$$$$'+results);
      return null;
     }
  public List<Userwrapper> XXX() 
  {
     if(userList == null) {
      userList = new List<Userwrapper>();

     for(User u:results)
      {
        userList.add(new Userwrapper(u));
      }
      system.debug('****ADDEDUSERS****'+userlist);
       }
       return userList;

  }
    
   Public PageReference getSelected()
   {
       // String id=ApexPages.CurrentPage().getParameters().get('id');
        system.debug('ENTERED INTO SELECTED');
        List<User> selectedUsers = new List<User>();
        for(userwrapper usrwrapper : XXX())
        {
          if(usrwrapper.selected == true)
          {
           selectedusers.add(usrwrapper.wuser);
          }
        }
        system.debug('@@@SELECTEDUSERs@@@:'+selectedusers); 
        return null;
  }
  
   Public Pagereference UpdateManager()
   {
        return null;
   }
      
   public List<User> getResults()
    {
        return results;
    }
 
 }

 

 

 

Rahul SharmaRahul Sharma

 

You can try adding some page messages for debugging.

asish1989asish1989

Hi

    Try by adding immediate is true . and let me know wheather it works or not 

          <apex:actionsupport event="onchange" immediate="true" action="{!doSearch}" rerender="theTable" />

 

 

 

 

Did this post answers your question if so please mark it solved

 

Thanks

asish

bob_buzzardbob_buzzard

immediate=true will discard any changes that the user has made, so that won't help.  

bob_buzzardbob_buzzard

What do you see if you add some debug to the doSearch method to dump out the u:Region__c value?