0

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>
15
  • What exactly are you trying to do? And could you also post the controller code? Commented Nov 22, 2016 at 11:22
  • Do you have a getter method within your controller thats defined as "topic"?
    – TSmith
    Commented Nov 22, 2016 at 11:23
  • My controller code is just a booolean set to true for test purposes. What i'm trying to do is to open a window on click with those parameters. but with onclick the controller does not update on time to set my parameters true values. So i'm forced to use oncomplete. But using this it does not recognize my loop variable.
    – user37586
    Commented Nov 22, 2016 at 11:24
  • No getter method. Topic is suppose to be my loop variable. I have a {get;set;} on my list.
    – user37586
    Commented Nov 22, 2016 at 11:25
  • Paste your controller code to your question so we can help.
    – TSmith
    Commented Nov 22, 2016 at 11:25

2 Answers 2

0

It seems the apex:commandButton is not recognising the repeat variable. I would suggest you to use the apex:input type="button" instead if you can.

<input type="button" oncomplete="openTask('{!topic.Title__c}', '{!isValid}')" value=" click here " class="btn"/>

You also have to write another actionSupport method which will execute your action method in the controller. I am not sure if it has any other alternatives.

0

There seems to be a Limitation in oncomplete which does not accept any Page side variables.

Since checkErrors is already a pagereference method, you can pass the parameters using to controller and perform the action done in openTask JS Method

Thanks

1
  • This solution does not work in this case unfortunately :s i need to have access to that specific topic object that is assigned to that specific button. i found a solution and will post it. thank you very much for your input!
    – user37586
    Commented Nov 22, 2016 at 14:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .