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
Luka Matovic 2Luka Matovic 2 

Can't create apex:attribute in custom component

Hi all,

I have a problem regarding tying an attribute in a visualforce component to a Controller. THe thing is, i needed some new functionality so i created new controller PaginatorController2. There, i have a property defined like this: 
 

public object pCon {get;set;}

next I added an attribute to a component: 

<apex:component controller="PaginatorController2"> 
<apex:attribute name="pCon" description="" assignTo="{!pCon }" type="object" required="true"/>


The compiler reports an error: 

<apex:attribute assignTo> cannot be the same as the <apex:attribute name> ( pCon )

 

Ok, i change the name of the attribute to 'xxxx' or whatever else, but now compiler prints an error: 

Type mismatch for <apex:attribute assignTo>. Value binding to a property of type ANY is required, property specified (pCon) is of type Object.
 

Now, i can't do anything with this, i have a feeling it's some bug with compilor but it is veeery frustrating, can't create any new component. I didn't want to bother you so i tried the forum first but with no luck. 
http://salesforce.stackexchange.com/questions/54628/cant-create-attribute-with-type-object-in-custom-vf-component?noredirect=1#comment71901_54628  (http://salesforce.stackexchange.com/questions/54628/cant-create-attribute-with-type-object-in-custom-vf-component?noredirect=1#comment71901_54628)

After this, i tried setting the attribute type to be specific, type="BaseListExtension" and it worked, both component and controller compiled properly, but when i wanted to add the component to a page, like any other component, on any other page, it didn't want to accept my changes 
(MyController is of BaseListExtension type)

<c:Paginator2 controller="{!MyController }"></c:Paginator2>

The error produced is 

Wrong type for attribute <urbanhawks:paginator3 controller="{!MyController}">. Expected BaseListExtensionS, found String

And i know i am not doing anything wrong with the code because i am trying to accomplish something that works on several places throughout the project in the same way. 
I would appreciate any help I can get. Thanks.

 

Luka

Parvinder SinghParvinder Singh
For the first issue, change the either change the attribute name or change the variable name in your controller, they both cannot be same, ex-
<apex:component controller="PaginatorController2">
<apex:attribute name="pCon1" description="" assignTo="{!pCon }" type="object" required="true"/>

Hope this helps!
 
Luka Matovic 2Luka Matovic 2
Yes, that's exactly what I did, and then there was a next error it produced. I wrote it up there, type mismatch for value binding. So now I am stuck on that, i also tried to create more, new, components, but the same things happen.