0

I have a requirement in which when select the checkbox based on the value of checkbox i.e. true or false, I have to pass the value to Apex class method and based on the value of checkbox it should display an status images. I have modified the code in VF page like this:

    j$('.voCheckbox').click(function() {
        j$('[id$=":selectedVerifiableOutcomeIdInput"]').val(j$(this).data("output"));
        j$('[id$=":currentStageInput"]').val(j$(this).data("stage"));
        completeActionJSCheck();
    });
<apex:actionFunction action="{!completeActionCheck}" name="completeActionJSCheck" >
     <apex:param name="v" value="" assignTo="{!myCheckbox}" /> 
</apex:actionFunction>

VF code for setting the image based on the value of checkbox:

    <label class="outcome-name">{!output.Name}:</label>
    <apex:outputPanel layout="none" rendered="{!currentOpportunity[output.FieldName__c] == true}">

    <input type="checkbox" class="voCheckbox"  Checked="Checked" Value="true" event="onselect" style="vertical-align: middle" data-outcome="{!outcome.Id}" enable="true"/>
    <i class=" green"></i>

    </apex:outputPanel>
    <apex:outputPanel layout="none"  rendered="{!currentOpportunity[output.FieldName__c] == false}">
    <input type="checkbox" Checked="False" class="voCheckbox" event="onselect" style="vertical-align: middle" data-outcome="{!outcome.Id}" enable="true"/>
    <i class="fa fa-times red"></i>
</apex:outputPanel>
</apex:outputPanel>

in the above code I have used to pass the value to the Boolean variable myCheckbox. But on UI when I select/disselect the checkbox then it thows and error. "Value not of required type".

in Apex class I have modified the below code :

public boolean myCheckbox {get; set;}
ActionResult result = ActionFactory.getInstance(selectedOutputId, oppId).execute(myCheckbox);
 checkActionResult(result);

Can somebody help me what I am missing here? My target is i

0

I think you should not use an actionFunction, but rather actionSupport. Your checkbox will look something like this;

<apex:inputCheckbox value="{!myCheckbox}>
    <apex:actionSupport event="onchange" action="{!myApexFunction}" />
</apex:inputCheckbox>

In this case the checkbox will be automatically posted to the controller, so there's no need to pass it as a parameter. For reference; the documentation of the actionSupport element.

  • Hi @Lex when I add the below code <apex:inputCheckbox value="{!myCheckbox}"> <apex:actionSupport event="onchange" action="{!completeActionCheck}" /> </apex:inputCheckbox> then it does not load the lage because in my case based on the value of true and false I am setting the images based on page load.I have added the image code In the question. please check – Dhananjay Patil Aug 11 '16 at 6:42
  • It seems to me you want to show a different image, based on the value of a chechbox. In that case you can still use actionSupport. I suggest you check the documentation, especially the part about the rerender attribute. You can also use it in conjunction with actionRegion, that would be helpful to you as well. Currently, the question is too unclear for me to provide more detailed code snippets. – rael_kid Aug 11 '16 at 6:49
  • the reason I am using actionfunction because it is under the <apex:form> that's why I have to use actionFunction in this case – Dhananjay Patil Aug 11 '16 at 7:12
  • An actionSupport can also be a child of a form. In fact, it has to be. – rael_kid Aug 11 '16 at 8:58

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.