0

I have a VF page with 3 tabs. I can't figure out why the value assigned to the activeTab String always gets set to the last value in the <ul>. I thought the events were separate for each <apex:actionSupport/> tag... could someone kindly tell me what I am doing wrong here?

Example: when the page first loads, the controller correctly sets the value to 'regularUSR'. However when any <li> is clicked, only the last value ('multiLicenseDeactivate') will get assigned.

UPDATE: I noticed that the onclick event apparently is firing for any click on the visualforce page, not just on the anchor tags / list items on the page.

VF page:

<ul id="myTab" class="nav nav-tabs">  
    <li id="li1" class="active"> 
      <a id="anchor1" href="#tab1" data-toggle="tab">
        <apex:actionSupport event="onclick" action="{!tabWasChanged}" reRender="ResultPanel1,ResultPanel2">
          <apex:param value="regularUSR" assignTo="{!activeTab}"></apex:param>
        </apex:actionSupport>
      Standard USR</a>
    </li>

    <li id="li2">
      <a id="anchor2" href="#tab2" data-toggle="tab">
        <apex:actionSupport event="onclick" action="{!tabWasChanged}" reRender="ResultPanel1,ResultPanel2">
          <apex:param value="multiLicenseActivate" assignTo="{!activeTab}"></apex:param>
        </apex:actionSupport>
      License Request</a>
    </li>
    <li id="li3">
      <a id="anchor3" href="#tab3" data-toggle="tab">
        <apex:actionSupport event="onclick" action="{!tabWasChanged}" reRender="ResultPanel1,ResultPanel2">
          <apex:param value="multiLicenseDeactivate" assignTo="{!activeTab}"></apex:param>
        </apex:actionSupport>
      License Deactivation</a>
    </li>
</ul> 

Extension:

public Boolean regularUSR {get;set;}
public Boolean multiLicenseActivate {get;set;}
public Boolean multiLicenseDeactivate {get;set;}
public String activeTab {get;set;}

public USRlicenseExtension(ApexPages.StandardController stdController) {
    u = (User_Support__c)stdController.getRecord();
    if(activeTab == null){activeTab = 'regularUSR';}
    tabWasChanged();
}

public PageReference tabWasChanged(){

    System.Debug('activeTab= '+activeTab);

    if(activeTab == 'regularUSR'){
        regularUSR = true;
        multiLicenseActivate = false;
        multiLicenseDeactivate = false;
    }

    else if(activeTab == 'multiLicenseActivate'){
        regularUSR = false;
        multiLicenseActivate = true;
        multiLicenseDeactivate = false;
    }

    else if(activeTab == 'multiLicenseDeactivate'){
        regularUSR = false;
        multiLicenseActivate = false;
        multiLicenseDeactivate = true;
    }

    return null;
}
  • The docs state "adds AJAX support to another component" so maybe that why it is attaching to the page and not the element. Try wrapping the children of the li in an output panel Also, Shots in the dark - The <li> has no Id so the Actionsupport is attached to li of which you have many. Try adding Id's to the li. Second, if you want the action support to only happen on the <a> tag you need to put it inside of the <a> tag. Additionally, not sure of the behavior of Action support when it is NOT used as a child of another apex component. – Eric Mar 6 '17 at 17:00
  • I have updated my actionSupport and apex:param tags to be inside of the anchor tag... however it is still firing on any click on the page. I have also added ids to the list items and anchors, but is there a way to map the actionSupport or apex:params to those ids? I think I'm missing something... – rmarq423 Mar 6 '17 at 17:08
  • do the outputPanel thing. I believe it needs to be a child of a component and not a regular html tag – Eric Mar 6 '17 at 17:13
  • That worked. You @Eric... are a life saver! – rmarq423 Mar 6 '17 at 17:18
  • Glad I could help. Your comment on firing when the page was clicked was the key. Nicely asked question – Eric Mar 6 '17 at 17:19
1

The docs state "adds AJAX support to another component"

<li id="li1" class="active"> 
  <apex:outPutPanel layout="inline">
  <a id="anchor1" href="#tab1" data-toggle="tab">
    <apex:actionSupport event="onclick" action="{!tabWasChanged}" reRender="ResultPanel1,ResultPanel2">
      <apex:param value="regularUSR" assignTo="{!activeTab}"></apex:param>
    </apex:actionSupport>
  Standard USR</a>
   </apex:outPutPanel>
</li>

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.