7

I want to Implement functionality with one picklist for selecting object Id and several tabs presenting details of selected record. Each of tabs will have separate controller, but needs selected object id as an input. At first I thought that passing that parameter via page parameters is appropriate approach, but when I switch between the tabs, the parameter is reset. Is there any better way to do that, or am I missing something in my code? Below I enclose simplified code:

Parent page for selecting object id

<apex:page standardStylesheets="false" sidebar="false" showHeader="false" controller="testParentCtr">
  <apex:form >
      <apex:selectList value="{!param}" size="1" >
          <apex:selectOption itemLabel="1" itemValue="1" />
          <apex:selectOption itemLabel="2" itemValue="2" ></apex:selectOption>
          <apex:selectOption itemLabel="3" itemValue="3" ></apex:selectOption>      
      </apex:selectList>  
      <apex:commandButton rerender="tabpanel"  value="Set"/>
  </apex:form>

  <br/> 
  Parent Page->CurrentPage.parameters.param: {!$CurrentPage.parameters.param}
  <br/>
  ApexPages.currentPage().getParameters().get('param'): {!param}

        <apex:tabPanel switchType="server" id="tabpanel">
            <apex:tab label="child1"><apex:include pageName="child" /></apex:tab>
            <apex:tab label="child2"><apex:include pageName="child" /></apex:tab>
        </apex:tabPanel>   

</apex:page>

and it's controller

public with sharing class testParentCtr {

    public String param{
        get;
        set{ 
            ApexPages.currentPage().getParameters().put('param', value ); //hope this will propagate 'param' new value to child page
            param=value; 
           } 
        }

   public testParentCtr(){
       this.param =  ApexPages.currentPage().getParameters().get('param'); //just bind to param to set default value on selectList
   }

}

Plus the child page (included in tabs)

<apex:page controller="testChildCtr" standardStylesheets="false" sidebar="false" showHeader="false">

  Child->CurrentPage.parameters.param:{!$CurrentPage.parameters.param}
  <br/>
  Child->ApexPages.currentPage().getParameters().get('param') :{!param}

</apex:page>

and it's controller.

public with sharing class testChildCtr {

public String getParam(){
    return ApexPages.currentPage().getParameters().get('param'); 
}

}

Thank You for advise.

1

I would use a visualforce component for your childpage instead of visualforce page. So at least you can pass attributes from the parent to the children easily.

<apex:tab>
<c:childPage myfield="{!an_amazing_field}" otherfield="{!another_nice_Field}" />
</apex:tab>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.