function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saurabh DhobleSaurabh Dhoble 

Problem generating hyperlink inside a repeat

Folks,

I'm running into an issue putting hyperlinks inside a repeat object - please see below VF code -

<apex:outputPanel id="opnlSearchResult">
     <apex:repeat value="{!searchResult}" var="contact">
          <a href="#">
               <h1>{!contact.Name}</h1>
                <p>{!contact.Id}</p>
           </a>
      </apex:repeat>
</apex:outputPanel>

{!searchResult} is a list of type Contact.
I'm expecting this to generate a repeat of the following HTML :-

<a href="#">
   <h1>Name1</h1>
   <p>Id1</p>
</a>
<a href="#">
   <h1>Name2</h1>
   <p>Id2</p>
</a>

Instead, I'm getting -

<a href="#"></a>
<h1><a href="#">Name1</a></h1>
<p>Id1</p>

Basically, I want the header & paragraph to appear **inside** the hyperlink - this is required so they render correctly on mobile html5 pages. But Visualforce is somehow distorting the HTML.

Please help !!
logontokartiklogontokartik
I dont see VF Page distoring the HTML. Its exatly as you were expecting. I copy pasted your code and it worked as you expected. Here is the testpage
<pre>
<apex:page standardController="Contact" recordSetVar="cons">
    <apex:outputPanel id="opnlSearchResult">
     <apex:repeat value="{!cons}" var="contact">
          <a href="#">
               <h1>{!contact.Name}</h1>
                <p>{!contact.Id}</p>
           </a>
      </apex:repeat>
</apex:outputPanel>
</apex:page>
</pre>
Saurabh DhobleSaurabh Dhoble
Kartik,

You are right - it works as is. However, the problem is in the Ajax rendering part - try the below. The page renders correctly at first, but when you click the "Search" button the DOM gets modified, introducing the problem I mentioned above.

<apex:page standardController="Contact" recordSetVar="cons">
    <apex:form>
    <apex:commandButton id="searchButton" value="Search" reRender="opnlSearchResult"
            html-data-inline="true"  />       
    <apex:outputPanel id="opnlSearchResult">
     <apex:repeat value="{!cons}" var="contact">
          <a href="#">
               <h1>{!contact.Name}</h1>
                <p>{!contact.Id}</p>
           </a>
      </apex:repeat>
</apex:outputPanel>   
    </apex:form>       
</apex:page>

Any ideas ?
Thx.
Andries.NeyensAndries.Neyens
I have the same issue: https://developer.salesforce.com/forums/ForumsMain?id=906F000000099aUIAQ

and have a case open at Salesforce. If I receive an answer I will let you know!!