1

here i am trying to make a radio button which will when clicked should make my pageblock table editable. is there any way to achieve this, if yes please help me out. here is my vf page--enter image description here

here is my vf page code--

 <apex:selectList value="{!selectedValue}" multiselect="false" size="1">
                <apex:selectOption itemValue="1" itemLabel="1"/>
                <apex:selectOption itemValue="2" itemLabel="2"/>
                <apex:selectOption itemValue="3" itemLabel="3"/>
                <apex:actionSupport event="onchange" action="{!search}" rerender="frm"  />
            </apex:selectList>
     records per page

    <apex:inputText value="{!searchstring}" onblur="searchAF();"/>
    <apex:actionfunction action="{!search}" rerender="frm" name="searchAF"/>
    <apex:pageBlockTable value="{!wrapProductList}" var="accWrap"   >
                    <apex:column >
                      <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                      <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                    <apex:column value="{!accWrap.productObject.PricebookEntry.Name}" />
                    <apex:column value="{!accWrap.productObject.Contract_Start_Date__c}" />
                    <apex:column value="{!accWrap.productObject.Service_Start_Date__c}" />
                    <apex:column value="{!accWrap.productObject.Full_Revenue_Date__c}" />
                    </apex:pageBlockTable>
    </apex:pageBlock>

controller--

   public void checkSelectedManual(){        
        system.debug('Selected value is: ' + manualRadio);        
    }  
    public void save() {
        update opportunityList;
    }

   ID opportunId = ApexPages.currentPage().getParameters().get('id');
   public List<Opportunity> opportunityList {get;set;}
    public List<wrapProduct> wrapProductList {get; set;}
    public String extendRadio{get;set;}
    public String copyRadio{get;set;}
    public String manualRadio{get;set;}
    public String selectedValue{get;set;}
    public String searchstring {get;set;}
  public GEN_Op(){ 
   opportunityList = new List<Opportunity>();
   opportunityList = [Select id, Submission_Date__c,Decision_Date__c,CloseDate from Opportunity where id =: opportunId ];
   wrapProductList = new List<wrapProduct>();
   for(OpportunityLineItem priceBookEntryObject: [SELECT PricebookEntry.Name,Contract_Start_Date__c,Service_Start_Date__c,Full_Revenue_Date__c FROM OpportunityLineItem where opportunityId =: opportunId]) {
                 wrapProductList.add(new wrapProduct(priceBookEntryObject));


   }
   }
    public void search(){  
                 wrapProductList = new List<wrapProduct>();
                 string searchquery='SELECT PricebookEntry.Name,Contract_Start_Date__c,Service_Start_Date__c,Full_Revenue_Date__c FROM OpportunityLineItem where PricebookEntry.Name like \'%'+searchstring+'%\' AND opportunityId =: opportunId Limit ' +selectedValue;  

                 for(OpportunityLineItem priceBookEntryObject: Database.query(searchquery)) {
                      wrapProductList.add(new wrapProduct(priceBookEntryObject)); //adding the searched products into list
                 }
        }

        public class wrapProduct {
                public OpportunityLineItem productObject {get; set;}
                public Boolean selected {get; set;}

                public wrapProduct(OpportunityLineItem pBEParam) {
                    productObject = pBEParam;
                    selected = false;
                }
        }
2

So this will be a lengthy ans so

First take a new boolean variable in wrapper class i.e. isEditable

public class wrapProduct {
        public OpportunityLineItem productObject {get; set;}
        public Boolean selected {get; set;}
        public isEditable {get;set;}
        public wrapProduct(OpportunityLineItem pBEParam) {
            productObject = pBEParam;
            selected = false;
            isEditable = false;
        }
}

You need to add action support on radio button and on click call a controller method.. Here method is i.e makeeditable

<apex:selectRadio value="{!country}">
        <apex:actionSupport event="onclick" 
                            action="{!makeeditable}" 
                            rerender="pageBlockTableId"/>
</apex:selectRadio>

Now in method make isEditable to true..

public void makeeditable()
{
    for(wrapProduct objWrapper: wrapProductList)
    {
        objWrapper.isEditable = true;
    }
}

and use rendered attribute to display inputField and outpufield based on isEditable boolean

Your Table

<apex:pageBlockTable value="{!wrapProductList}" var="accWrap"  Id="pageBlockTableId" >
   <apex:column >
      <apex:facet name="header">
         <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
      </apex:facet>
      <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
   </apex:column>
   <apex:column  >
      <apex:outputField value="{!accWrap.productObject.PricebookEntry.Name}" rendered="{!!accWrap.isEditable}">
      <apex:inputField value="{!accWrap.productObject.PricebookEntry.Name}" rendered="{!accWrap.isEditable}">
   </apex:column>
   <apex:column  >
      <apex:outputField value="{!accWrap.productObject.Contract_Start_Date__c}" rendered="{!!accWrap.isEditable}">
      <apex:inputField value="{!accWrap.productObject.Contract_Start_Date__c}" rendered="{!accWrap.isEditable}">
   </apex:column>
   <apex:column  >
      <apex:outputField value="{!accWrap.productObject.Service_Start_Date__c}" rendered="{!!accWrap.isEditable}">
      <apex:inputField value="{!accWrap.productObject.Service_Start_Date__c}" rendered="{!accWrap.isEditable}">
   </apex:column>
   <apex:column  >
      <apex:outputField value="{!accWrap.productObject.Full_Revenue_Date__c}" rendered="{!!accWrap.isEditable}">
      <apex:inputField value="{!accWrap.productObject.Full_Revenue_Date__c}" rerender="{!accWrap.isEditable}">
   </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
  • hii, iam getting this error,,,,,,,--- Unsupported attribute rerender in <apex:outputField> in myVFPage at line 78 column 112 – RAT__ Feb 16 '16 at 11:15
  • 1
    @RAT__ ohh Sorry ..my mistake this should be rendered – Ratan Paul Feb 16 '16 at 11:16
  • for both input as well as output fields ?? – RAT__ Feb 16 '16 at 11:17
  • 1
    @RAT__ Yes.. But only one will be displayed at a time based on isEditable value – Ratan Paul Feb 16 '16 at 11:18
  • 1
    @RAT__ use disabled attribute of apex:inputCheckbox .. <apex:inputCheckbox value="{!accWrap.selected}" id="inputId" disabled="{!isEditable}"/> – Ratan Paul Feb 16 '16 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.