0

I have a commandbutton on a VF page that calls a method in the controller that should redirect to a new pagereference. When I select a value from a Selectcheckboxes control, the page will not redirect and it appears that the method that should be called from the commandbutton is never invoked. I tried debugging, but none of my debugs show in the log. I also tried disabling development mode. No luck.

public PageReference toResultsPage()
{
    //do stuff
    PageReference page = new PageReference(
        'https://c.cs51.visual.force.com/apex/SearchResults?searchString='+searchStringATLEAST+'&searchStringALL='+searchStringALL+'&searchStringEXACT='+searchstringEXACT+'&queryString='+contentsearchquery
    );
    return page.setredirect(false);  
}  

And the VF part:

<div class="col-md-12">  
    <div class="form-group text-center">  
        <apex:commandButton value="Enhanced Search" action="{!toResultsPage}" id="submit-search" styleClass="btn btn-primary gradient"/>      
     </div>
 </div>
  • Can you post the code which does the redirection please ? – SF_user Dec 23 '15 at 15:09
  • Just added the method in the page controller. This works if fileFilters is empty, but fails if I select any of the checkboxes associated with filetypefilters – Stephen Dec 23 '15 at 16:50
  • Please also post the markup for your commandButton. – Adrian Larson Dec 23 '15 at 17:53
  • do you see any required field on your vf page ? – Himanshu Dec 23 '15 at 19:13
  • There are no required fields on my page, but I do think I'm having an issue with validation. Any thoughts? – Stephen Dec 23 '15 at 19:46
1

The problem was that I didn't initialize the list returned by the checkboxes control. This line: filetypefilter=new list(); in the page constructor was not present in my original code and was causing the method called by the commandButton to fail, without an error. Also, if no values were selected from the list the method would fire, sending an email with no values. I could then make selections from the list and they would show in the email.

<apex:page controller="debugpage">  
<apex:form >
    <div class="col-md-4">           
        <h4>Refine by Document Type</h4>
        <apex:outputPanel id="files">
            <apex:selectCheckboxes value="{!fileTypeFilter}"  layout="pageDirection">
                <apex:selectOptions value="{!filelist}"/>
            </apex:selectCheckboxes>
        </apex:outputPanel>
    </div>  
    <apex:commandButton Action="{!MethodName}" value="Emailresult"/>  
</apex:form>  
</apex:page>  

public with sharing class debugpage {

public list<selectoption> fileList{get;set;}//list to populate document type boolean list
public list<string> fileTypeFilter{get;set;}//list returned from filetype filter

public debugpage(){

    filetypefilter=new list<string>();
    filelist=new list<selectoption>();
    list<AggregateResult> extensionList=new list<AggregateResult>();//initialize list for file_type_families__c
    extensionlist=[select  extension_family__c from file_type_family__c group by extension_family__c]; //query for file type families       
    for(aggregateResult ar:extensionlist){//for each record returned in query for file type families add to filelist as a selectoption
        fileList.add(new SelectOption((string)ar.get('Extension_Family__c'),(string)ar.get('Extension_Family__c') ));
    }
}
public PageReference MethodName() {

List<Messaging.SingleEmailMessage> mails =  new List<Messaging.SingleEmailMessage>(); 
String[] toAddresses = new String[] {'name@something.com'};

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();  
mail.setToAddresses(toAddresses);
system.debug(toAddresses);
mail.setReplyTo('Noreply@systemmessage.com');
mail.setSenderDisplayName('System Automated Message');
mail.setSubject('What got Selected');

String body = 'settings ';
For (String i : FileTypeFilter){
    Body+= 'Line '+i;
}
mail.setHtmlBody(body);
mails.add(mail);
System.debug(body);
System.debug(mails);
Messaging.sendEmail(mails);


    return null;
}

}

| improve this answer | |
0

If you want the PageReference to cause a redirect, don't call setRedirect(false). The default value is true.

Aside from this correction, you should construct your PageReference in such a way that it will work across all environments.

PageReference redirect = Page.SearchResults;
redirect.getParameters().put(searchString, someValue);
// etc.
return redirect;
| improve this answer | |
  • the page will go to the requested page whether redirect is true or false. It's set to false because I want to maintain the state of the page. The page that I'm redirecting to will use the same controller. – Stephen Dec 23 '15 at 18:48

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.