+ Start a Discussion

Struggling with ajax

In fact, struggling with a lot...this is like the eleventeenth post I've made on this page and controller...it just keeps getting bigger. Anyway, here is the situation.  I have a datatable that I want to allow users to filter with two different picklists, which are called Unit and Principle. The datatables are reRendered based on dynamic soql queries generated by what they select from the filter picklists, and the constructor is set up so that the page defaults to be filtered to only record's in the User's Unit and All Principles. The user has to select the combination of Unit and Principle that they want and then click a Filter button to get a different view.  I actually have all that working.


The part that I am struggling with is getting the two picklist values to reRender. The Unit that a User selects should change the available Principles to select from and vice versa. So I am trying to use dynamic soql for this too. There were points in my playing around with it that it kind of worked...it would work up until the first time I clicked the filter button, but then anytime after it just pulled all values, and now it's just pulling all Values, and I can't get back to the partial success I was having. I'm pretty lost and tired at this point, so I am just going to throw the code out there to see if any of you has any ideas or opinions.  Thanks!


BTW, I am not going to post the entire controller or page because they are getting pretty long. 


public with sharing class narrativeWizard_Controller {
        public String accountID;
        public String swpnAccount { get; set; }
        public SchoolWorkPlanLog__c getLog { get; set; }
        public List<UniversalJoin__c> juncObs { get; set; }
        public List<cAIS> theWrappers { get; set; } 
        public Map<ID,List<cAIS>> theWrapperMap { get; set; }
        public List<DeployedStrategy__c> theDSs { get; set; }
        public List<Goal__c> theGoals { get; set; }
        public List<cGS> theGoalWrappers { get; set; }        
        public Set<String> unitOptions = new Set<String>();
        public String selectedUnit { get; set; }
        public Set<String> princyOptions = new Set<String>();
        public String selectedPrincy { get; set; }
        //public Set<String> catyOptions = new Set<String>();
        //public String selectedCaty { get; set; }
        public List<cCONS> theConWrappers { get; set; }
        public List<cCASES> theCaseWrappers { get; set; }
        public String unitFilter { get; set; }
        public Set<String> goalUnitOptions = new Set<String>();
        public String selectedGoalUnit { get; set; }
        //sets up class extension of SchoolWorkPlanLog__c
        private final SchoolWorkPlanLog__c swpn;
        public narrativeWizard_Controller(ApexPages.StandardController swpnController) {
            this.accountID = ApexPages.currentPage().getParameters().get('aID');
            this.swpn = (SchoolWorkPlanLog__c)swpnController.getRecord();
            this.getLog= new SchoolWorkPlanLog__c();
            this.selectedUnit = setUpUnitFilter();
            this.selectedGoalUnit = setUpUnitFilter();
        //pulls the Account from which the Log was initiated.
        public void setUpAccount() {
            Account acct = [select ID, Name from Account where ID = :accountID Limit 1];
            this.swpnAccount = acct.Name;
        //pulls the user who initiated the log so that lists can be filtered to the Unit they belong to.
        public String setUpUnitFilter() {
                ID UP = Userinfo.getUserId();
                User userX = [select ID, Name, Department__c, Unit__c from User where ID =:UP];         
                return userX.Unit__c;
        //pulls all Strategies to generate inital list of Unit options.
        public void getAllStrategyUnits() {
        	for(DeployedStrategy__c aDS : [select ID, Name, Principle__c, Category__c, Unit__c from DeployedStrategy__c where Account__c = :accountID And Status__c = 'Active']) {
        //generates query strings to pull Unit Options based on the Princple that was chosen.
        public void getStratyUnits() {
            List<DeployedStrategy__c> theDSs2= new List<DeployedStrategy__c>();
        	String queryString2;
        	if(this.selectedPrincy != 'All') {
        		queryString2 = 'select ID, Name, Principle__c, Category__c, Unit__c from DeployedStrategy__c where Account__c = :accountID And Status__c = \'Active\' and Principle__c =:selectedPrincy';
        	if(this.selectedPrincy == 'All') {
        		queryString2 = 'select ID, Name, Principle__c, Category__c, Unit__c from DeployedStrategy__c where Account__c = :accountID And Status__c = \'Active\'';
        	theDSs2 = Database.query(queryString2);
        	for(DeployedStrategy__c aDS : theDSs2) {
        public void getStratyPrincys() {
        	List<DeployedStrategy__c> theDSs3= new List<DeployedStrategy__c>();
        	String queryString3;
        	if(this.selectedUnit != 'All') {
        		queryString3 = 'select ID, Name, Principle__c, Category__c, Unit__c from DeployedStrategy__c where Account__c = :accountID And Status__c = \'Active\' AND Unit__c =:selectedUnit';
        	if(this.selectedUnit == 'All') {
        		queryString3 = 'select ID, Name, Principle__c, Category__c, Unit__c from DeployedStrategy__c where Account__c = :accountID And Status__c = \'Active\'';
        	theDSs3 = Database.query(queryString3);
        	for(DeployedStrategy__c aDS : theDSs3) {


<apex:pageBlock id="pb2">
          <apex:pageBlockSection columns="1">
              <apex:pageBlockSectionItem >
                  <apex:commandButton action="{!processSelected}" value="Save" style="left:300px;position:relative;" />
                  <apex:commandButton action="{!cancelButton}" value="Cancel" style="left:310px;position:relative;"/>
      <apex:pageBlockSection title="Select the Work Plans, Goals, Cases and Contacts that this Entry pertains to." collapsible="false" rendered="{!showAIandGoal}" columns="1">
          <apex:tabPanel switchType="client" selectedTab="tab1" >
              <apex:tab label="Work Plans" id="tab1">
              <apex:pageBlockSection collapsible="false" columns="3">
              <apex:pageBlockSectionItem >
               <apex:outputLabel value="Filter by Unit"/>
               <apex:selectList value="{!selectedUnit}" size="1" id="uniList">
                  <apex:selectOptions value="{!Units}"/>
                  <apex:actionSupport event="onchange" reRender="princyList" action="{!getStratyPrincys}" status="UnitStatus" />
                  <apex:actionStatus id="UnitStatus" startText="Fetching Principles..."/>
              <apex:pageBlockSectionItem >
              <apex:outputLabel value="Filter by Principle"/>
               <apex:selectList value="{!selectedPrincy}" size="1" id="princyList">
                  <apex:selectOptions value="{!Princys}"/>
                  <apex:actionSupport event="onchange" reRender="uniList" action="{!getStratyUnits}" status="PrincyStatus"/>
                  <apex:actionStatus id="PrincyStatus" startText="Fetching Principles..."/>
              <apex:pageBlockSectionItem >
                  <apex:commandButton action="{!makesStrategyWrappers}" reRender="table1" value="Filter">
                      <apex:actionSupport event="onchange" status="UnitStatus"/>
                      <apex:actionStatus id="UnitStatus" startText="Fetching Records..."/>






In the <action:support> tags, instead of  getStratyUnits use just StrayUnits and instead of  getStratyPrincys use StratiPrincys and see if this wroks. Otherwise have you tried wrting debug statementsfor the SelectList in the controller. This will help you find where the problem occurs and will know whether your actionsupport method is called each time the value changes.


Let me know if you have any concerns.



I already tried your first suggestion, but gave it a second shot, and got the same response, which is that the methods are not found. Any idea on why it's doing that?


To debug, I have added {!now()} within the selectList tags. The times are not changing. So I guess the fields are not being reRendered. Did you have something else in mind?





ok, I put system.asserts in each if statement to test if they were getting called when I changed the picklist...they are. So if the methods are being called, and the {!Now()} tags are showing me that the fields are not being reRendered, but I'm clearly asking those fields to be reRendered...what next?




Can you send me the picklist values for the custom fileds so that i can create the fiels on my instance and run the code.


Send me the Object Model : custom object and fields so that i can test it thoroughly.