I'm trying to build a Visualforce page which lists a set of records (via apex:repeat
for a Visualforce 'record' Component), and where each record has a 'delete' button under it.
Hitting delete should remove it from a List variable in the apex controller. My current solution is acquiring the list index via apex:repeat
+ apex:variable
, and passing it into the given commandButton->apex:param
->assignTo.
Unfortunately, the indexOfNewChildToRemove
variable always comes out as null
, so I'm not sure whether I'm doing something wrong or what I'm doing is simply impossible.
This is what I've got:
<!--Counter for number of children - this is important with removals-->
<apex:variable value="{!0}" var="rowNum"/>
<apex:repeat value="{!newChildren}" var="child">
<!--Heading and child detail component-->
<h2>{!child.Child_s_First_Name__c} {!child.Child_s_Last_Name__c}</h2>
<c:ASDetectEvalStudyUpsertChildCmp child="{!child}"/>
<!--Delete record from list-->
<apex:commandButton action="{!deleteNewChild}"
value="Remove">
<apex:param name="childIndex" value="{!rowNum}" assignTo="{!indexOfNewChildToRemove}"/>
</apex:commandButton>
<!--Increment counter-->
<apex:variable var="rowNum" value="{!rowNum + 1}"/>
</apex:repeat>
On the apex controller, I have {get; set;}
but do not explicitly initialise the variable. Even when I do, the value doesn't change - so it doesn't seem to register that the assignTo is happening.