+ Start a Discussion
DrBixDrBix 

Compile Error in a Visualforce Page -- apex:pageBlockTable and a List

I am working on a project that has a very large Visualforce page.  I'm breaking it down into more manageable chunks by using a "State" object that encapsulates information about a particuar state inside of smaller objects.  The base class is abstract, and each state extends that abstract class to provide different functionality.  Anyhow, one state manages a purchase order and has a method called getPO ().  I can access that method via an Apex expression like this:

 

{!curState['PO'].PO_Number__c}

 

In that object (which works perfectly).  Obviously I cannot access the getPO() method directly because the base class does not have that method and the Controller that maintains the state object returns the abstract State obejct, I also have a method called getLineItems() that returns a collection of objects (line items on a purchase order).  The collection is a "List."  I can actually test this such as:

 

<apex:outputText value="{!curState['LineItems']}"/>

 

Which shows the collection as having the correct number of elements.

 

When I attempt to iterate over that collection in a pageBlockTable such as:

 

<apex:pageBlockTable id="lineItems" value="{!curState['LineItems']}" var="t">


it will not compile.  The error message is:

    Save error: Cannot coerce from class core.apexpages.el.adapters.RuntimeTypeMetadataELAdapter to class java.lang.Boolean

 

Perhaps I'm misunderstanding what Datatable should take in the value.  However, if I put the exact same list in the controller class, it WORKS.  Any ideas on how I can fix this?

 

Thanks in advance.

 

aballardaballard

Strange.   That looks like it should be ok.  It certainly shouldn't be looking for a boolean.   I think you will have to open a support case on this. 

 

DrBixDrBix

I'm also getting the same type of issues in other places in my Visualforce page such as this:

 

<apex:outputText value="{0,number,0}">
  <apex:param value="{!curState['LineItem'].Line_Number__c}" />
</apex:outputText>

 

Error:
Save error: The value attribute on <apex:outputText> is not in a valid format. It must be a positive number, and of type Number, Date, Time, or 

 

Do you see anything wrong with this as well?

aballardaballard

Come to think of it, why are you using the dynamic references at all?

 

What happens if you use {!curstate.lineitems} in the first case and curState.lineitem.line_number__c in the second?  That should be exactly equivalent...

 

(Though the syntax you have used should be valid...)

DrBixDrBix

Because curState is an abstract class.  The "real" state extends the abstract class and adds other methods that are not part of the base class, otherwise I would do what you suggested.  That's why I'm uding a dynamic reference.

aballardaballard

Ah.  Sounds like some bad error handling, but I doubt that is going to work if lineItem/lineItems (or gettes for them) are not defined in curState. You'd need a cast to an object that has those properties and there is no way to do that in a formula expression. 

 

Have you tried defining getLineItem/getLineItems as abstract methods in the base class?  (In which case the standard syntax should work...)

 

DrBixDrBix

Well, your solution would technically work, but since I have like 25 different states, each one would then have to provide that method (or a default would have to be provided in the abstract base class).  Neither option sounds palatable to me from a design (or object oriented) point of view.

 

If it comes down to that as being the answer, then I'll just bite the bullet and put it in the controller because that just seems like a better solution than putting a hack into the base class.  It just seems unreasonable to me that I can do that use dynamic references using an Object, even a collection of Objects, in some tag's value parameter but not others.  I was even able to pass the List to an outputText tag and have it show each object's ID in the list.

 

Don't get me wrong.  I realize that there are limitations in what Visualforce Pages can do, but to me, this just feels more like a bug as opposed to something that shouldn't be done.

 

Either way, I appreciate your help.

aballardaballard

The fact that it seems to  work ok to display the entire list does seem to indicate that it is close to working!   I'd still suggest opening a support case.

icemft1976icemft1976

Hi, did you ever get to the bottom of this?

 

I have the same issue but the error throws when I try to use a repeat variable inside the brackets where the expression goes. If I manually reference a specific location it displays fine

 

works

    <tr>
        <td><apex:outputText value="{!reportYear.monthsList[0].Name}" /></td>
        <td class="dollars"><apex:outputText value="{0,number,$#,###.##}"><apex:param value="{!reportYear.monthsList[0].totalsales}"/></apex:outputText></td>
        <td class="dollars"><apex:outputText value="{0,number,$#,###.##}"><apex:param value="{!reportYear.monthsList[0].plan}"/></apex:outputText></td>
        <td class="percent"><apex:outputText value="{!reportYear.monthsList[0].pscore}" /></td>
    </tr>

 

 

does not work

	<apex:repeat value="{!reportYear.quarterMap['Q1']}" var="month" >
		<tr>
			<td><apex:outputText value="{!reportYear.monthsList[month].Name}" /></td>
			<td class="dollars"><apex:outputText value="{0,number,$#,###.##}"><apex:param value="{!reportYear.monthsList[month].totalsales}"/></apex:outputText></td>
			<td class="dollars"><apex:outputText value="{0,number,$#,###.##}"><apex:param value="{!reportYear.monthsList[month].plan}"/></apex:outputText></td>
			<td class="percent"><apex:outputText value="{!reportYear.monthsList[month].pscore}" /></td>
		</tr>
	</apex:repeat>

 the Quarter Map just holds a map of Strings (QuarterName) to lists of Integers (corresponding months in the 12 month array).  'Q1' => (0,1,2), etc.

 

note - the weird outputText treatment is to format numbers in class level objects to look like currency fields. I'm not sure this is still the best way to do things but I haven't seen another approach lately. 

 

thanks for any feedback you might have on this one. Seems like its something under the hood....

TLFTLF

I'm running into this too. It seems to be something specific to iterating over a set of map keys using the apex:repeat tag or similar iterating component. Has anyone figured this out? If not, I'll see if I can create a simple repro case and open a case with Salesforce developer support.

vaughan.crole1.3898398161361802E12vaughan.crole1.3898398161361802E12
Has anyone solved this issue yet? and/or devised a workaround?

Keen to hear people's thoughts!
Mitesh SuraMitesh Sura
Anybody with any solution. Agree with other users, something to do with repeat tag and map/list variable. I have same logic in other class and that seems to be working fine. 
Mitesh SuraMitesh Sura
Found and fixed the issue. In my case it was simple, but that might not be case for others.

I changed the var label in apex:repeat and apex:pageBlockTable tags. That cleared the issue. I am sure the error was something else, but Salesforce did not handle it in good way.

Hope this will help someone. 
Abdul Mujeeb ShaikAbdul Mujeeb Shaik
Hi Mitesh Sura, Can you please tell me from wht to what you changed the lable of var in repeat and in pageblock table.
i am facing the same issue.
thanks 
Mitesh SuraMitesh Sura
hi Abdul Mujeeb Shaik,

In my case, I think there was issue with the label, changing that helped me.For e.g. var="a" to var="b". I did not have any var="a" on VF page, hence I am do not think this is the solution. I was just lucky that it worked. 
urawaredsurawareds
I had this same error, and hopefully figured out the problem.
In my case, I was using the same "var" name in other apex:repeat.