Skip to content

Instantly share code, notes, and snippets.

@peterknolle
Last active December 12, 2015 08:18
Show Gist options
  • Save peterknolle/4742979 to your computer and use it in GitHub Desktop.
Save peterknolle/4742979 to your computer and use it in GitHub Desktop.
Some Visualforce and Apex experimentation with rerendering
public with sharing class RerenderNoAction {
public RerenderNoAction() {
viewMeCnt = 0;
}
public Integer viewMeCnt { get; set; }
public String parentOpt { get; set; }
public List<SelectOption> getParentOptions() {
List<SelectOption> opts = new List<SelectOption>();
opts.add(new SelectOption('',''));
opts.add(new SelectOption('1', '2'));
opts.add(new SelectOption('3', '4'));
return opts;
}
public String opt { get; set; }
public List<SelectOption> getOptions() {
viewMeCnt = viewMeCnt + 1;
List<SelectOption> opts = new List<SelectOption>();
if (parentOpt == '1') {
opts.add(new SelectOption('1111', '2222'));
opts.add(new SelectOption('3333', '4444'));
} else {
opts.add(new SelectOption('7777', '8888'));
opts.add(new SelectOption('9999', '0000'));
}
return opts;
}
}
<apex:page controller="RerenderNoAction" showheader="false" sidebar="false" standardStylesheets="false">
<apex:form >
<apex:actionRegion >
<apex:selectList value="{!parentOpt}" multiselect="false" size="1">
<apex:selectOptions value="{!parentOptions}"/>
<apex:actionsupport event="onchange" rerender="panel" />
</apex:selectList>
</apex:actionRegion>
<br />
<apex:outputPanel id="panel">
Here we are!<br/>
View Count: {!viewMeCnt}<br />
<apex:selectList value="{!opt}" multiselect="false" size="1" required="true" id="opt">
<apex:selectOptions value="{!options}" />
</apex:selectList>
</apex:outputPanel>
</apex:form>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment