【问题标题】:Custon object fields from controller not displayed using apex:outputfield in VF page来自控制器的自定义对象字段未使用顶点显示:VF 页面中的输入字段
【发布时间】:2016-05-01 09:48:31
【问题描述】:

我正在使用标签在 VF 页面中显示控制器的自定义对象字段。从选择列表中选择值(使用 实现)后,我已放置标签以从控制器中的数据库中检索自定义对象。现在我想在 VF 页面中显示这个 RETRIVED 对象的字段 onchange of picklist value。这些值没有显示出来。 我知道这是非常基本的,请帮助我清除任何愚蠢的错误!

VF 页面:

<apex:form>
        <apex:pageblock >
            <apex:pageBlocksection title="Attribute Details">
                <apex:tabpanel switchtype="client">
                    <apex:tab label="Script 1" id="s1" labelWidth="90px">
                        <h1>
                            Choose Script:
                        </h1>
                        <apex:selectlist value="{!selectedValue}" size="1" id="selectID">
                            <apex:selectOptions value="{!scriptoptions}" />
                        </apex:selectlist>
                        <br/>
                        <apex:outputPanel id="thisPanel">
                            <apex:actionSupport event="onchange" action="{!setValues}" rerender="thisPanel" />
                            <apex:actionStatus startText="fetching related values..."
                                               stopText="" id="actionStatus"/>
                            <outputfield label="Executioner" value="{!valueResult.Executioner_Emp_ID__c}"/>
                            <br/>
                            <outputfield label="Planner" value="{!valueResult.Planner_Emp_ID__c}"/>
                            <br/>
                            <outputfield label="Reviewer" value="{!valueResult.Reviewer_Emp_ID__c}"/>
                        </apex:outputPanel>
                    </apex:tab>.....

控制器:

public class ScriptAttributesController 
{

    public String setValues { get; set; }
    public List<Test_script__c> scriptListWithValues = [select name, id, Executioner__c, Planner__c, Reviewer__c from Test_Script__c];
    public static Test_Script__c valueResult {get;set;}
    public String selectedValue {get;set;}

    //public Test_Script__c returnedTestScript {get;set;}

    public void ScriptAttributesController()
    {
    }

    public List<SelectOption> getScriptoptions()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('select a value','select a value'));
        for(Test_Script__c s: scriptListWithValues )
        {
            options.add(new SelectOption(s.id,s.name));
        }
        return options;
    }

        public void setValues()
    {
        system.debug('ValueResult: '+valueResult);
        system.debug('selectedValue: '+selectedValue);
        valueResult=[select name, id, Executioner_Emp_ID__c, Planner_Emp_ID__c, Reviewer_Emp_ID__c, Iteration__c from Test_Script__c where id=:selectedValue limit 1];
        system.debug('ValueResult: '+valueResult);
    }

【问题讨论】:

    标签: controller salesforce visualforce


    【解决方案1】:

    有两个错误:

    1. 第一个是 apex:actionSupport 标签应该在 apex:selectlist 内。此外,如果您想显示当前的操作状态,您应该使用 apex:actionSupport 中的 status 属性。

    2. 另一个是你应该使用apex:outputfield而不是简单的outputfield

    这里是固定代码:

    <apex:form>
            <apex:pageblock >
                <apex:pageBlocksection title="Attribute Details">
                    <apex:tabpanel switchtype="client">
                        <apex:tab label="Script 1" id="s1" labelWidth="90px">
                            <h1>
                                Choose Script:
                            </h1>
                            <apex:selectlist value="{!selectedValue}" size="1" id="selectID">
                                <apex:selectOptions value="{!scriptoptions}" />
                                <apex:actionSupport event="onchange" action="{!setValues}" rerender="thisPanel" status="actionStatus"/>
                            </apex:selectlist>
                            <br/>
                            <apex:outputPanel id="thisPanel">
                                <apex:actionStatus startText="fetching related values..."
                                                   stopText="" id="actionStatus"/>
                                <apex:outputfield label="Executioner" value="{!valueResult.Executioner_Emp_ID__c}"/>
                                <br/>
                                <apex:outputfield label="Planner" value="{!valueResult.Planner_Emp_ID__c}"/>
                                <br/>
                                <apex:outputfield label="Reviewer" value="{!valueResult.Reviewer_Emp_ID__c}"/>
                            </apex:outputPanel>
                        </apex:tab>.....
    

    【讨论】:

      猜你喜欢
      • 2012-05-28
      • 2013-12-08
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多