Salesforce 使用映射进行分页不起作用

Salesforce 使用映射进行分页不起作用,salesforce,visualforce,apex,Salesforce,Visualforce,Apex,我试图在Visualforce页面中使用Map进行分页。我已将pageSize设置为1。起初它只显示1个问题及其相应的选项,但当我按下下一步(>)按钮时,它会显示上一个问题和下一个问题。也就是说,它显示了两个问题及其各自的选项。然后,当我再次按“下一步”时,它会显示3个问题及其选项 我只想在每次单击时显示一个问题及其选项。在“下一个”中,它应显示下一个问题和上一个问题( 发生这种情况是因为您没有在方法getQuestions()中重新初始化映射变量“questions”。您必须在方法getQu

我试图在Visualforce页面中使用
Map
进行分页。我已将pageSize设置为1。起初它只显示1个问题及其相应的选项,但当我按下下一步(>)按钮时,它会显示上一个问题和下一个问题。也就是说,它显示了两个问题及其各自的选项。然后,当我再次按“下一步”时,它会显示3个问题及其选项

我只想在每次单击时显示一个问题及其选项。在“下一个”中,它应显示下一个问题和上一个问题(

发生这种情况是因为您没有在方法getQuestions()中重新初始化映射变量“questions”。您必须在方法getQuestions()中添加一行以重新初始化映射变量“questions”。这将使其为空,之后只会向其添加一个问题。请参阅下面更正的getQuestions()方法代码-:

public Map<Survey_Question__c, List<SelectOption>> getQuestions(){
//---------You must add this below line---------------------------
questions= new Map<Survey_Question__c, List<SelectOption>>();
ques = (List<Survey_Question__c>) setCon.getRecords();
for(Survey_Question__c que: ques){
    List<SelectOption> olist = new List<SelectOption>();
    olist.add(new SelectOption('a',que.Option1__c));
    olist.add(new SelectOption('b',que.Option2__c));
    olist.add(new SelectOption('c',que.Option3__c));
    olist.add(new SelectOption('d',que.Option4__c));
    olist.add(new SelectOption('e',que.Option5__c));
    olist.add(new SelectOption('f',que.Option6__c));
    questions.put(que, olist);
}
return questions;  
publicmap getQuestions(){
//---------您必须将此添加到下面的行中---------------------------
问题=新地图();
ques=(List)setCon.getRecords();
(调查问题:问题){
List olist=新列表();
olist.add(新选择选项('a',que.Option1_u_uc));
olist.add(新的选择选项('b',que.Option2_u_uc));
olist.add(新的选择选项('c',que.Option3_uuc));
olist.add(新的选择选项('d',que.Option4_uc));
olist.add(新的选择选项('e',que.Option5_uuc));
olist.add(新的选择选项('f',que.Option6_uc));
问题。提出(问题,寡头);
}
回答问题;
}

<apex:page standardController="Survey__c" extensions="SurveyExtension">
<apex:form >
    <apex:pageBlock title="Survey Title" id="queBlock">                                                      
             <apex:repeat value="{!questions}" var="que">
              Question :  {!que.Question__c} <br/><br/>
              Options : 
                 <apex:repeat value="{!questions[que]}" var="opt">
                    <apex:selectRadio value="{!answer}">                          
                        <apex:selectOptions value="{!opt}" />                          
                    </apex:selectRadio>
                </apex:repeat>
            </apex:repeat> 
            <apex:panelGrid columns="5">
                <apex:commandButton status="fetchStatus" reRender="queBlock" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="queBlock" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="queBlock" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="queBlock" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
                </apex:outputPanel>
            </apex:panelGrid>
    </apex:pageBlock>
</apex:form>
public Map<Survey_Question__c, List<SelectOption>> getQuestions(){
//---------You must add this below line---------------------------
questions= new Map<Survey_Question__c, List<SelectOption>>();
ques = (List<Survey_Question__c>) setCon.getRecords();
for(Survey_Question__c que: ques){
    List<SelectOption> olist = new List<SelectOption>();
    olist.add(new SelectOption('a',que.Option1__c));
    olist.add(new SelectOption('b',que.Option2__c));
    olist.add(new SelectOption('c',que.Option3__c));
    olist.add(new SelectOption('d',que.Option4__c));
    olist.add(new SelectOption('e',que.Option5__c));
    olist.add(new SelectOption('f',que.Option6__c));
    questions.put(que, olist);
}
return questions;