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
MWelch_WTMWelch_WT 

Problem with controller variable in "id" attribute.

Hello,

 

I'm trying to show a page containing a bunch of pageblocks  generated from a controller List.  I'd like each pageblock to be individually identifiable, by doing something like this:

 

 

<apex:repeat value="{!controllerVariable}" var="cv"> <apex:pageBlock id="pb{!cv.cvid}"> ... ... ...

 

The problem is, that I get the following error when I try to save a VF page with this kind of code in it:

 

Error: id="mp{!cv.cvid}" core.apexpages.el.adapters.exceptions.UnknownPropertyException: Unknown property 'cv'

 

You might expect that my "cv" var isn't being generated correctly, but that's not the case.  If I change the code as follows:

 

 

<apex:repeat value="{!controllerVariable}" var="cv"> <apex:pageBlock id="pb"> This is the expected id: {!cv.cvid} ... ... ...

 

The page saves just fine, and the correct cvid is displayed when I navigate to that page.

 

I've looked around, but didn't see anything similar.  Does the platform support  using controller variables in id attributes?  And, if not, how else might I go about making repeating sections of the page individually identifiable?

 

 

jwetzlerjwetzler

id attributes should have never compiled with expressions (and just fyi in the next release they will no longer even compile for new pages).

 

Each pageBlock is uniquely identifiable, as it is not valid to have elements on your page with the same ids.  If you look at the source for your page, you'll see that each pageBlock will have a row index injected into its DOM id (if you specified ids for all of your containers it would come out looking something like id="thePage:theForm:theRepeat:0:thePageBlock" for the first one, and id="thePage:theForm:theRepeat:1:thePageBlock" for the second, etc.). 

MWelch_WTMWelch_WT

Jill,

 

Thanks for the reply.  I know I can descend the DOM, but one of the things I wanted to do was link a section, through its id attribute, directly to individiual members if a list, thorugh reference to a unique number in each member object of that list.  In other words, I've got the following code:

 

 

Public List<repeatObject> repeatObjectList; this.repeatObjectList=new List<repeatObject>(); ro1=new repeatObject (1, 'bird'); ro2=new repeatObject (2, 'cat'); repeatObjectList.add(ro1); repeatObjectList.add(ro2); public class repeatObject { public Integer roID {get; set;} public String Animal {get; set;} public repeatObject(Integer roID, String Animal) { } }

 

 That's mostly pseudocode, so please forgive any syntax errors.  The point is, though, that I'd like to be able to associate individual sections of the VF-output page with the roID variables in the repeatObject class.  Any way to do this?

Thanks.