1

I currently use the actionregion to rerender an image based on the input of a picklist field. This works by showing the image if I select the correct value in the picklist field. How do I do an actionsupport on pageload to initialize the rerender? The Idea is to have 2 images from which 1 is shown on pageload and based on the picklist value selected the corresponding image is shown. See:

Panel:

<apex:outputPanel id="RenderImage">                         
                    <apex:image id="theImage4" value="{!$Resource.HR1}" width="200" height="200" alt="HR Ketel" rendered="{!Opportunity.StartRecurrent__c=='0'}"/><br/><br/>
              </apex:outputPanel>

Actionregion:

<apex:actionRegion >
                          <apex:inputField value="{!Opportunity.StartRecurrent__c}">
                          <apex:actionSupport event="onchange" reRender="RenderImage" />
                          </apex:inputField>
                         </apex:actionRegion>
3
  • You wouldn't need to do so; the initial state would be calculated based on the value in the field. If it's not working right, we'd need to see more code than you've shown here, ideally a short, self-contained, correct example.
    – sfdcfox
    Mar 28, 2019 at 6:36
  • @sfdcfox I want to achieve this only from the input of the visualforce without info of the controller, or is this only possible with javascript?
    – Thomas
    Mar 28, 2019 at 6:47
  • You could set a default value on the field, or you can pass in a value as a page parameter, or you can use JavaScript. Any of the three might be appropriate depending on your use case.
    – sfdcfox
    Mar 28, 2019 at 6:52

1 Answer 1

2

For anyone else who bumps into this I solved this the following way:

<apex:outputPanel id="RenderImage" style="margin-left:50px"> 
                    <apex:image id="ImageInit" value="{!$Resource.HR1}" width="200" height="200" alt="HR Ketel" rendered="{!NOT(Opportunity.StartRecurrent__c=='0' || Opportunity.StartRecurrent__c=='1')}"/>
                    <apex:image id="Image1" value="{!$Resource.HR1}" width="200" height="200" alt="HR Ketel" rendered="{!Opportunity.StartRecurrent__c=='0'}"/>
                    <apex:image id="Image2" value="{!$Resource.HR2}" width="200" height="200" alt="HR Ketel" rendered="{!Opportunity.StartRecurrent__c=='1'}"/><br/><br/>
                </apex:outputPanel> 

You must log in to answer this question.

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