1
votes

Sounds easy enough, but I'm taking the values output in my table from a number of field sets, so admin users can customise the columns that appear in the table.

Here's my functioning page block...

        <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>

You can see I've created a 'hard-coded' hyperlink for an image in the first column, but I want to dynamically hyperlink a field, if it is the name field for a custom object.

For example, if the fieldset...

$ObjectType.Project__c.FieldSets.Picture_Gallery_Search_Results

...contains the a field called 'Name', I want to insert a hyperlink that would take you to the salesforce page to view that project.

So firstly I need to be able to determine if the field is a custom object name field and secondly, output a hyper link rather than a label.

If anyone has any ideas, I would be most appreciative.

Thanks for taking the time to read this.

2

2 Answers

2
votes

Have you considered doing this logic in an APEX controller/extension? After you execute your query, you can iterate over the results, determine what you want the hyperlink to be for each, and populate a map you expose to your Visualforce page keyed by some unique value in the search result (presumably ID) and the value would be the hyperlink. Then in your Visualforce iterator you can do map[SearchResult.Id] or whatever the key ends up being.

1
votes
<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>