1. ItemEdit apex:
public with sharing class YUT_ItemEditController {
private ApexPages.StandardController controller {get; set;}
public List<Account> searchResults {get;set;}
public string searchText {get;set;}
// standard controller - could also just use custom controller
public YUT_ItemEditController(ApexPages.StandardController controller) { }
// fired when the search button is clicked
public PageReference search() {
String qry = 'SELECT Id, YUT_Author__c FROM Account ' +
'where name LIKE \'%'+searchText+'%\' order by name';
searchResults = Database.query(qry);
return null;
}
// fired when the save records button is clicked
public PageReference save() {
try {
update searchResults;
} Catch (DMLException e) {
ApexPages.addMessages(e);
return null;
}
return new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
}
// takes user back to main record
public PageReference cancel() {
return new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
}
}
2. VF Page:
<apex:page standardController="Account" extensions="YUT_ItemEditController">
<apex:sectionHeader title="{!Account.Name}" subtitle="Edit Records"/>
<apex:form >
<apex:pageBlock mode="edit" id="block">
<apex:pageBlockButtons location="both">
<apex:commandButton action="{!save}" value="Save Records"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageMessages />
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel for="searchText">Keyword</apex:outputLabel>
<apex:panelGroup >
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection><br/>
<apex:actionStatus id="status" startText="Searching... please wait..."/>
<apex:pageBlockSection title="Search Results" id="resultsBlock" columns="1">
<apex:pageBlockTable value="{!searchResults}" var="item" rendered="{!NOT(ISNULL(searchResults))}">
<apex:column value="{!item.id}" headerValue="Item" width="100"/>
<apex:column headerValue="YUT_Author__c" width="200">
<apex:inputField value="{!item.YUT_Author__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
3. 实现效果: