0

嗨,我正在写一个视觉力量,其代码是

 <apex:page id="pageId" controller="FieldSetDemonstration">  
<apex:form id="formId">  
    <apex:pageblock id="pbId">  
        <apex:pageblocksection columns="1" id="pbsIs">  
            <apex:repeat value="{!Fields}" var="f">  
                <apex:outputLabel value="{!merch[f]}">  
            </apex:outputLabel></apex:repeat>  
        </apex:pageblocksection>  
    </apex:pageblock>  
</apex:form>  
</apex:page>

控制器代码是 public class FieldSetDemonstration {

public Resource__c merch { get; set; }

public FieldSetDemonstration() {
    this.merch = getMerchandise();
}

public List<Schema.FieldSetMember> getFields() {
    return SObjectType.Resource__c.FieldSets.Hello2.getFields();
}

private Resource__c getMerchandise() {
    String query = 'SELECT ';
    for(Schema.FieldSetMember f : this.getFields()) {
        query += f.getFieldPath() + ', ';
    }
    query += 'Id  FROM Resource__c LIMIT 1';
    System.debug('Hello world debug log');
   Resource__c res= Database.query(query);
   Object re=res.Resource_Position__r.Name;

System.debug('Hello World 调试日志'+''+res); System.debug('Hello World1'+query); 返回资源;} }

和系统日志值是

12:28:55.052 (52125000)|USER_DEBUG|[22]|DEBUG|Hello World 调试日志Resource__c:{Name=Hello Bro, OwnerId=00590000001V6loAAC, Id=a04900000023JI7AAM}

12:28:55.052 (52157000)|USER_DEBUG|[23]|DEBUG|Hello World1 SELECT Resource_Position__r.CreatedById, Resource_Position__c, Name, Owner.Email, Resource_Position_r.Name , Id FROM Resource_c LIMIT 1

代码中的 Resource__c 和 Resource_Position__c Hello2 是一个包含以下字段的字段集

资源职位 > 资源职位名称

资源位置

资源名称

我面临的问题不是显示所有三个字段的值 1.Resource Position>Resource Position Name 2.Resource Position 3.Resource Name 它的显示值只有 Resource Name 没有值

资源位置>资源位置名称

资源位置

但是我将 Resource_Position_c对象与 Resource_c对象相关联,为什么它没有显示这两个字段的值,任何人都可以帮助解决这个问题。你的帮助非常值得

如果我在字段集 hello2 Owner ID>E-mail 中再添加一个字段,那么它在 visualforce 页面中显示所有者的正确电子邮件地址唯一的问题是来自此自定义对象的字段名称,谁能告诉我为什么它没有为 Resource_Position__c.name 字段赋值

4

1 回答 1

0

更改<apex:outputLabel value="{!merch[f]}"><apex:outputLabel value="{!merch[f.fieldPath]}">

于 2013-01-08T15:46:46.700 回答