• Abul Jasser 8
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi,

Unable to pass parameters while navigating between pages

Scenario:
Using iFrame to show the page content. 
iFrame > apex:page > apex:pageBlock 
The pageBlock contains 3 apex:components, only one out of three is rendered at a time. 
<apex:page controller="myController">
    <script>
          var localJavascriptVariable = '';
          setVariables('a', 'b', 'c');
          showComponent1();
    </script>


    <apex:pageBlock>
            <c.component1 />
            <c.component2 />
            <c.component3 />
    </apex:pageBlock>

    <apex:form >
        <apex:actionFunction name="showComponent1" action="{!renderComponent1}">
        </apex:actionFunction>
        <apex:actionFunction name="showComponent2" action="{!renderComponent2}">
        </apex:actionFunction>
        <apex:actionFunction name="showComponent3" action="{!renderComponent3}">
        </apex:actionFunction>
        <apex:actionFunction name="setVariables" action="{!assignValues}">
             <apex:param id="myValue1" assignTo="{!stringFromComponent1}" value=""/>
             <apex:param id="myValue2" assignTo="{!stringFromComponent2}" value=""/>
             <apex:param id="myValue3" assignTo="{!stringFromComponent3}" value=""/>
        </apex:actionFunction>
    </apex:form>


<apex:page>
'myController' takes care of the navigation between of the components
public class myController {

    public string stringFromComponent1 { get; set; }
    public string stringFromComponent2 { get; set; }
    public string stringFromComponent3 { get; set; }
    
    public Boolean componentVisible1 { get; set; }
    public Boolean componentVisible2 { get; set; }
    public Boolean componentVisible3 { get; set; }
    
    public myController() { 
        componentVisible1 = true;
        componentVisible2 = false;
        componentVisible3 = false;
    }

    public PageReference renderComponent1() {
        componentVisible1 = true;
        componentVisible2 = false;
        componentVisible3 = false;
        return null;
    }

    public PageReference renderComponent2() {
        componentVisible1 = false;
        componentVisible2 = true;
        componentVisible3 = false;
        return null;
    }

    public PageReference renderComponent3() {
        componentVisible1 = false;
        componentVisible2 = false;
        componentVisible3 = true;
        return null;
    }

    public PageReference assignValues() {
        stringFromComponent1 = System.currentPagereference().getParameters().get('myValue1');
        stringFromComponent2 = System.currentPagereference().getParameters().get('myValue2');
        stringFromComponent3 = System.currentPagereference().getParameters().get('myValue3');
        return null;
    }
Everytime the components are swapped, the values stored in stringFromComponent1, stringFromComponent2,  stringFromComponent3 is reset and the localJavascriptVariable looses value in it .

Question:
1. I think the component swap is rerendering the page and hence the local variables are lost, how to stop it from this behaviour?
2. While swapping another instance of  controller is created. How to let all components use same instance of same controller?

Thanks in advance!