如何在顶点:PageBlockTable中输出自定义对象名称字段的超链接

时间:2013-02-01 16:53:04

标签: hyperlink salesforce fieldset

听起来很简单,但我从多个字段集中获取表格中的值输出,因此管理员用户可以自定义表格中显示的列。

这是我正常运作的页面块...

        <apex:pageBlock title="{!$Label.Search_Results}">
        <apex:pageBlockTable value="{!SearchResults}" var="pictureGallerySearchResult" title="SearchResults">
            <apex:column headerValue="Image" styleClass="imageDataCell">
                <a target="_blank" href="/servlet/servlet.FileDownload?file={!pictureGallerySearchResult.ActualAttachment.Id}" >
                    <img class="searchResultImage" style="{!SearchResultsImageStyle}" src="/servlet/servlet.FileDownload?file={!pictureGallerySearchResult.ActualAttachment.Id}" alt="{!pictureGallerySearchResult.ActualAttachment.Name}"/>
                </a>
            </apex:column>
            <apex:column headerValue="Test" value="{!pictureGallerySearchResult.Project[pictureGallerySearchResultField]}"/>
            <apex:repeat value="{!$ObjectType.Project__c.FieldSets.Picture_Gallery_Search_Results}" var="pictureGallerySearchResultField">
                <apex:column headerValue="{!$ObjectType.Project__c.Fields[pictureGallerySearchResultField].label}" value="{!pictureGallerySearchResult.Project[pictureGallerySearchResultField]}"/>
            </apex:repeat>              
            <apex:repeat value="{!$ObjectType.Store__c.FieldSets.Picture_Gallery_Search_Results}" var="pictureGallerySearchResultField">
                <apex:column headerValue="{!$ObjectType.Store__c.Fields[pictureGallerySearchResultField].label}" value="{!pictureGallerySearchResult.Store[pictureGallerySearchResultField]}"/>
            </apex:repeat>
            <apex:repeat value="{!$ObjectType.Visit__c.FieldSets.Picture_Gallery_Search_Results}" var="pictureGallerySearchResultField">
                <apex:column headerValue="{!$ObjectType.Visit__c.Fields[pictureGallerySearchResultField].label}" value="{!pictureGallerySearchResult.Visit[pictureGallerySearchResultField]}"/>
            </apex:repeat>
            <apex:repeat value="{!$ObjectType.Photo_Attachment__c.FieldSets.Picture_Gallery_Search_Results}" var="pictureGallerySearchResultField">
                <apex:column headerValue="{!$ObjectType.Photo_Attachment__c.Fields[pictureGallerySearchResultField].label}" value="{!pictureGallerySearchResult.PhotoAttachment[pictureGallerySearchResultField]}"/>
            </apex:repeat>
        </apex:pageBlockTable>
    </apex:pageBlock>

您可以看到我在第一列中为图像创建了一个“硬编码”超链接,但我想动态超链接一个字段,如果它是自定义对象的名称字段。

例如,如果是字段集......

$ObjectType.Project__c.FieldSets.Picture_Gallery_Search_Results

...包含一个名为“Name”的字段,我想插入一个超链接,将您带到salesforce页面以查看该项目。

首先,我需要能够确定该字段是否为自定义对象名称字段,其次,输出超链接而不是标签。

如果有人有任何想法,我会非常感激。

感谢您花时间阅读本文。

2 个答案:

答案 0 :(得分:2)

您是否考虑过在APEX控制器/分机中执行此逻辑?执行查询后,您可以迭代结果,确定您希望每个超链接的超链接,并填充您在Visualforce页面中显示的地图,该地图由搜索结果中的某个唯一值(可能是ID)和值组成。将是超链接。然后在您的Visualforce迭代器中,您可以映射[SearchResult.Id]或任何键结束。

答案 1 :(得分:1)

<apex:column headerValue="{!$Label.Filename}">{!pictureGallerySearchResult.ActualAttachment.Name}</apex:column>
<apex:repeat value="{!$ObjectType.Project__c.FieldSets.Picture_Gallery_Search_Results}" var="pictureGallerySearchResultField">
    <apex:column headerValue="{!$ObjectType.Project__c.Fields[pictureGallerySearchResultField].label}">
        <apex:outputLabel value="{!pictureGallerySearchResult.Project[pictureGallerySearchResultField]}" rendered="{!NOT(ShowResultFieldHyperlinkMap[$ObjectType.Project__c.Fields[pictureGallerySearchResultField].label])}"/>
        <apex:outputLink value="{!URLFOR($Action.Project__c.View, pictureGallerySearchResult.Project['Id'])}" rendered="{!ShowResultFieldHyperlinkMap[$ObjectType.Project__c.Fields[pictureGallerySearchResultField].label]}" styleClass="resultFieldHyperlink">
            <apex:outputLabel value="{!pictureGallerySearchResult.Project[pictureGallerySearchResultField]}" styleClass="resultFieldHyperlinkLabel"/>
        </apex:outputLink>
    </apex:column>
</apex:repeat>