You need to sign in to do that
Don't have an account?

please help me for checkbox
HI.
please any one help me ,
I create one vf page for displaying all the case related data along with check box for every record. using wrapper class , i display 10 records for every page like pagenation type, first page i cheched 4 records displayed in other pageblocksection ,and click it second page or next button again checked 2 records and display it in same pageblocksection, but here my problem is i clicked previos button i saw the earlyier selected record which is unchecked. but i want check it
please any one help me ,
I create one vf page for displaying all the case related data along with check box for every record. using wrapper class , i display 10 records for every page like pagenation type, first page i cheched 4 records displayed in other pageblocksection ,and click it second page or next button again checked 2 records and display it in same pageblocksection, but here my problem is i clicked previos button i saw the earlyier selected record which is unchecked. but i want check it
If my answer helps resolve your query, please select it as a 'Best Answer' so that it benefits others and helps us improve the overall quality of the forums.
VF:
<apex:page controller="PagingControllerforCase">
<apex:form id="frm">
<apex:pageBlock title="Paging through Categories of Stuff">
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!ProcessSelected}" value="Show Selected accounts" reRender="block2"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageMessages />
<apex:pageBlockSection title="Category Results - Page #{!pageNumber}" columns="1">
<apex:pageBlockTable value="{!categories}" var="c">
<apex:column width="25px">
<apex:inputCheckbox value="{!c.checked}"/>
</apex:column>
<apex:column value="{!c.cat.id}" headerValue="ID"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:panelGrid columns="4">
<apex:commandLink action="{!first}" reRender="frm">First</apex:commandlink>
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}" reRender="frm">Previous</apex:commandlink>
<apex:commandLink action="{!next}" rendered="{!hasNext}" reRender="frm">Next</apex:commandlink>
<apex:commandLink action="{!last}" reRender="frm">Last</apex:commandlink>
</apex:panelGrid>
<apex:pageBlock >
<apex:pageBlockTable value="{!selectedAccounts}" var="sa" id="block2">
<apex:column value="{!sa.Id}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
apex:
public class PagingControllerforCase {
public list<categoryWrapper> wrapaccountList { get; set; }
List<categoryWrapper> categories {get;set;}
public list<Case> selectedAccounts{get;set;}
public Set<Case> setSelectedAcc {set;get;}
// instantiate the StandardSetController from a query locator
public PagingControllerforCase()
{
setSelectedAcc=new Set<Case>();
wrapaccountList =new list<categoryWrapper>();
for(Case a:[select id from case limit 10]){
wrapaccountlist.add(new categoryWrapper(a));
}
}
public ApexPages.StandardSetController con {
get {
if(con == null) {
con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id FROM Case limit 100]));
// sets the number of records in each page set
con.setPageSize(5);
}
return con;
}
set;
}
// returns a list of wrapper objects for the sObjects in the current page set
public List<categoryWrapper> getCategories() {
categories = new List<categoryWrapper>();
for (Case category : (List<Case>)con.getRecords())
categories.add(new CategoryWrapper(category));
return categories;
}
// indicates whether there are more records after the current page set.
public Boolean hasNext {
get {
return con.getHasNext();
}
set;
}
// indicates whether there are more records before the current page set.
public Boolean hasPrevious {
get {
return con.getHasPrevious();
}
set;
}
// returns the page number of the current page set
public Integer pageNumber {
get {
return con.getPageNumber();
}
set;
}
// returns the first page of records
public void first() {
con.first();
}
// returns the last page of records
public void last() {
con.last();
}
// returns the previous page of records
public void previous() {
con.previous();
}
// returns the next page of records
public void next() {
con.next();
}
// returns the PageReference of the original page, if known, or the home page.
public void cancel() {
con.cancel();
}
public void ProcessSelected(){
selectedAccounts=new list<Case>();
for(CategoryWrapper wrapobj:categories )
{
if(wrapobj.checked==true)
setSelectedAcc.add(wrapobj.cat);
}
selectedAccounts.addall(setSelectedAcc);
System.debug('@@@@@@'+selectedAccounts);
update selectedAccounts;
wrapaccountList=null;
}
public class CategoryWrapper {
public Boolean checked{ get; set; }
public Case cat { get; set;}
public CategoryWrapper(){
cat = new Case();
checked = false;
}
public CategoryWrapper(Case c){
cat = c;
checked = false;
}
}
}
please help me very ugent.
thanks
Satheesh
Try instantiating your selectedAccounts and categories in the contructor instead of doing it every time you call ProcessSelected method and getCategories:
You can also create another Case list to prevent updating records repeatedly:
Apex:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Zuinglio Lopes Ribeiro Júnior,
i will explain correct problem ,
we are in first page i selected two record after that I clicked 'show Selected accounts ' that time selected records are appear in below pageblock.which is good.
again i Clicked next link it will shows second page records I selected two records after that I clicked 'show Selected accounts ' that time selected records are appear in below pageblock.which is good.
now i Clicked Previous link it will shows first page which is also good.
but my problem is earlyier I checked two records but now it will shows unchecked ,(whenever i clicked previous link) now also so which is required to check the selected records
Thanks
Satheesh
Please Any one help me for above mentioned problem .It's Very Urgent.
Thanks
Satheesh
I will reproduce your code here so I can have a better idea of what is going on but it may take a while. As soon as I finish my tests I will give you a feedback.
Regards.
Thank you for giving your valueble time for me. I got Solution, let you Know if anything is required from your side .Thank you very very much.
Note: This code is solved my problem.
Vf Code:
<apex:page controller="Pagin_alpha">
<style type="text/css">
.loadingIcon {
background-image: url(/img/loading.gif);
width: 16px;
height: 16px;
}
</style>
<script type="text/javascript">
function checkAll(cb,cbid)
{
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf(cbid)!=-1){
inputElem[i].checked = cb.checked;
}
}
}
</script>
<apex:form id="form">
<br/>
<div style="align:right;">
<apex:repeat value="{!alphabet}" var="a">
<apex:commandLink value="{!a}" action="{!refreshList2}" rerender="form" style="{!if($CurrentPage.parameters.alpha=a,'font-weight:bold','')}" status="stat">
<apex:param name="alpha" value="{!a}"/>
</apex:commandLink>
|
</apex:repeat>
</div>
<br/>
<apex:pageBlock id="block">
<apex:pageBlockButtons >
<apex:commandButton value="First" action="{!standardsetcon.First}" rerender="block,block2" status="stat"/>
<apex:commandButton rendered="{!standardsetcon.hasprevious}" value="Previous" action="{!standardsetcon.previous}" rerender="block,block2" status="stat"/>
<apex:commandButton rendered="{!standardsetcon.hasnext}" value="Next" action="{!standardsetcon.next}" rerender="block,block2" status="stat"/>
<apex:commandButton value="Last" action="{!standardsetcon.Last}" rerender="block,block2" status="stat"/>
</apex:pageBlockButtons>
<apex:actionStatus id="stat">
<apex:facet name="start">
<apex:outputPanel layout="block" styleClass="message infoM4">
<apex:panelGrid columns="2" styleClass="messageTable" columnClasses="messageCell" style="padding:0px;margin:0px;">
<apex:panelGroup >
<img class="loadingIcon" src="/s.gif"/>
</apex:panelGroup>
<apex:panelGroup >
<div class="messageText">Please wait...</div>
</apex:panelGroup>
</apex:panelGrid>
</apex:outputPanel>
</apex:facet>
<apex:facet name="stop">
<apex:pageBlockTable value="{!CurrentList}" var="c" id="table">
<apex:column >
<apex:facet name="header"><apex:inputcheckbox onclick="checkAll(this,'check')" value="{!fals}" /></apex:facet>
<apex:inputcheckbox value="{!c.checked}" id="check">
</apex:inputcheckbox>
</apex:column>
<apex:column value="{!c.ocontact.id}" headerValue="Id"/>
</apex:pageBlockTable>
</apex:facet>
</apex:actionStatus>
</apex:pageBlock>
<apex:pageBlock title="Selected Contacts" id="block2">
<apex:commandButton value="Display Selected" rerender="block2"/>
<apex:pageBlockTable value="{!DisplaySelectedList}" var="c">
<apex:column value="{!c.id}" headerValue="Id"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code:
public with sharing class Pagin_alpha {
private List<ContactSet> ContactSetList{get;set;}
private string ContactListQuery;
private set<Case> selectedContact;
public List<string> alphabet{get;set;}
public boolean fals{get;set;}
public Pagin_alpha(){
fals=false;
alphabet=new string[]{'All','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
ContactSetList = new List<ContactSet>();
selectedContact = new set<Case>();
ContactListQuery= 'select id from Case limit 1000';
}
Private void updateSelectedContact(){
for(ContactSet cs:ContactSetList ){
if(cs.checked)
selectedContact.add(cs.oContact);
else{
if(selectedContact.contains(cs.oContact))
selectedContact.remove(cs.oContact);
}
}
}
public ApexPages.StandardSetController standardSetCon {
get {
if(standardSetCon == null) {
standardSetCon = new ApexPages.StandardSetController(Database.getQueryLocator(ContactListQuery));
// sets the number of records in each page set
standardSetCon .setPageSize(5);
}
return standardSetCon ;
}
set;
}
public List<ContactSet> getCurrentList() {
updateSelectedContact();
ContactSetList = new List<ContactSet>();
for (Case category : (List<Case>)standardSetCon.getRecords()){
if(selectedContact.contains(category))
ContactSetList.add(new ContactSet(category,'true'));
else
ContactSetList.add(new ContactSet(category));
}
fals=false;
return ContactSetList;
}
public PageReference refreshList2() {
standardSetCon = null;
string s;
if(apexpages.currentpage().getparameters().get('alpha') == 'All')
s='%';
else
s= apexpages.currentpage().getparameters().get('alpha')+'%';
ContactListQuery= 'select id from Case';
return null;
}
public List<Case> getDisplaySelectedList(){
updateSelectedContact();
List<Case> displaycon = new list<Case>();
displaycon.addall(selectedContact);
return displaycon;
}
public class ContactSet {
public Boolean checked{ get; set; }
public Case oContact { get; set;}
public ContactSet(){
oContact = new Case();
checked = false;
}
public ContactSet(Case c){
oContact = c;
checked = false;
}
public ContactSet(Case c,string s){
oContact = c;
checked = true;
}
}
}
Thank
Satheesh