You need to sign in to do that
Don't have an account?
Luffy Carl_op
Is there a way to know which button i click between two?
There are two buttons in my Visualforce Page.Show All reports, and Show This Month reports.And a function,which will update single record in page. I want to refresh the list after updating one record.But I don't know which one button was clicked, or to say, which list is in this page.How can I judge it? thanks.
===========================================
public with sharing class ManagePageCtrl{ public List<SelectOption> optionMonth {get; set;} public String selectedmonth {get; set;} public List<WorkTime__C> relist {get; set;} public ManagePageCtrl(){ relist = new List<WOrkTime__C>(); optionMonth = new List<SelectOption>(); optionMonth.add(new SelectOption('0' , '-none-')); optionMonth.add(new SelectOption('12', 'December')); optionMonth.add(new SelectOption('11', 'November')); optionMonth.add(new SelectOption('10', 'October')); optionMonth.add(new SelectOption('9' , 'September')); optionMonth.add(new SelectOption('8' , 'August')); optionMonth.add(new SelectOption('7' , 'July')); optionMonth.add(new SelectOption('6' , 'June')); optionMonth.add(new SelectOption('5' , 'May')); optionMonth.add(new SelectOption('4' , 'April')); optionMonth.add(new SelectOption('3' , 'March')); optionMonth.add(new SelectOption('2' , 'February')); optionMonth.add(new SelectOption('1' , 'January')); } public pageReference showWorks(){ if(selectedmonth == '0'){ relist = [select Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c where WorkerRef__r.Name = :selectedsubordinate And CALENDAR_MONTH(BeginTime__c) = :Date.Today().Month() Order by BeginTime__c DESC ]; }else{ relist = [select Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c where WorkerRef__r.Name = :selectedsubordinate And CALENDAR_MONTH(BeginTime__c) = : ]; } if (relist.isEmpty()) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This Employee has not ATTENDANCE INFORMATION this month.')); return null; } return null; } public pageReference showAllWorks(){ relist = [select Name, BeginTime__c, WorkerRef__r.Name, EndTime__c, Note__c from WorkTime__c where WorkerRef__r.Name = :selectedsubordinate Order by BeginTime__c DESC ]; if (relist.isEmpty()) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'This Employee has not ATTENDANCE INFORMATION.')); return null; } return null; } public pageReference saveSingleRecord(){ string recId = ApexPages.currentpage().getParameters().get('myRecId'); WorkTime__c mySingleRec; for (WorkTime__c c : relist) { if (recId == c.Name) { mySingleRec = c; break; } } if (mySingleRec != null) update mySingleRec; //It's it, How can i judge which one button was clicked and return showAllWorks() or showWorks()? return showAllWorks(); } }
===========================================
<apex:page controller="ManagePageCtrl" tabStyle="WorkTime__c" sidebar="false"> <apex:pageBlock title="Hello, {!$User.LastName}! W id="thePageBlock"> <apex:pageMessages /> <apex:commandButton value="Show All Reports" action="{!showAllWorks}"/> Month:<apex:selectList multiselect="false" value="{!selectedmonth}" size="1" style="width:230px"> <apex:selectOptions value="{!optionMonth}"></apex:selectOptions> </apex:selectList> <apex:commandButton value="Show This Month Reports" action="{!showWorks}" /> <apex:actionStatus id="loadingStatus" startText="Please Wait. Processing..." /> <apex:pageBlockTable value="{!relist}" var="rec" id="myTable"> <apex:column headerValue="ID" value="{!rec.Name}" /> <apex:column headerValue="LoginTime" value="{!rec.BeginTime__c}" /> <apex:column headerValue="LogoutTime" value="{!rec.EndTime__c}" /> <apex:column headerValue="Notes"> <apex:inputText value="{!rec.Notes__c}" /> </apex:column> <apex:column headerValue="Update"> <apex:commandLink action="{!saveSingleRecord}" rerender="thePageBlock" status="loadingStatus"> Update <apex:param value="{!rec.Name}" name="myRecId" /> </apex:commandLink> </apex:column> </apex:pageblocktable> </apex:pageBlock> </apex:form> </apex:page>
If that's not enough distinction, the easiest way would to be a boolean variable in your controller (or enum or something) that you set from either of those methods, so that you know which view you're looking at when it comes time to update a record.
All Answers
If that's not enough distinction, the easiest way would to be a boolean variable in your controller (or enum or something) that you set from either of those methods, so that you know which view you're looking at when it comes time to update a record.