0

I am trying to add a delete function in my Extension class on my visualforce page. The param on the visualforce page from the PageBlockTable row is not being passed when the CommandButton Action is being called.

VisualForce Page

<apex:pageBlockSection title="Assigned Components" columns="1">
    <apex:pageBlockTable var="a" value="{!AppComponents}" >
        <apex:column headerValue="Actions" width="10%">
            <apex:commandButton value="edit" onclick="window.location='/apex/vfAppComponentEdit?retURL=%2F{!a.Application__c}&id={!a.id}'; return false;" />                     
            <apex:commandButton value="delete" action="{!deleteRow}" rerender="Components"/>
<!--  **** this is where the parameter is assigned **** -->
    <apex:param name="rowid" value="{!a.Id}" assignTo="{!SelectedRowId}"/>

Apex Class

    public class APM_ApplicationExtension {
        private final App_Components__c appComponent;
        private final id appId;

/****  THIS IS THE GETTER AND SETTER WHERE THE PARAM IS SUPPOSED TO GO ***/
        public string SelectedRowId{get;set;}

        public APM_ApplicationExtension(apexpages.StandardController stdController){
            this.appComponent = (App_Components__c)stdController.getRecord();

        }

        public list<App_Components__c> getAppComponents(){

            list<App_Components__c> a =  [select name, product__c, component_category__c, id, application__c from App_Components__c where Application__c =: appComponent.Application__c];
            return a;
        }

        public Pagereference deleteRow(){

/*** THIS IS ALWAYS NULL  ****/
            system.debug('selected row id is: ' + SelectedRowId);
            list<App_Components__c> appComponents = getAppComponents();
            if (appComponents.size() > 0){
                for(app_components__c appComponent : appComponents ){
                    if (appComponent.id == SelectedRowId){
                        delete appComponent;
                        system.debug('deleted');
                    }
                }
            }        
            return null;
        }
    }
2

apex:param : A parameter for the parent component. The component can only be a child of the following components:

<apex:actionFunction>
<apex:actionSupport>
<apex:commandLink>
<apex:outputLink>
<apex:outputText>
<flow:interview>

see the use here

It will have no effect if works independently.

|improve this answer|||||
  • correct! Will accept this answer in 4 minutes – tjcinnamon Jun 21 '17 at 17:13
0

For anyone running into this. The param needs to be inside the CommandButton tag

 <apex:commandButton value="delete" action="{!deleteRow}" rerender="Components">
     <apex:param name="rowid" value="{!a.Id}" assignTo="{!SelectedRowId}"/>
 </apex:commandButton>
|improve this answer|||||

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.