在apex控制器中维护CheckBox状态

问题描述 投票:1回答:1

我正在编写一个visualforce页面,用户必须在用户单击上一个按钮时选择机会列表实现分页,然后它将再次呈现列表面板,我在调用中更改了list的值,我的visualforce页面段是

<apex:pageBlockTable value="{!numbers}" var="n" align="center">
    <apex:column >
        <apex:inputCheckbox value="{!n.checked}"/>
    </apex:column> 
    <apex:column value="{!n.cat.Id}" />
    <apex:column value="{!n.cat.Name}" />
    <apex:facet name="footer">Showing Page # {!pageNumber} of {!totalPages}</apex:facet>
</apex:pageBlockTable>

我有一个OpportunityWrapper类来维护checkItem:

public class OpportunityWrapper {
    public Boolean checked { get; set; }
    public Opportunity cat { get; set; }

    public OpportunityWrapper(){
        cat = new Opportunity();
        checked = false;
    }

    public OpportunityWrapper(Opportunity c){
        cat = c;
        checked = false;
    }

    public OpportunityWrapper(Opportunity c, Boolean checked){
        cat = c;
        this.checked = checked ;
    }
}

获取自定义控制器中Opportunity Wrapper列表的代码段是

public List<OpportunityWrapper> getNumbers() {
    opp = new List<OpportunityWrapper>();
    if ( selectedPage != '0' )
        counter = list_size*integer.valueOf(selectedPage)-list_size;

    //we have to catch query exceptions in case the list is greater than 2000 rows
    try {
        for ( Opportunity o : [SELECT Id,Name from Opportunity order by name 
               limit :list_size offset :counter] ) {
            if ( !oppId.contains(o.Id) ) 
                opp.add(new OpportunityWrapper(o));
            else
                opp.add(new OpportunityWrapper(o,true));               
        } 
    } catch ( QueryException e ) {
        ApexPages.addMessages(e);                   
        return null;
    }    
    return opp;
}

当按下前一个按钮时,调用下面的方法

public PageReference Previous() {
    //user clicked previous button
    for ( OpportunityWrapper o : opp ) { 
        if ( o.checked &&  oppId.contains(o.cat.Id) )
            oppId.add(o.cat.Id); 
    }
    selectedPage = '0';
    counter -= list_size;
    return null ;
}

以下是自定义类的公共成员

private integer counter = 0;  //keeps track of the offset
private integer list_size = 5;
public integer total_size; 
List<OpportunityWrapper> opp ;
public List<OpportunityWrapper> oppwrapper = new List<OpportunityWrapper>(); //list of Opportunity wrapper shown in the page
public  Set<String> oppId = new Set<String>(); //set for maintaining which Id's are checked

我的目标是当我检查任何机会包装并转到下一个或上一个列表时,当返回该项应该被检查但我得到设置值总是空但我在select()方法的集合中存储选择值的列表为什么它的显示设置总是空的?

salesforce apex-code visualforce
1个回答
0
投票

您可以在以下主题中找到2个解决方案(一个用JS实现,另一个用apex控制器实现):

How to find out which checkboxes have been selected on the next page in VisualForce?

© www.soinside.com 2019 - 2024. All rights reserved.