I have a custom home page narrow component i.e. My Component that have the following code in it to show my custom VF Page in an iframe
`
<style>#sidebarDiv .sidebarModule .sidebarModuleBody{ padding:0px;}</style><iframe style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; WIDTH: 200px; HEIGHT: 290px; BORDER-TOP: medium none; BORDER-RIGHT: medium none" src="/apex/samplePage"></iframe>
In my VF Page, I have a drop down list to show on the page. User can select different values from the pick list and it shows greetings based on the value (for example).
The issue is:
Whenever, the page refreshes or user goes to a different component in the SFDC, the home page narrow component gets refreshed as well, and the value for the pick list is set to the default value.
Need: I want it to retain the last selected value that use had it in the pick list, instead of setting it again to default value.
My thoughts:
I was thinking to get the reference to last selected value and pass it as a parameter in iFrame to my VF Page and have VF Page read this value in the beginning and set the value of the pick list.
How can I get the reference to the last selected value of the pick list in home page narrow component code? (listed above) Is it possible to retrieve the value of the selected pick list? If Not, then what should I be doing in my VF Page to ensure I always set the value to the last selected value, instead of the default value.
Following is the sample code
<!-- Page: -->
<apex:page controller="sampleCls" showHeader="false" >
<apex:form >
<apex:selectList value="{!countries}" multiselect="false" size="1" >
<apex:selectOptions value="{!items}"/>
</apex:selectList>
<p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel >
<p>You have selected:</p>
{!country}
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>
...
...
/* Controller: */
public class sampleCls {
public String countries{get;set;}
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;
}
public String getcountry() {
return countries;
}
}