Salesforce 如何在VisualForce的下一页中找到已选中的复选框?

Salesforce 如何在VisualForce的下一页中找到已选中的复选框?,salesforce,visualforce,force.com,Salesforce,Visualforce,Force.com,我有一个数据表,它遍历自定义对象并生成复选框。在第二页上,我想确定已选中这些复选框中的哪些 在VisualForce页面中: Age <apex:inputText value="{!age}" id="age" /> <apex:dataTable value="{!Areas}" var="a"> <apex:column > <apex:inputCheckbox value="{!a.name}" /> <

我有一个数据表,它遍历自定义对象并生成复选框。在第二页上,我想确定已选中这些复选框中的哪些

在VisualForce页面中:

 Age <apex:inputText value="{!age}" id="age" />
 <apex:dataTable value="{!Areas}" var="a">
      <apex:column >
      <apex:inputCheckbox value="{!a.name}" /> <apex:outputText value="{!a.name}" />
      </apex:column>
  </apex:dataTable>
年龄
在控制器中:

 public String age {get; set; }
  public List<Area_Of_Interest__c> getAreas() {
      areas = [select id, name from Area_Of_Interest__c];
      return areas;
  }
公共字符串年龄{get;set;}
公共列表区域(){
区域=[从感兴趣的区域中选择id、名称];
返回区;
}
在我的第二页,我可以使用
{!age}
检索用户在文本框“age”中输入的值。如何检索已选中的复选框


谢谢。

在我当前的项目中,我遇到了同样的问题。我使用了apex:pageBlockTable,但我想您可以使用我的代码(我对对象名称的代码做了一些更改)

我在这里使用jQuery,这意味着您也应该在页面中包含以下代码

<apex:includeScript id="JQuery" value="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"/>
... some code
<script>
    window.$j = jQuery.noConflict();
    ... some code
</script>

... 一些代码
window.$j=jQuery.noConflict();
... 一些代码
分页按钮也涉及js:

<apex:panelGrid columns="7">
   <apex:commandButton status="fetchStatus" reRender="results" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page" onClick="saveSelection();" oncomplete="   restoreSelection()"/>
   <apex:commandButton status="fetchStatus" reRender="results" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page" onClick="saveSelection();"    oncomplete="restoreSelection()"/>
   <apex:commandButton status="fetchStatus" reRender="results" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page" onClick="saveSelection();" oncomplete="   restoreSelection()"/>
   <apex:commandButton status="fetchStatus" reRender="results" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page" onClick="saveSelection();" oncomplete="   restoreSelection()" />
   <apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText>
   <apex:outputPanel style="color:#4AA02C;font-weight:bold">
       <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
   </apex:outputPanel> 
</apex:panelGrid>

{!(pageNumber*size)+1-size}-{!如果((pageNumber*size)>noOfRecords,noOfRecords,(pageNumber*size))}的{!noOfRecords}

我希望这可能会对您有所帮助。

好的,如果您想用Javascript处理它,请使用Pavel的方法,否则请通过控制器使用以下方法。您必须为希望跟踪的内容创建包装器类。我不确定它是如何工作的,但是如果在包装器类中将一个布尔变量命名为“selected”,它就会映射到复选框。代码如下:

因此,在“视觉力”页面中,请执行以下操作:

<apex:dataTable value="{!Foos}" var="f">
    <apex:column >
        <apex:outputLabel value="{!f.foo.name}" /> <apex:inputCheckbox value="{!f.selected}" />
    </apex:column>
 </apex:dataTable>
 <apex:commandButton action="{!getPage2}" value="go"/>
2) 声明列表变量

public List<wFoo> foos {get; set;}
public List<Foo__c> selectedFoos {get; set;}

完美的概念和实施!谢谢@Pavel
<apex:includeScript id="JQuery" value="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"/>
... some code
<script>
    window.$j = jQuery.noConflict();
    ... some code
</script>
<apex:panelGrid columns="7">
   <apex:commandButton status="fetchStatus" reRender="results" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page" onClick="saveSelection();" oncomplete="   restoreSelection()"/>
   <apex:commandButton status="fetchStatus" reRender="results" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page" onClick="saveSelection();"    oncomplete="restoreSelection()"/>
   <apex:commandButton status="fetchStatus" reRender="results" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page" onClick="saveSelection();" oncomplete="   restoreSelection()"/>
   <apex:commandButton status="fetchStatus" reRender="results" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page" onClick="saveSelection();" oncomplete="   restoreSelection()" />
   <apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText>
   <apex:outputPanel style="color:#4AA02C;font-weight:bold">
       <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
   </apex:outputPanel> 
</apex:panelGrid>
<apex:dataTable value="{!Foos}" var="f">
    <apex:column >
        <apex:outputLabel value="{!f.foo.name}" /> <apex:inputCheckbox value="{!f.selected}" />
    </apex:column>
 </apex:dataTable>
 <apex:commandButton action="{!getPage2}" value="go"/>
public class wFoo {
    public Foo__c foo {get; set}
    public boolean selected {get; set;}

    public wFoo(Foo__c foo) {
        this.foo = foo;
        selected = false; //If you want all checkboxes initially selected, set this to true
    }
}
public List<wFoo> foos {get; set;}
public List<Foo__c> selectedFoos {get; set;}
public List<wFoo> getFoos() {
    if (foos == null) {
        foos = new List<wFoo>();
        for (Foo__c foo : [select id, name from Foo__c]) {
            foos.add(new wFoo(foo));
        }
    }
    return foos;
}
public void processSelectedFoos() {
    selectedFoos = new List<Foo__c>();
    for (wFoo foo : getFoos) {
        if (foo.selected = true) {
            selectedFoos.add(foo.foo); // This adds the wrapper wFoo's real Foo__c
        }
    }
}
public PageReference getPage2() {
    processSelectedFoos();
    return Page.Page2;
}