You need to sign in to do that
Don't have an account?
help needed on Two Checkbox columns !!!
Hello
My requirement is to displayed a table with two chexbox columns and allow the user to select only one checkbox in each column.
The below code is working fine for only one column. first when i select first checkbox in mastercolumn and then select 2nd checkbox in the same mastercolumn then it is automatically deselecting the first and selecting the 2nd using the below code.
But when i select any checkbox in the duplicatecolumn then the checkbox selected in the mastercolumn is getting deselected.
Does anyone have any idea on how to resolve this issue?..please advise.....Thanks in advance
Master |
Duplicate |
Name |
Owner |
|
|
Acme1 |
john |
|
|
Acme2 |
jim |
|
|
Acme |
john |
<apex:page tabStyle="Account" controller="Account_controller" action="{!init}">
<script>
var selectedChkbox;
function deSelectOthers(chkBox)
{
if (chkBox.checked)
{
if ((chkBox != selectedChkbox) && (selectedChkbox != null))
{
selectedChkbox.checked = false;
}
selectedChkbox = chkBox;
}
}
</script>
<apex:form >
<apex:pageBlock>
<apex:panelGrid id="AccountDetail" columns="1" width="150%">
<apex:pageBlock id="page1">
<apex:pageBlockButtons location="Bottom">
<apex:commandButton action="{!continue1}" value="Continue"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Select Master and Dupe records">
<apex:pageBlockTable value="{!AccountResults}" var="acc" rules="all" width="150%">
<apex:column headerValue="Master">
<apex:outputPanel id="op1">
<apex:inputCheckBox value="{!Mstchk}" id="master_Checkbox" disabled="{!Mstchk}" onclick="deSelectOthers(this)">
</apex:inputCheckBox>
</apex:outputPanel>
<script>
if ("{!Mstchk}" == "true")
{
var idForSelectedBox = "$component.master_Checkbox";
selectedChkbox = document.getElementById(idForSelectedBox);
}
</script>
</apex:column>
<apex:column headerValue="Duplicate">
<apex:outputPanel id="op2">
<apex:inputCheckBox value="{!Dupchk}" id="duplicate_Checkbox" disabled="{!Dupchk}" onclick="deSelectOthers(this)">
</apex:inputCheckBox>
</apex:outputPanel>
<script>
if ("{!Dupchk}" == "true")
{
var idForSelectedBox = "$component.duplicate_Checkbox";
selectedChkbox = document.getElementById(idForSelectedBox);
}
</script>
</apex:column>
<apex:column headerValue="Name" value="{!acc.Name}">
</apex:column>
<apex:column headerValue="Owner" value="{!acc.Owner.Name}">
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:panelGrid>
</apex:form>
</apex:page>
public class Account_controller
{
private String searchText;
private Boolean Dupchk;
private Boolean Mstchk;
public string AName;
Id AcctId =ApexPages.currentPage().getparameters().get('id');
public Account acctName;
List<Account> AccountResults=null;
public List<Account> getAccountResults()
{
return AccountResults;
}
public Boolean getDupChk()
{
return Dupchk;
}
public void setDupChk (Boolean Dupchk)
{
this.Dupchk = Dupchk;
}
public Boolean getMstChk()
{
return Mstchk;
}
public void setMstChk (Boolean Mstchk)
{
this.Mstchk = Mstchk;
}
public string getSearchText()
{
return AName;
}
public void setSearchText (String searchText)
{
this.searchText = searchText;
}
public PageReference continue1()
{
return null;
}
public PageReference init()
{
acctName=[Select Name from Account where id=:AcctId];
AName=acctName.Name;
return null;
}
public void search()
{
try
{
AccountResults= (List<Account>)[select Id, Name, Type, BillingStreet,Billingcity,BillingState,BillingPostalCode,Owner.Name from Account where Name like: searchText+'%'];
}
catch (Exception e)
{
AccountResults = (List<Account>)null;
System.Debug('Error in search criteria.');
}
}
public Class AccountResults
{
public Account Acc
{
get;
set;
}
public Boolean selected
{
get;
set;
}
public AccountResults(Account a)
{
Acc=a;
selected=false;
}
}
}
Hi
AccountResults needs to be declared as List<AccountResult>
List<AccountResult> AccountResults = null; public void search() { try { List<Account> accounts= [select Id, Name, Type, BillingStreet,Billingcity,BillingState,BillingPostalCode,Owner.Name from Account where Name like: searchText+'%']; for (Account account : accounts) AccountResults.add(new AccountResult(account)); } catch (Exception e) { AccountResults = null; System.Debug('Error in search criteria.'); } }
All Answers
user selections need to be stored in AccountResult class
<apex:pageBlockTable value="{!AccountResult}" var="acc" rules="all" width="150%">
<apex:column headerValue="Master">
<apex:outputPanel id="op1">
<apex:inputCheckBox value="{!acc.master_selected}" id="master_Checkbox">
<apex:actionSupport event="onclick" action="{!SelectAccount}" rerender="page1"/>
</apex:inputCheckBox>
<apex:inputCheckBox value="{!acc.duplicate_selected}" id="duplicate_Checkbox">
<apex:actionSupport event="onclick" action="{!SelectAccount}" rerender="page1"/>
</apex:inputCheckBox>
public Class AccountResult
{
public Account Acc { get; set; }
public Boolean master_selected { get; set; }
public Boolean duplicate_selected { get; set; }
public AccountResult(Account a)
{
Acc=a;
selected=false;
}
}
public void SelectAccount()
{
for (AccountResult acc : AccountResults)
{
if (acc.master_selected) .....
if (acc.duplicate_selected) .....
}
}
Thanks for the response.
I changed my code to read as following..but still getting the errorin for loop
Loop variable must be of type SOBJECT:Account
public class Account_Controller
{
private String searchText;
public string AName;
Id AcctId = ApexPages.currentPage().getparameters().get('id');
public Account acctName;
List<Account> AccountResults=null;
public List<Account> getAccountResults()
{
return AccountResults;
}
public string getSearchText()
{
return AName;
}
public void setSearchText (String searchText)
{
this.searchText = searchText;
}
public PageReference init()
{
acctName=[Select Name from Account where id=:AcctId];
AName=acctName.Name;
return null;
}
public void search()
{
try
{
AccountResults= (List<Account>)[select Id, Name, Type, BillingStreet,Billingcity,BillingState,BillingPostalCode,Owner.Name from Account where Name like: searchText+'%'];//and ownerid=:UserInfo.getUserId()];
}
catch (Exception e)
{
AccountResults = (List<Account>)null;
System.Debug('Error in search criteria.');
}
}
public Class AccountResult
{
public Account Acc { get; set; }
public Boolean selected { get; set; }
public Boolean master_selected { get; set; }
public Boolean duplicate_selected { get; set; }
public AccountResult(Account a)
{
Acc=a;
selected=false;
}
}
public void SelectAccount()
{
for (AccountResult acc : AccountResults) //Loop variable must be of type SOBJECT:Account
{
if (acc.master_selected) {}
if (acc.duplicate_selected) {}
}
}
}
And also one more i noticed is in the VF PageblockTable you are advising to grab values from AccountResult class. We cannont grab Account Name and Account Owner fields from AccountResult class.
Please advise....thanks
Hi
AccountResults needs to be declared as List<AccountResult>
List<AccountResult> AccountResults = null; public void search() { try { List<Account> accounts= [select Id, Name, Type, BillingStreet,Billingcity,BillingState,BillingPostalCode,Owner.Name from Account where Name like: searchText+'%']; for (Account account : accounts) AccountResults.add(new AccountResult(account)); } catch (Exception e) { AccountResults = null; System.Debug('Error in search criteria.'); } }
Hello AltiumForce
Thank you for the input. Sorry i was out of town and did't get a channce to look at this.
Any way..this is still not working. When i click on search button just a blank white screen is appearing. And i noticed an error on the webpage
Am i doing correct...Can you please help??
i apologize if i am asking simple things...i am not a developer..trying to learn programming..
\\Webpage error details
Message: Object doesn't support this property or method
Line: 172
Char: 390
Code: 0
URI: https://cs2.salesforce.com/faces/a4j/g/3_3_0.GAorg.ajax4jsf.javascript.AjaxScript
<apex:page tabStyle="Account" controller="Account_controller" action="{!init}"> <apex:form > <apex:pageBlock title="Account Delete"> <apex:pageBlockSection title="Account Search"> <apex:pageBlockSectionItem > <apex:panelGroup > <apex:outputLabel for="AcName" style="{font-weight:bold}">Account Name: </apex:outputLabel> <apex:inputText id="AcName" value="{!searchText}" tabindex="0"> </apex:inputText> <apex:commandButton id="Search1" status="SearchStatus" value=" Search " reRender="AccountDetail" action="{!search}" accesskey="\r\n"/> </apex:panelGroup> </apex:pageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> <apex:panelGrid id="AccountDetail" columns="1" width="150%"> <apex:pageBlock id="page1" tabStyle="Account" title="Search Results"> <apex:pageBlockButtons location="Bottom"> <apex:commandButton action="{!continue1}" value="Continue"/> </apex:pageBlockButtons> <apex:actionStatus id="SearchStatus" startText="Requesting..."> <apex:facet name="stop"> <apex:pageBlockSection title="Select Master and Dupe Accounts to merge"> <apex:pageBlockTable value="{!AccountResult}" var="acc" rules="all" width="150%"> <apex:column headerValue="Master"> <apex:inputCheckBox value="{!acc.master_selected}" id="master_Checkbox"> <apex:actionSupport event="onclick" action="{!SelectAccount}" rerender="page1"/> </apex:inputCheckBox> </apex:column> <apex:column headerValue="Duplicate"> <apex:inputCheckBox value="{!acc.duplicate_selected}" id="duplicate_Checkbox"> <apex:actionSupport event="onclick" action="{!SelectAccount}" rerender="page1"/> </apex:inputCheckBox> </apex:column> <apex:column headerValue="Name" value="{!acc.Name}"> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:facet> </apex:actionStatus> </apex:pageBlock> </apex:panelGrid> </apex:form> </apex:page>
public class Account_controller
{ private String searchText; public string AName; Id AcctId =ApexPages.currentPage().getparameters().get('id'); Public Account acctName; List<AccountResult> AccountResults = null; public List<AccountResult> getAccountResult() { return AccountResults; } public string getSearchText() { return AName; } public void setSearchText (String searchText) { this.searchText = searchText; } public PageReference continue1() { return null; } public PageReference init() { acctName=[Select Name from Account where id=:AcctId]; AName=acctName.Name; return null; } public void search() { List<Account> accounts= [select Id, Name, Type, BillingStreet,Billingcity,BillingState,BillingPostalCode,Owner.Name from Account where Name like: searchText+'%']; for (Account account : accounts)
{
AccountResults.add(new AccountResult(account));
} } public Class AccountResult { public Account Acc { get; set; } public Boolean selected { get;set;} public string Name {get;set;} public Boolean master_selected { get; set; } public Boolean duplicate_selected { get; set; } public AccountResult(Account a) { Acc=a; Name=a.Name; selected=false; } } public void SelectAccount() { for (AccountResult acc : AccountResults) { if (acc.master_selected) {} if (acc.duplicate_selected) {} } } }