+ Start a Discussion
VeMan1542VeMan1542 

Weird Behavior - Getting and Setting Query String Parameters on a Single Page

The code on the Tutorial page for this topic in the Developer's Guide results in rather odd behavior. I'm trying to learn Visualforce from the ground up and all has been well until this page. Here's the code:

<apex:page standardController="Account">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying contacts from the {!account.name} account.
Click a contact's name to view his or her details.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:form>
<apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4" border="1">
<apex:column>
<apex:commandLink>
{!contact.Name}
<apex:param name="cid" value="{!contact.id}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:pageBlock>
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>
</apex:page>
According to the tutorial, "

After saving this markup, refresh your browser with the id query string parameter but without the cid parameter in the URL. Initially the contact detail page is not rendered, but when you click a contact name the page renders the appropriate detail view."

However, refreshing the page using just the id query string parameter does render the Contact Detail page.

Also, in this case I have two contacts in the form section. Clicking on the other contact still renders the page with the first contact. I've copied this code into my page verbatim, and it's not working as advertised. I sent a message to the Developer's Guide writers with no response. Am I copying and pasting the code incorrectly, or is there a glitch in the example??

Thanks in advance

jwetzlerjwetzler
I definitely found a bug in there.

First, I talked to our documentation writer and he did already have a task to look at this, so it did not fall on deaf ears!

But second, here's a workaround page that uses a partial page update to just update the detail component.  I think it is a better example of what you would actually want to do since it eliminates the need for a full page refresh.  It will still show one of the contact detail section initially though.

Code:
<apex:page standardController="Account">
<apex:pageBlock title="Hello {!$User.FirstName}!">
You are displaying contacts from the {!account.name} account.
Click a contact's name to view his or her details.
</apex:pageBlock>
<apex:pageBlock title="Contacts">
<apex:form >
<apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4" border="1">
<apex:column >
<apex:commandLink rerender="detail">
{!contact.Name}
<apex:param name="cid" value="{!contact.Id}"/>
</apex:commandLink>
</apex:column>
</apex:dataTable>
</apex:form>
</apex:pageBlock>
<apex:outputPanel id="detail">
<apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false" title="false"/>
</apex:outputPanel>
</apex:page>

 



Message Edited by jwetzler on 06-19-2008 05:38 PM