I'm not sure what I'm doing wrong but I have a column where I am trying to send an ID to the controller to delete it from the database and pageBlockTable.
The problem is when I call the removeThisTeamMember() method - the otIdValue value is always null. What am I doing wrong? I'm not sure I have my actionSupport method set up correctly...
Page:
<apex:page controller="OperationalTeamController">
<apex:form >
<apex:pageBlock title="Operational Team Mass Update" >
<apex:pageBlockButtons >
<apex:commandButton id="update" action="{!quickUpdat}" value="Quick Update Roles"/>
</apex:pageBlockButtons>
<apex:pageBlockTable id="pageblocktableid" value="{!ot}" var="o">
<apex:inlineEditSupport showOnEdit="update, cancelButton"
hideOnEdit="editButton" event="ondblclick"
changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
<apex:column headerValue="Delete">
<!--heres the action support-->
<apex:actionSupport event="onclick" action="{!removeThisTeamMember}" reRender="pageblocktableid">
<apex:commandLink onclick="if(confirm('Are you sure you want to delete this Team Member?')) {return true;} else return false;">
<img style="" src="/img/func_icons/remove12_on.gif" alt="X"/>
<apex:param name="otIdValue" value="{!o.id}" assignTo="{!otIdValue}"/>
</apex:commandLink>
</apex:actionSupport>
</apex:column>
<apex:column headerValue="Operational Team Name">
<apex:outputfield value="{!o.name}"/>
</apex:column>
<apex:column headerValue="Team Member Role">
<apex:outputfield value="{!o.Team_Member_Role__c}"/>
</apex:column>
<apex:column headerValue="Last Modified Date">
<apex:outputfield value="{!o.LastModifiedDate}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class OperationalTeamController {
public list <Operational_Team__c> ot {get;set;}
public Map <Id, String> oldData = new Map<Id, String>();
public list <Operational_Team__c> otToUpdate = new list <Operational_Team__c>();
public String message{get;set;}
public String otIdValue {get;set;} //capture value from assignTo
public OperationalTeamController(){
Id oppId = ApexPages.currentPage().getParameters().get('id');
//string searchquery='select name,Team_Member_Role__c from Operational_Team__c WHERE ID = \'a1Z0t000000W4e7\'';
ot = [select id, name, Team_Member_Role__c, LastModifiedDate from Operational_Team__c WHERE Opportunity__c = :oppId ];
for(Operational_Team__c o : ot){
oldData.put(o.Id,o.Name+';'+o.Team_Member_Role__c);
}
}
public PageReference removeThisTeamMember(){
System.debug(otIdValue); //this is always null
//to-do: get the record in question and delete it
return null;
}
public PageReference quickUpdat(){
try{
//loop through values and only update names that were actually changed
for(Operational_Team__c o : ot){
if(o.Name+';'+o.Team_Member_Role__c != oldData.get(o.Id)){
otToUpdate.add(o);
}
}
update otToUpdate;
PageReference pageRef = ApexPages.CurrentPage();
pageRef.setRedirect(true);
return pageRef;
}catch(Exception e){
message='Data Base error during saving...';
ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, message));
return null;
}
}
}
If my approach is way off and there is a better way to do this, I'm all ears. I personally think a wrapper is overkill for this, hence why I'm sending individual rows to the controller. Thanks!!