我正在编写一个visualforce页面,用户必须在用户单击上一个按钮时选择机会列表实现分页,然后它将再次呈现列表面板,并且我在调用我的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 ;
}
}
在自定义控制器中获取OpportunityWrapper列表的代码段是
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
我的目标是当我检查任何机会包装并转到下一个或上一个列表时,当返回该项应该被检查但我得到设置值总是空但我在前一组中存储选择值列表( )方法为什么它显示Set总是空的?
答案 0 :(得分:0)
您可以在以下主题中找到2个解决方案(一个用JS实现,另一个用apex控制器实现):
How to find out which checkboxes have been selected on the next page in VisualForce?