function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Subramani_SFDCSubramani_SFDC 

Regarding checkbox

i have checkboxes in pageblock table for passing that value from one page to another vf page....if i am selecting one by one it wil get selected and passing the values to the next vf page. but if i am going to select the next value it not added to the next vf page.Also if i selecting all checkboxes it will give the error like this...

 

System.StringException: Invalid id: checkedone

Error is in expression '{!doSelectItem}' in page searchproduct
 
 
how to avoid this...i m using wrapper class...if need i will post my entire code here. anyone give the solution for this..
 
 
 
Thanks
Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

after a close look to the code

 

I found that 

checkAll(this,'checkedone')

 You are passing 'checkdone' to your actionFunction and whihc is assigning it to contextItem variable whihc happens to be a Id field. Basically you are assinging String to Id and hence it is giving error

 

<apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="refresh">

<apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
</apex:actionFunction>

 

 

 

You are not doing justice to the wrapper classes!!!

Am not sure why are you passing Id using actionFunction ? I guess you are using wrapper class and they will be automatically passed to the controller. Please go through the blog link I have provided to implement this in correct way.

All Answers

Avidev9Avidev9

Few inputs

  • apex : inputcheckbox should only be binded with a boolean field
  • Most important are you doing some comparision on Id field ? Like
Id someId;
if(someId == ''){
//this will give you exception
}

 The above code will give you StringException

 

Id someId
if(someId == null){
//this is the correct way
}

 

 

Had another look at your code seems like you are assigning String value to an Id field. Please post your code, but am assuming this is the case

Avidev9Avidev9
Have a look at this blog http://blogforce9.blogspot.in/2013/06/wrapper-classes-wrap-it-up-with-wrapper.html . If you need help with wrapper classes
Subramani_SFDCSubramani_SFDC

public list<productlistdisplay> listproduct{get;set;}


public List<productlistdisplay> getproducts(){


listproduct= new List<productlistdisplay>();

for(product2 p : (List<product2>)this.Con.getRecords()){
//product2 p = (product2)pr;

productlistdisplay pd = new productlistdisplay(p);


if(this.selectedproductIds.contains(p.id)){
pd.check=true;
}

listproduct.add(pd);
//else{
//pd.check=false;}



}

return listproduct;
}







public list<productlistdisplay> SelectedprodList{get;set;}
public list<productlistdisplay> getSelectedproducts()
{

selectedprodList = new list<productlistdisplay >();
for(productlistdisplay pCon:getproducts())
{
if(pCon.Check == true)
{
selectedprodList.add(pCon);

}

}
system.debug('#### SELETCED'+selectedprodList.size());
return selectedprodList;
}

public class productlistdisplay{
public product2 prod{get;set;}
public decimal Quantity{get;set;}
public date Opp_Date{get;set;}
public string LineDes{get;set;}
public double Sales_Price{get;set;}
public boolean check{get;set;}


public productlistdisplay( product2 p){
this.prod=p;
check=false;
}
}

 

 

 

<apex:pageBlock >


<apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="refresh">


<apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
</apex:actionFunction>
<apex:actionFunction name="aSelectAllItems" action="{!SelectAllItems}" rerender="refresh"/>
<!-- handle deselected item -->
<apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}">
<apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
</apex:actionFunction>



<apex:pageBlockTable value="{!products}" var="ProList" align="centre" id="ProductTable" columns="10">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox value="{!ProList.check}" onclick="checkAll(this,'checkedone')" style="background-color:lightblue;" />
</apex:facet>
<apex:inputCheckbox value="{!ProList.check}" id="checkedone" onchange="doCheckboxChange(this,'{!ProList.prod.Id}')" />
</apex:column>

<apex:column >

 

 

 

i am using javascript for validation

 

 

<script type="text/javascript">
function doCheckboxChange(cb,itemId){

if(cb.checked==true){
//alert('checed'+itemId);
aSelectItem(itemId);
}
else{
aDeselectItem(itemId);
}

 

}

function checkAll(cb,cbid)
{


var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf("checkedone")!=-1)
inputElem[i].checked = cb.checked;
}
}


</script>

 

this is the wrapper class.....

 

 

 

 

 

Avidev9Avidev9

after a close look to the code

 

I found that 

checkAll(this,'checkedone')

 You are passing 'checkdone' to your actionFunction and whihc is assigning it to contextItem variable whihc happens to be a Id field. Basically you are assinging String to Id and hence it is giving error

 

<apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="refresh">

<apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
</apex:actionFunction>

 

 

 

You are not doing justice to the wrapper classes!!!

Am not sure why are you passing Id using actionFunction ? I guess you are using wrapper class and they will be automatically passed to the controller. Please go through the blog link I have provided to implement this in correct way.

This was selected as the best answer
Subramani_SFDCSubramani_SFDC

I m a newbie to salesforce.....couldnt fix it correctly.....sorting searching paging is done using stdsetcontroller.....if one working others are not working.....give any javascript code or jquery for checking the checkbox validation???

Avidev9Avidev9
Have a look if it helps blogforce9.blogspot.in/2013/03/pageblocktable-enhancer-v20b-and.html