2014-07-22 67 views
0

我有一個包含選取列表的主題的Visualforce頁面,有時我需要在頁面加載時選擇其中一個選項列表選項(表示該主題將從另一個頁面傳遞並且將需要在第一次加載頁面時選擇)。我不知道如何做到這一點?我正在發佈處理主題選擇和下面的Controller代碼的Visualforce頁面的一部分。任何幫助將不勝感激。謝謝。在加載時在可視化頁面上選擇選項列表選項

Visualforce頁面:

<!---------------------------------- Select Topic ----------------------------------------------------->  
        <apex:pageblockSection title="Select the Topic" >  
          <apex:selectList value="{!topic}" size="1"> 
           <apex:outputlabel for="Topic" value="Pick a Topic :" ></apex:outputlabel> &nbsp;&nbsp;&nbsp; 
           <apex:selectOptions id="topic" value="{!Topics}"/> 
            <apex:actionSupport action="{!populateParameters}" reRender="parametersSection,querySection" event="onchange"/> 
          </apex:selectList> 
        </apex:pageblockSection> 
      <!---------------------------------- End of Select Topic ----------------------------> 

      <!---------------------------------- Parameters for Topic ----------------------------------------------------->  
       <apex:pageblockSection id="parametersSection" title="Input Parameters"> 
        <apex:repeat value="{!topicpParamWrapperList}" var="params"> 
         <apex:outputPanel > 
          <apex:outputlabel value="{!params.parameter.Name}" ></apex:outputlabel> &nbsp;&nbsp;&nbsp; 
          <apex:inputfield value="{!params.parameter.inputValue__c}" rendered="{!params.renderAsText}"> 
           <apex:actionsupport action="{!placeValuesInQuery}" reRender="querySection,splunUrlLink" event="onchange"/> 
          </apex:inputfield> 
          <apex:inputfield value="{!params.parameter.DateTimeValueHolder__c}" rendered="{!params.renderAsDate}"> 
           <apex:actionsupport action="{!placeValuesInQuery}" reRender="querySection,splunUrlLink" event="onchange"/> 
          </apex:inputfield> 
         </apex:outputPanel> 
        </apex:repeat> 
       </apex:pageblockSection> 
      <!---------------------------------- End of Parameters for Topic ----------------------------------------------------->  

的Apex控制器

public List <topicpParamWrapper> topicpParamWrapperList { 
     get; 
     set; 
    } { 
     topicpParamWrapperList = new List <topicpParamWrapper>(); 
    } 


public void populateParameters() 
{ 
     if(!topicpParamWrapperList.isEmpty()) 
     { 
       topicpParamWrapperList.clear(); 
     } 

     if(topic!='' && topic!=Null) 
     { 
       for(Query_Parameter__c qParam :[select id, Parameters__r.Variable_Name__c, Parameters__r.Type__c,Parameters__r.Name from Query_Parameter__c where Topics__c=:topic]) 
       { 
         Parameters__c param = new Parameters__c(); 
         param.Name =qParam.Parameters__r.Name ; 
         param.type__c = qParam.Parameters__r.type__c; 
         param.Variable_Name__c=qParam.Parameters__r.Variable_Name__c; 
         topicpParamWrapperList.add(new topicpParamWrapper(param)); 
       } 
       getQueryToRun(); 
     } 

} 

public void getqueryToRun(){ 

     if(mapTopics.containsKey(topic)) 
     { 
       this.queryToRun =mapTopics.get(topic).query__c; 
       this.queryMain=mapTopics.get(topic).query__c; 
     } 

} 

public List <topicpParamWrapper> paramList { 
     get; 
     set; 
    } { 
     paramList = new List <topicpParamWrapper>(); 
    } 

回答

0

你真正需要做的是將topic設置在構造函數(一些初始值的特殊功能具有與課程名稱相同的名稱)。您將其設置爲某個值,然後它將在visualforce中正確呈現(假設相同的值是可選選項之一!)。

您省略了構造函數或<apex:page>標記,因此我們不知道如何導航到該頁面。但是最簡單的方法是在URL中傳遞主題。所以,如果你訪問這樣的頁面:

/apex/MyPage?topic=Something, something 

然後在構造函數中,你可以這樣做:

topic = ApexPages.currentPage().getParameters().get('topic'); 

(URL參數的名稱不一定是相同的變量名但它是有道理讓他們至少類似)

你可以閱讀更多關於getParameters()

如果有風險,你的主題將包含&,空間等,你可能應該URLENCODE建立鏈接時。

相關問題