0

我有一个 visualforce 页面,其中有一个名为 Topic 的选项列表,有时我需要在页面加载时选择其中一个选项列表选项(这意味着主题将从另一个页面传递,并且需要在第一次加载页面时选择时间)。我不知道该怎么做?我正在发布处理主题选择的 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 ----------------------------------------------------->    

顶点控制器

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>();
   }
4

1 回答 1

0

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

您省略了构造函数或<apex:page>标记,因此我们不知道您是如何导航到该页面的。但对您来说最简单的方法可能是在 URL 中传递主题。因此,如果您访问这样的页面:

/apex/MyPage?topic=Something, something

然后在构造函数中你可以这样做:

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

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

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

如果您的主题存在包含 &、空格等的风险,您可能应该在构建链接时对其进行URLENCODE 。

于 2014-07-24T08:33:58.103 回答