在加载时选择视觉力页面上的拾取列表选项



我有一个visualforce页面,其中有一个名为Topic的picklist,有时我需要在页面加载时选择其中一个picklist选项(这意味着Topic将从另一个页面传递,并且需要在第一次加载页面时选择)。我不知道该怎么做?我发布了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 ----------------------------------------------------->    
<<p> 顶端控制器/strong>
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>();
   }

您真正需要做的就是在构造函数(具有与类名称相同的名称的特殊函数)中将topic设置为某个初始值。你将它设置为某个值,然后它将在visualforce中正确渲染(假设相同的值是可选择的选项之一!)。

你省略了构造函数或<apex:page>标签,所以我们不知道你是如何导航到那个页面的。但对您来说最简单的方法可能是在URL中传递主题。如果你像这样进入页面:

/apex/MyPage?topic=Something, something

那么在构造函数中你可以这样做:

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

(URL参数的名称不必与变量名称相同,但至少相似是有意义的)

你可以阅读更多关于getParameters()

如果你的主题有可能包含& &;,空格等,你可能应该在建立链接时URLENCODE它

最新更新