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
werewolfwerewolf 

Using merge fields on id attributes of input components

Hi all,

This simple question has got me stumped.  My offending snippet is:

<apex:dataTable id="itemlist" value="{!sortedChecklistItems}" var="Item">
       <apex:facet name="header"><b>Checkbox</b></apex:facet>
            <apex:inputCheckbox id="{!Item.Id}" value="{!Item.Checkbox__c}" disabled="{!Item.Not_Available__c}"  />
       </apex:column>
</apex:dataTable>

Unfortunately the id attribute is giving me trouble.  When I try to save this I get:

Save error: Unknown property 'Checklist__cStandardController.Item'

But when I remove the id attribute it all works fine, showing clearly that the Item property is perfectly valid, since I'm also using it in the value attribute.  

Is there something about the id attribute that acts differently from the other attributes?  Can I not use a merge field in that?  If not, how else can I ensure that each input item in my table gets a predictably unique ID?  Thanks.


Message Edited by werewolf on 01-08-2009 10:37 AM
Best Answer chosen by Admin (Salesforce Developers) 
EricVlachEricVlach
Nope, you can't use a merge field in an ID. VisualForce makes the ID unique when you render the page. Reference the ID using the {!$Component.} merge field.

Useful documentation:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_access.htm

All Answers

EricVlachEricVlach
Nope, you can't use a merge field in an ID. VisualForce makes the ID unique when you render the page. Reference the ID using the {!$Component.} merge field.

Useful documentation:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_access.htm
This was selected as the best answer
werewolfwerewolf
Thank you Eric, using $Component solved the problem.
montblanc2000montblanc2000

Can you please provide an example of your corrected code? I am new to Visualforce and am grappling with the same problem. Any help would be greatly appreciated.

 

Paul

werewolfwerewolf
See the sample code in the docs here.