+ Start a Discussion
Prasanthi BPrasanthi B 

Method call on a command button is not working

Hi,

 

My controller class is having two actions. One is search based on a picklist value. Other one is command button action based on the result of first action.

 

Command button action(second action) is not getting invoked when the first action is occured.

 

Indepently it is working fine. Only the command button action without the first action is working.

 

But these two should be dependent actions.

 

Please advise on the requirement

 

VFCODE:

<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>
<apex:actionRegion >
<apex:outputLabel value="Select Region of the user: " for="viewlist" />
<apex:inputField id="startMode" value="{!User.Region__c}">
<apex:actionsupport event="onchange" action="{!doSearch}" rerender="theTable" />
</apex:inputfield> 
</apex:actionRegion>
           <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:inputField value="{!User.ManagerId}" rendered="{!size}"/> -->
<apex:inputField value="{!User.ManagerId}" styleClass="StyleCSS"/>
<apex:actionRegion >
<apex:commandButton value="UpdateManager" Id="Update" action="{!getselected}" styleClass="StyleCSS"/>
</apex:actionRegion>
    </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) 
   { 
     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()
   { 
        User u1=(User)stdCtrl.getrecord();
        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 boolean getsize()
  {
    Integer size=results.size();
     IF(size>0)
      return True;
     Else 
      return false;
    
  } 
  Public Pagereference UpdateManager()
   {
        return null;
   }
     
   public List<User> getResults() 
    {
        return results;
    }
 
 }

 Update manager button action is not working in the page.

 

Please advice.

 

Thanks,

Santhi.

bob_buzzardbob_buzzard

I have to say this looks like the same problem you posted earlier, just worded differently.

 

Are you expecting the commandbutton action to fire as part of the input field change?

Prasanthi BPrasanthi B

Hi,

 

My exact requirement is user should search users belong to one particular region(picklist for region field). And one lookup field will be provided, there he can select any manager name. Out of the search results for one particular region, he should update manager field for some selected users only.

 

The problem is, search action is working fine when the region is selected and list of users are displayed in a table.

 

If some of the users are selected using check boxes, and updatemanager command button is clicked, the action is not getting invoked.

 

I tested by putting only debug statement in the controller for commandbutton action. When only the button is clicked, it is working fine. But when the region is selected and then the updatemanager is clicked, then the methos is not getting invoked.

 

Hope i'm clear.

 

Thanks.

 

 

bob_buzzardbob_buzzard

In your page you have backed the checkbox with User.ManagerId - that is an id field so I'd imagine there is an error trying to save the true/false value to that field.

 

Add an apex:pagemessages component to the page and that will show you if there are any errors being encountered.

Prasanthi BPrasanthi B

I haven't reached till the checkbox selection yet. Even the 'system.debug' is also not reached in case the first action is executed.

 

I just put the system.debug in my controller for the command button. If the button is clicked individually it is invoked.

 

If the picklist value is selected and then clicked on the command button, then the method is not getting invoked.

bob_buzzardbob_buzzard

So this is the same issue that you have already raised in a separate thread?

Prasanthi BPrasanthi B

Yes. The issue is still not resolved.

bob_buzzardbob_buzzard

I understand that, but simply reposting the same issue to multiple threads won't help - in fact its likely to reduce responses.

bob_buzzardbob_buzzard

Anyway, I think the issue is still the way that you are backing the checkbox inputs - change these so that they are backed by a field of the appropriate type - checkbox - and I reckon it will work.

sfdcttslsfdcttsl

 

I worked on and it got resolved.

 

Everyone may not see the same thread and provide resolution. Hence I reposted it in another thread. No need to mention it explicitly.