Skip to content

Instantly share code, notes, and snippets.

@tyoshikawa1106
Created May 3, 2013 14:13
Show Gist options
  • Save tyoshikawa1106/5509339 to your computer and use it in GitHub Desktop.
Save tyoshikawa1106/5509339 to your computer and use it in GitHub Desktop.
2つのページと同一コントローラーサンプル
public with sharing class SearchController {
public List<Account> accounts {get; set;}
public SearchController() {
this.accounts = new List<Account>();
}
public void doSearch() {
this.accounts = [select Id,Name from Account limit 200];
}
public PageReference doClick() {
return Page.ViewPage.setRedirect(false);
}
}
<apex:page controller="SearchController" title="SearchPage" showHeader="true" sidebar="false" id="page">
<apex:form id="form">
<apex:pageBlock id="block">
<apex:pageBlockButtons >
<apex:commandButton value=" Search!! " title=" Search!! " action="{!doSearch}" reRender="form" />
<apex:commandButton value=" Click!! " title=" Click!! " action="{!doClick}" rendered="{!accounts.size > 0}" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!accounts}" var="item">
<apex:column headerValue="{!$ObjectType.Account.Fields.Name.Label}">
<apex:outputText value="{!item.Name}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page controller="SearchController" title="ViewPage" showHeader="false" sidebar="false" id="page">
<apex:form id="form">
<apex:pageBlock id="block">
<apex:pageBlockTable value="{!accounts}" var="item">
<apex:column headerValue="{!$ObjectType.Account.Fields.Name.Label}">
<apex:outputText value="{!item.Name}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment