You need to sign in to do that
Don't have an account?
Vivek Zanje 5
Search and Insert Functionality on same visualForce Page
I have Created 2 Objects as Physician__c and Physician_Contact__c. I want two search records on the basis of Name and Email in Physician__c and display the result on same Visualforce page. With each record I need a radiobutton. There is one Add Physician Button on same visualforce page that will add the selected record's Name to Physician_Contact__c Object.
I have successfully implemented the search and display Funationality.
But I am not able to successfully fetch the value associated with selected radio button. Can anyone suggest how i should Implement this functionality.
My Visualforce Page:
My Apex Controller:
Output:
I have successfully implemented the search and display Funationality.
But I am not able to successfully fetch the value associated with selected radio button. Can anyone suggest how i should Implement this functionality.
My Visualforce Page:
<apex:page standardController="Contact" extensions="ctrlSearch"> <script> function dislayDetails(){ alert("You are not allowed to delete this credit card entry"); } </script> <style> input[type=text], select, textarea { width: 50%; padding: 12px; border: 1px solid #ccc; border-radius: 4px; margin-top: 6px; margin-bottom: 16px; resize: vertical; } </style> <script> function valueChanged(){ if(document.getElementById("is_BMW").checked == true) { document.getElementById("is_Mercedes").checked = false; } else { document.getElementById("is_BMW").checked = false; } } </script> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:outputLabel >Name </apex:outputLabel> <apex:inputtext value="{!strAccSearchString}"/> <apex:outputLabel >Email </apex:outputLabel> <apex:inputtext value="{!strAccSearchString1}"/> </apex:pageBlockSection> <apex:pageBlockSection > <apex:commandButton value="Search" action="{!SearchAccountRec}"/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock rendered="{!IF(AND(NOT(ISBLANK(lstAccount)),lstAccount.size>0),true,false)}" title="Search Result"> <apex:pageBlockTable value="{!lstAccount}" var="acc"> <apex:column > <apex:facet name="header">Select</apex:facet> <apex:selectRadio value="{!idSelected}" styleClass="myChk" onclick="is_checked"> <apex:selectOption itemValue="{!acc.Id}" ></apex:selectOption> </apex:selectRadio> </apex:column> <apex:column > <apex:facet name="header">Name</apex:facet> <apex:outputLink value="{!acc.id}">{!acc.Name}</apex:outputLink> </apex:column> <apex:column > <apex:facet name="header">Email</apex:facet> <apex:outputField value="{!acc.Email__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock > <table> <apex:repeat value="{!lstAccount}" var="acc"> <apex:selectOption value="{!items}"></apex:selectOption> </apex:repeat> </table> </apex:pageBlock> <apex:pageBlock > <apex:pageblockSection > <apex:commandButton value="Create New Physician" action="{!URLFOR($Action.Physician__c.New)}"/> <apex:commandButton value="Add Physician" action="{!insertRecord}"/> </apex:pageblockSection> </apex:pageBlock> </apex:form> </apex:page>
My Apex Controller:
public class ctrlSearch { public string strAccSearchString {get; set;} public string strAccSearchString1 {get; set;} public List<Physician__c> lstAccount {get; set;} public List<Physician__c> phy {get;set;} public Physician__c phy1 {get;set;} public boolean isResultDisplay {get; set;} public String idSelected{get;set;} private apexpages.standardController controller {get; set; } public ctrlSearch(ApexPages.StandardController controller) { this.controller = controller; idSelected =''; } public ctrlSearch(id idSelected){ this.idSelected=idSelected; isResultDisplay = false; } public void SearchAccountRec(){ isResultDisplay = true; string strLikeString = '%'+strAccSearchString+'%'; string strLikeString1 = '%'+strAccSearchString1+'%'; string strSOQL = 'select id,Name,Email__c from Physician__c where Name like :strLikeString and Email__c like:strLikeString1'; lstAccount = database.query(strSOQL); } public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); for (Physician__c a : lstAccount) { options.add(new SelectOption(a.Id, a.Name)); } return options; } public void insertRecord() { idSelected = apexpages.currentpage().getparameters().get('selected'); System.debug('Value ' +idSelected); } public void checkSelectedValue(){ system.debug('Selected value is: ' + idSelected); } }
Output: