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
kkurahashikkurahashi 

Custom List Contollerを使ったページング表示がうまく機能しない

お世話になります。

 

PDF版の”Visualforce Developer's Guide"の中でpage 62の最後から掲載されているリストを試しているのですが、

ページングが機能しません。

 

Custom List ControllerでデータのListを作って、VisualforceではcommandLinkでactionに!previousと!nextを

バインドしています。ページは1画面20行に区切られて表示されますが、Prev/Nextのリンクをクリックしても何も

起こりません。

 

同じサンプルをお試しになった方はいらっしゃいますか?

 

問題の解決方法をご存知の方、ご教示いただければ幸いに存じます。 

Best Answer chosen by Admin (Salesforce Developers) 
ue123ue123

previous、nextはStandardSetControllerのメソッドです。

(StandardSetControllerクラスについてはForce.com Apex Code Developer's Guideを参照してください。)

 

apex:dataListにバインドされているaccountPaginationに対してprevious、nextする場合は、accountPaginationが参照している

StandardSetController(accountRecords)に対して処理を要求しますので、

 

action="{!accountRecords.previous}"、action="{!accountRecords.next}"

 

になります。

 

All Answers

kkurahashikkurahashi

解決ではないのですが…とりあえずVisualforce上の<APEX:page~からextensionsを削除し、

<APEX:dataList~のvalueをaccountsに変更するとページングは機能するようになります。

 

もちろん、APEXコードでの検索条件は無効になります…当たり前ですが。

 

 わからないのは、例えば動いている状態でも動いていない状態でもVisualforce上で

actionにバインドした!previousのスペルを変更すると 「不明なメソッド」になります。

 

なので、このactionが何らかのメソッドと関連付けられているのは間違いないようですが…。

 

なお、getterでreturnのかわりに代入文に直しても状況は変わりません。

 

さて次に何を試したものか…。 

timatima

こんにちわ。

できれば実際に書いたVFPageとControllerのソースをあげてみてください。

なかなか想像しにくいところがありますし、

以前にやった方も、ソースを見れば思い出すかと思います。

 

kkurahashikkurahashi

ご指摘ありがとうございます。そうですね、おっしゃる通りです。

 

…で…insert codeで貼ろうとしているのですが…改行が処理されず修正中です。

 

試行錯誤中のものをご覧になった方、申し訳ございません。 

 

#テキストモードだとemoticonに自動変換されてしまうし…

03-30-2010 09:01 AM
にkkurahashiにより編集されたメッセージ
03-30-2010 09:01 AM
にkkurahashiにより編集されたメッセージ
kkurahashikkurahashi

ソースを貼ります。

 

#Salesforce.com, "Visualforce Developer's Guide" page 62-63掲載のソースリスト

 

<apex:page standardController="Account" recordSetvar="accounts"
extensions="AccountPagination">
<apex:pageBlock title="Viewing Accounts">
<apex:form id="theForm">
<apex:pageBlockSection >
<apex:dataList var="a" value="{!accountPagination}" type="1">
{!a.name}
</apex:dataList>
</apex:pageBlockSection>
<apex:panelGrid columns="2">
<apex:commandLink action="{!previous}">Previous</apex:commandLink>
<apex:commandLink action="{!next}">Next</apex:commandLink>
</apex:panelGrid>
</apex:form>
</apex:pageBlock>
</apex:page>


public class AccountPagination {
private final Account acct;

public AccountPagination(ApexPages.StandardSetController controller) {
this.acct = (Account)controller.getRecord();
}

public ApexPages.StandardSetController accountRecords {
get {
if (accountRecords == null) {
accountRecords = new ApexPages.StandardSetController(

Database.getQueryLocator(

[SELECT name FROM Account WHERE bushoMei__c like '2%']

));
}
return accountRecords;
}
private set;
}

public List<Account> getAccountPagination() {
return (List<Account>)accountRecords.getRecords();
}
}

 

  #Insert codeにそのままコピペすると改行が正しく処理されないので、

  #その場合は一度メモ帳などを経由してからペーストすると良です。 

 

なお、一つ上に余計なメッセージを残してしまい申し訳ありません。プレビュー機能に気づきませんでした…。

 

どうぞよろしくお願い致します。 

03-30-2010 09:14 AM
にkkurahashiにより編集されたメッセージ
ue123ue123

previous、nextはStandardSetControllerのメソッドです。

(StandardSetControllerクラスについてはForce.com Apex Code Developer's Guideを参照してください。)

 

apex:dataListにバインドされているaccountPaginationに対してprevious、nextする場合は、accountPaginationが参照している

StandardSetController(accountRecords)に対して処理を要求しますので、

 

action="{!accountRecords.previous}"、action="{!accountRecords.next}"

 

になります。

 

This was selected as the best answer
kkurahashikkurahashi

ありがとうございます、解決致しました。

 

なるほど、extension下のスコープがどうなっているのか気になってはいたのですが、

これですっきりしました。

 

お手数をおかけしました。今後ともよろしくお願い致します。

 

#テキストのソースを直しておいてくださいね>Salesforceさん

kkurahashikkurahashi

そういえば、PDF掲載のAPEXソースコードにはもう一箇所誤りがあります。

 

 

getter内の初期化コードが 

return new ApexPages.StandardSetController(Database.getQueryLocator(

 となっていますが、ここはもちろん、

 

accountRecords = new ApexPages.StandardSetController(Database.getQueryLocator(

 でないと、上とは別の理由でページングが実行されません。 

 

蛇足ですが…。