0

I have a VF that is used to return reults based on criteria selected by the user, the page consists on inputTexts and Checkboxes and a button that then refreshes the data. If i fill in inputTexts everything works fine, however, if i just fill in the checkBoxes the RefreshData method is not called (ive checked the debug logs and its not being called) and the correct results are not displayed (if both are filled in the query executes correctly). Any ideas what i'm missing? Code below!

Cheers Paul

.inputWidth { width: 80%; body {text-align:center;} }

</style>

    <apex:selectCheckboxes value="{!type}" title="Store type" style="labelCol">
        <apex:selectOptions value="{!storeType}"/>
    </apex:selectCheckboxes>

    <apex:selectCheckboxes value="{!fascia}" title="Fascia" >
        <apex:selectOptions value="{!storeFascias}"/>
    </apex:selectCheckboxes>
    <apex:outputPanel >
    <table border="0">
    <colgroup>
       <col span="1" style="width: 30%;"/>
       <col span="1" style="width: 25%;"/>
       <col span="1" style="width: 5%;"/>
       <col span="1" style="width: 25%;"/>
       <col span="1" style="width: 5%;"/>
    </colgroup>
    <tr>
    <td class="labelCol">
        <apex:outputtext >Store Size</apex:outputtext>
    </td>
    <td>
        <apex:inputtext value="{!jsSize}" styleClass="inputWidth"/>
    </td>
    <td class="labelCol">
        <apex:outputtext >+-</apex:outputtext>
    </td>
    <td>
        <apex:inputtext value="{!jsSizePerc}" styleClass="inputWidth"/>
    </td>
    <td class="labelCol">
        <apex:outputtext >%</apex:outputtext>
    </td>
    </tr>
    <tr>
    <td class="labelCol">
        <apex:outputlabel >Site Size</apex:outputLabel>
    </td>
    <td>
        <apex:inputtext value="{!compSize}" styleClass="inputWidth"/>
    </td>
    <td class="labelCol">
        <apex:outputtext >+-</apex:outputtext>
    </td>
    <td>
        <apex:inputtext value="{!compSizePerc}" styleClass="inputWidth"/>
    </td>
    <td class="labelCol">
        <apex:outputtext >%</apex:outputtext>
    </td>
    </tr>
    <tr>
    <td class="labelCol">
        <apex:outputtext >Distance from:</apex:outputtext>
    </td>
    <td>
        <apex:inputtext value="{!distFrom}" styleClass="inputWidth"/>
    </td>
    <td class="labelCol">
        <apex:outputtext >to:</apex:outputtext>
    </td>
    <td>
        <apex:inputtext value="{!distTo}" styleClass="inputWidth"/>
    </td>
    </tr>


    </table>
    </apex:outputPanel>

    <apex:pageBlockSectionItem >
    <apex:outputText >Government Region</apex:outputText>
    <apex:selectList id="grPicklist" value="{!gor}" size="1">
        <apex:selectOptions value="{!Govt}"/>
    </apex:selectList>
    </apex:pageBlockSectionItem>


    <apex:commandButton value="Refresh" action="{!refreshData}"/>

</apex:pageBlockSection>


<apex:pageBlocksection title="Results" columns="1">
    <apex:pageBlockTable value="{!analogues}" var="analogue">
        <apex:column value="{!analogue.Site__c}"/>    
        <apex:column value="{!analogue.S_Store__c}"/>                   
        <apex:column value="{!analogue.Forecast_Impact__c}"/>
        <apex:column value="{!analogue.Actual_Impact__c}"/>
        <apex:column value="{!analogue.Distance_miles__c}"/>
    </apex:pageBlockTable>

</apex:pageBlockSection>

Controller

public with sharing class AnalogueController {

public String gor { get; set; }
public String gors { get; set; }
public string storeFascia{get;set;}
public List<Pipeline_Impact__c> analogues {get;set;}
public double distTo { get; set; }
public double distFrom { get; set; }
public double compSizePerc { get; set; }
public double compSize { get; set; }
public String results { get; set; }
public double jsSizePerc { get; set; }
public double jsSize { get; set; }
public List<String> fascia { get; set; }
public List<String> type { get; set; }


private string soqlString{get;set;}

public String[] getFascia() {
    return fascia;
}

public void setFascia(String[] fascia) {

    this.fascia= fascia;
}

public AnalogueController(){
    soqlString = 'Select Site__r.SalesAreaSqFt__c, Site__r.Operator__c, Site__r.RecordTypeId, Site__r.Name, Site__c, ';
    soqlString += 'S_Store__r.SalesAreaSqFt__c, S_Store__c, Forecast_Impact__c, Distance_miles__c, Actual_Impact__c ';
    soqlString += 'From Pipeline_Impact__c Where Pipeline_impact__c.name != null';

   // analogues = Database.query(soqlString);
    RefreshData();
}

public PageReference refreshData() {

    system.debug('Dist From: ' + String.valueof(distFrom));
    system.debug('Dist To: ' + String.valueof(distTo));
    system.debug('Fascia: ' + fascia);
    system.debug('JS size: ' + String.valueof(jsSize));
    system.debug('JS Size%: ' + String.valueof(jsSizePerc));
    system.debug('Comp size: ' + String.valueof(compSize));
    system.debug('Comp size%: ' + String.valueof(compSizePerc));
    system.debug('RecordType: ' + type);
    system.debug('GOR: ' + type);

    soqlString = 'Select Site__r.SalesAreaSqFt__c, Site__r.Operator__c, Site__r.RecordTypeId, Site__r.Name, Site__c, Site__r.GovtRegion__c, ';
    soqlString += 'S_Store__r.SalesAreaSqFt__c, S_Store__c, Forecast_Impact__c, Distance_miles__c, Actual_Impact__c ';
    soqlString += 'From Pipeline_Impact__c Where Pipeline_impact__c.name != null';

    if(distTo > 0 && distFrom != null)
    {
        soqlString += ' and Distance_miles__c >= ' + distFrom + ' and Distance_miles__c <= ' + distTo;
    }

    if(jsSize > 0 && jsSizePerc > 0)
    {
        double jsSizeFrom = jsSize*((100-jsSizePerc)/100);
        double jsSizeTo = jsSize*((100+jsSizePerc)/100);
        system.debug('js from ' + jsSizeFrom);
        system.debug('js to ' + jsSizeTo);
        soqlString += ' and S_Store__r.SalesAreaSqFt__c >= ' + jsSizeFrom + ' and S_Store__r.SalesAreaSqFt__c <= '+ jsSizeTo;
    }

    if(compSize > 0 && compSizePerc >0)
    {
        double compSizeFrom = compSize*((100-compSizePerc)/100);
        double compSizeTo = compSize*((100+compSizePerc)/100);
        soqlString += ' and Site__r.SalesAreaSqFt__c >= ' + compSizeFrom + ' and Site__r.SalesAreaSqFt__c <= ' + compSizeTo;
    }
    system.debug(fascia);

    //determine which competitors to include

        if(gor != null)
        {
            soqlString += ' and Site__r.GovtRegion__c =\'' + gor + '\'';
        }    

    if(fascia != null)
    {
        if(fascia.size()>0)
        {
            String comps = String.join(fascia,'\',\'');
            String incComps = '(\'' + comps + '\')';
            system.debug('COMPS - ' + incComps);
            soqlString += ' and Site__r.Operator__c IN' + incComps;
        }
    } 

    if(type != null)
    {
        if(type.size()>0)
        {

            List<RecordType> ids = [select ID from RecordType where sObjectType = 'Store__c' and Name IN:type];
            system.debug('RECORD TYPES: ' + ids.size());
            soqlString += ' and S_Store__r.RecordTypeID IN:ids';

        }
    }

    system.debug(soqlString);

// for(string s : fascia) // { // system.debug(fascia); // }

    //system.debug(fascia);
    analogues = Database.query(soqlString);

    return null;
}

public List<SelectOption> getstoreFascias() { 
    List<SelectOption> fascias = new List<SelectOption>();
    fascias.add(new selectOption('JJ','JJ'));
    fascias.add(new selectOption('TT','TT'));
    fascias.add(new selectOption('AA','AA'));
    fascias.add(new selectOption('MM','MM'));
    fascias.add(new selectOption('WW','WW'));
    fascias.add(new selectOption('Other','Other'));
    return fascias;
    }


public List<SelectOption> getstoreType() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('S','S'));
            options.add(new SelectOption('C','C'));
            return options;
    }

    public List<SelectOption> getGovt(){
        List<SelectOption> gr = new List<SelectOption>();
        gr.add(new SelectOption('', ''));
        gr.add(new SelectOption('London', 'London'));
        gr.add(new SelectOption('South East', 'South East'));
        gr.add(new SelectOption('South West', 'South West'));
        gr.add(new SelectOption('Scotland', 'Scotland'));
        gr.add(new SelectOption('North West', 'North West'));
        gr.add(new SelectOption('North East', 'North East'));
        gr.add(new SelectOption('Yorkshire and the Humber', 'Yorkshire and the Humber'));
        gr.add(new SelectOption('West Midlands', 'West Midlands'));
 //       gr.add(new SelectOption{'East Midlands', 'East Midlands'));
        return gr;
        }

}

1

I believe you have to instantiate the lists that are used to back selectcheckboxes - certainly that's what my code does where I've used them before. E.g.

public AnalogueController(){
   soqlString = 'Select Site__r.SalesAreaSqFt__c, Site__r.Operator__c, Site__r.RecordTypeId, Site__r.Name, Site__c, ';
   soqlString += 'S_Store__r.SalesAreaSqFt__c, S_Store__c, Forecast_Impact__c, Distance_miles__c, Actual_Impact__c ';
   soqlString += 'From Pipeline_Impact__c Where Pipeline_impact__c.name != null';

   // analogues = Database.query(soqlString);
   RefreshData();
   type=new List<String>();
   fascia=new List<String>();
}

I'd also say you don't need the explicit get/setFascia methods as you have declared it as an automatic property:

public List<String> fascia { get; set; }
| improve this answer | |

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.