I'm trying to update the boolean value named selected in wrapper class action support and onclick functions. Here is my code. Please let me know how to handle this

<apex:outputPanel id="table2">
        <div class="slds-pill_container" id="refresh">
          <apex:repeat value="{!selectedAccounts}" var="c" id="repeatTable2">
            <span class="slds-pill slds-pill_link">
              <a href="javascript:void(0);" class="slds-pill__action"
                title="Full pill label verbiage mirrored here">
                <span class="slds-pill__label">{!c.LeadName}</span>
              <button class="slds-button slds-button_icon slds-button_icon slds-pill__remove" title="Remove">
                 <a onclick="myActionFunction('{!c.selected}');" value="{!c.selected}" >
                <svg class="slds-button__icon" aria-hidden="true">
                  <use xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#close')}">
                <span class="slds-assistive-text">Remove</span>
          <apex:actionFunction name="myActionFunction" action="{!processUnselected}" reRender="table,table2"  >
                <apex:param name="selected" value=""/>

You can't use an actionFunction like this, because those methods don't have context: you can't tell which wrapper should be updated.

Option 1

Use an apex:commandLink instead.

<apex:commandLink onclick="{!c.toggleSelected}" value="{!c.selected}" >

Inside your wrapper class, add the method:

public void toggleSelected() {
  selected = !selected;

Option 2

Include the wrapper index to update:


Since you already know what the state is, you don't need to pass that in as a parameter; just toggle it directly.

public void myActionFunctionHandler(Integer index) {
    selectedAccounts[index].selected = !selectedAccounts[index].selected;

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.