0

I have some picklists that I generate some values for. I have a reset button that makes the VFP page look as it does on pageload - the picklist values should be the first value of the list, which is blank ('')... but they do NOT revert to blank. They stay their chosen values. Input fields blank out and SOME picklist values DO 'reset', but not all. Thoughts?

VFP code

        <apex:form id="form" >
            <apex:pageblock >
                <apex:pageblocksection columns="2" id="pbSearch" >

                    <apex:selectList value="{!searchCriteria.PP}" label="Label" multiselect="false" size="1" style="width:100%">
                        <apex:selectOptions value="{!PPList}"/>
                    </apex:selectList>

    <apex:pageblocksectionitem >
                        <apex:outputlabel />
                        <apex:outputpanel >
                            <apex:commandbutton value="Search" style="width:25%" action="{!search}" status="PleaseWait" rerender="someTable"/>
                            <apex:commandbutton value="Reset" style="width:25%" action="{!reset}" rerender="pbSearch"  status="PleaseWait"/>

                        </apex:outputpanel>                               
                    </apex:pageblocksectionitem>    
    </apex:pageblocksection>  
</apex:pageblock>
</apex:form>

Controller

I've tried rerendering the form, the pageblock... but the picklist doesn't "reset"

//Reset Search parameters
    public void reset(){
        searchCriteria = new wrapsearch();
    }

And the values of the list are redacted, but the first value is:

optionsPP.add(new SelectOption('', ''));

EDIT: 11/05 - the REAL issue, is that when I select a value for that particular picklist, the command button will NOT run its method - only the getters for the picklist options run. Any ideas why?

3
  • your reset button isn't doing a rerender
    – cropredy
    Commented Nov 5, 2015 at 6:34
  • I've updated the code. Even with a Rerender, not ALL picklists reset to blank. Some input fields and SOME picklists do, but not all - specifically the one listed in the above example. Any thoughts?
    – RC82
    Commented Nov 5, 2015 at 15:53
  • we're confused - is the problem your edit of 11/05 or the comment you posted 2 hours ago? More code exposed (simplified - no code dumps please) of inner class wrapsearch and action method search might hellp
    – cropredy
    Commented Nov 5, 2015 at 18:47

1 Answer 1

0

Recently I needed to create a page that received some user input, then the user would click a button to send the information, and reload the page with some fields being reset to empty.

When working with Visualforces like in this case, you need to remember that the information displayed in the page comes from a variable you have in your controller. So if you create a new instance of an object in your controller, and in your page you reference this object's fields, it will appear as empty, since all you have done is to instantiate a blank object.

If you need to do something in the database, and return an empty form, you need a return null in the method that the button calls (so it can reload the page), and, when loading the page, you need to instantiate a new, empty, object when the controller is called (for example: when the page is reloaded).

4
  • Hey I tried making it a page reference, return null, but nothing. I found the REAL issue though - it seems that when I have an option selected for that picklist, and then press the 'reset' button, it will NOT run the reset method,and any other command button won't run its method either. It just re-runs all the getters for the picklists. Any thoughts why?
    – RC82
    Commented Nov 5, 2015 at 16:28
  • If you need the page reset when you call the reset method, then you should find a way for it to return null and rerender the page. Currently, since it returns void, the page doesn't know how to behave. That's my guess for now... Commented Nov 5, 2015 at 16:43
  • 1
    I've changed it to a pagereference, and nothing. The issue is that the method won't run at all if that picklist has a value, as per the debug logs. This is very strange... thanks for the help so far.
    – RC82
    Commented Nov 5, 2015 at 17:29
  • Might not be related, but have you removed the "rerender" attribute in the commandbutton tag after changing the method to return a null PageReference? Commented Nov 5, 2015 at 17:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .