I have this button inside an apex repeat that it's iterating over a list from my extension controller:
<apex:page standardController="Visit_Report__c" extensions="AddTopicsController" showHeader="false">
<head>
<script>
function openTask(topic, valid){
if(valid == "true"){
window.open("/00T/e?retURL=/apex/VF_ForceClose&tsk5=" + topic, "Popup", "location=1,status=1,scrollbars=1");
}
}
</script>
</head>
<body>
<apex:form >
<apex:pageBlock id="theBlock">
<apex:repeat value="{!topicsList}" var="topic">
<apex:commandButton value="New Action" action="{!checkErrors}" rerender="theBlock" oncomplete="openTask('{!topic.Title__c}', '{!isValid}')"/>
</apex:repeat>
</apex:pageBlock>
</apex:form>
</body>
</apex:page>
But it does not recognize the loop's variable. It says "Unknown property 'Visit_Report__cStandardController.topic'". I figured out it has to do with oncomplete but i'm not being able to understand why this happens.
Thank you!
Edit Controller code:
public class AddTopicsController {
public List<Topic__c> topicsList {get;set;}
public Visit_Report__c visit_report {get;set;}
public boolean isValid {get;set;}
public AddTopicsController(ApexPages.StandardController stdController){
visit_report = (Visit_Report__c) stdController.getRecord();
topicsList = [Select id, Title__c, Description__c, Visit_Report__c From Topic__c Where Visit_Report__c = :visit_report.Id];
isValid = false;
}
public Pagereference checkErrors(){
isValid = false;
boolean error = false;
if(!error){
isValid = true;
}
return null;
}
}
Edit 2: I found a workaround for this "bug", it involves transfering every action related to the topic variable to an action support element. solution:
<apex:commandButton value="New Action" reRender="theBlock" >
<apex:actionSupport event="onclick" action="{!checkErrors}" oncomplete="openTask('{!topic.Title__c}', '{!isValid}')" reRender="theBlock"/>
</apex:commandButton>